Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 33624 invoked from network); 23 May 2006 15:14:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 May 2006 15:14:30 -0000 Received: (qmail 94027 invoked by uid 500); 23 May 2006 15:14:29 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 93833 invoked by uid 500); 23 May 2006 15:14:28 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 93765 invoked by uid 99); 23 May 2006 15:14:28 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 May 2006 08:14:27 -0700 X-ASF-Spam-Status: No, hits=0.6 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 May 2006 08:14:23 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 9006E1A983A; Tue, 23 May 2006 08:14:03 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r408925 [1/3] - in /geronimo/sandbox/geronimo-cache: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/geronimo/ src/main/java/org/apache/geronimo/cache/ src/main/java/org/apache/geronimo... Date: Tue, 23 May 2006 15:13:55 -0000 To: scm@geronimo.apache.org From: jgenender@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060523151403.9006E1A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jgenender Date: Tue May 23 08:13:52 2006 New Revision: 408925 URL: http://svn.apache.org/viewvc?rev=408925&view=rev Log: Add new geronimo-cache Added: geronimo/sandbox/geronimo-cache/ geronimo/sandbox/geronimo-cache/LICENSE.txt geronimo/sandbox/geronimo-cache/pom.xml geronimo/sandbox/geronimo-cache/src/ geronimo/sandbox/geronimo-cache/src/main/ geronimo/sandbox/geronimo-cache/src/main/java/ geronimo/sandbox/geronimo-cache/src/main/java/org/ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/Cache.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheConfigurationException.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheEvent.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheException.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheListener.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheManager.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheStore.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/LocalCache.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/ReplicatedCache.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/CacheChannel.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/CacheCommunicationException.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/HeartbeatEvent.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/JoinedEvent.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/MessageID.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/ProvideContentEvent.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteAddEvent.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteEvent.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteRemoveEvent.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteUpdateEvent.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/aioimpl/ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/aioimpl/CacheActiveIOCommListener.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/aioimpl/CacheChannelActiveIOImpl.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/CacheChannelUDPImpl.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/CacheCommListener.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/ClusterReceiverRunnable.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/ClusterSenderRunnable.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/config/ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/config/CacheConfig.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/config/CacheStorageConfig.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/AbstractCache.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/CacheMemoryStoreImpl.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/LocalCacheImpl.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/ReplicatedCacheImpl.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheLocator.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheServer.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheSession.java geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheSessionLocation.java geronimo/sandbox/geronimo-cache/src/main/xsd/ geronimo/sandbox/geronimo-cache/src/main/xsd/geronimo-cache-1.0.xsd geronimo/sandbox/geronimo-cache/src/main/xsd/xmlconfig.xml geronimo/sandbox/geronimo-cache/src/test/ geronimo/sandbox/geronimo-cache/src/test/java/ geronimo/sandbox/geronimo-cache/src/test/java/org/ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheConfigurationExceptionTest.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheEventTest.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheExceptionTest.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheManagerTest.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/LocalCacheTest.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/MockCacheListener.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/MockReplicatedCache.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/aiotest/ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/aiotest/Peer.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/CacheCommunicationExceptionTest.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/JoinedEventTest.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/MessageIDTest.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/MockCacheChannel.java geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/RunCacheStuff.java geronimo/sandbox/geronimo-cache/src/test/resources/ geronimo/sandbox/geronimo-cache/src/test/resources/META-INF/ geronimo/sandbox/geronimo-cache/src/test/resources/META-INF/geronimo-cache-config.xml Added: geronimo/sandbox/geronimo-cache/LICENSE.txt URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/LICENSE.txt?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/LICENSE.txt (added) +++ geronimo/sandbox/geronimo-cache/LICENSE.txt Tue May 23 08:13:52 2006 @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + Added: geronimo/sandbox/geronimo-cache/pom.xml URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/pom.xml?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/pom.xml (added) +++ geronimo/sandbox/geronimo-cache/pom.xml Tue May 23 08:13:52 2006 @@ -0,0 +1,133 @@ + + + 4.0.0 + org.apache.geronimo + geronimo-cache + 1.3-SNAPSHOT + Caching + jar + replicated cache session implementation +  + + 2.0.4 + + + + + apache-maven1-snapshot + Activemq Maven1 Repo + http://cvs.apache.org/repository + legacy + + + + + + commons-logging + commons-logging + 1.0.4 + + + backport-util-concurrent + backport-util-concurrent + 2.1 + + + junit + junit + 3.8.1 + test + + + xmlbeans + xbean + 2.0.0 + + + stax + stax-api + 1.0 + compile + + + stax + stax + 1.1.1-dev + compile + + + xmlbeans + xmlbeans-jsr173-api + + + + + org.apache.geronimo.modules + geronimo-session + 1.2-SNAPSHOT + + + incubator-activemq + activeio-core + 3.0-beta3 + + + + + + org.codehaus.mojo + xmlbeans-maven-plugin + 2.0 + + + + xmlbeans + + + + + true + + + src/main/xsd/xmlconfig.xml + + + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.0 + + + + clean + + + + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + \ No newline at end of file Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/Cache.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/Cache.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/Cache.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/Cache.java Tue May 23 08:13:52 2006 @@ -0,0 +1,151 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache; + +import java.rmi.server.UID; +import java.util.Map; +import java.util.Set; + +import org.apache.geronimo.cache.config.CacheConfig; + +/** + * The cache interface, implemented to plug in a particular implementation + * + * $Rev$ $Date$ + */ +public interface Cache extends Map { + + /** + * Generated identifier for this cache. + */ + public UID getId(); + + /** + * The name of the cache + * + * @return + */ + public String getName(); + + /** + * lock this cache + * + * @return true if the cache is locked, false otherwise + */ + public boolean lock(); + + /** + * try to lock in timeoutMilliSeconds + * + * @param timeoutMilliSeconds + * @return true if the cache is locked, false otherwise + */ + public boolean lock(long timeoutMilliSeconds); + + /** + * unlock this cache + * + * @param key + * @return returns true if the unlock is successful and the cache is + * unlocked, false otherwise + */ + public boolean unlock(); + + /** + * lock key in this cache, if the key does not exist this + * call is ignored + * + * @param key + * @return true if the key is locked, false otherwise + */ + public boolean lock(Object key); + + /** + * lock key in this cache in timeoutMilliSeconds + * if the key does not exist this call is ignored + * + * @param key + * @return true if the key is locked, false otherwise + */ + public boolean lock(Object key, long timeoutMilliSeconds); + + /** + * unlock key in this cache, if the key does not exist this + * call is ignored + * + * @param key + * @return returns true if the unlock is successful and the key is unlocked, + * false otherwise + */ + public boolean unlock(Object key); + + /** + * Finish initialization of the cache. This method is mostly used buy + * adaptors that plug into the caching api for any remaining configuration + * detail that must be done. + * + * @param config + */ + public void setConfiguration(CacheConfig config); + + /** + * Add a listener to this cache. Listeners are local and do not receive + * notifications from remote caches but will receive notifications when this + * cache is part of a cluster and the cluster changes. + * + * @see CacheListener + * @param listener + */ + public void addListener(CacheListener listener); + + /** + * Add a listener to this cache for key. Listeners are local + * and do not receive notifications from remote caches but will receive + * notifications when this cache is part of a cluster and the cluster + * changes. + * + * @see CacheListener + * @param listener + */ + public void addListener(CacheListener listener, Object key); + + /** + * Remove a listener from this cache. + * + * @see CacheListener + * @param listener + */ + public void removeListener(CacheListener listener); + + /** + * Remove a listener from this cache for key. + * + * @see CacheListener + * @param listener + */ + public void removeListener(CacheListener listener, Object key); + + /** + * Return a map that contains all the keys. Will contain + * null where the receiver does not have a value for a + * particular key. + * + * @param keys + * @return + */ + public Map getAll(Set keys); + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheConfigurationException.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheConfigurationException.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheConfigurationException.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheConfigurationException.java Tue May 23 08:13:52 2006 @@ -0,0 +1,40 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache; + +/** + * $Rev$ $Date$ + */ +public class CacheConfigurationException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public CacheConfigurationException() { + super(); + } + + public CacheConfigurationException(String message) { + super(message); + } + + public CacheConfigurationException(String message, Throwable cause) { + super(message, cause); + } + + public CacheConfigurationException(Throwable cause) { + super(cause); + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheEvent.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheEvent.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheEvent.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheEvent.java Tue May 23 08:13:52 2006 @@ -0,0 +1,72 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache; + + +/** + * Events posted by a cache and processed locally + * + * $Rev$ $Date$ + */ +//TODO: Does this make sense with the RemoteObject, should this thing be the one posted? +public class CacheEvent { + private Cache cache; + + private Object oldValue; + + private Object newValue; + + private Object key; + + public CacheEvent(Object key, Object oldValue, Object newValue, Cache cache) { + setCache(cache); + setKey(key); + setOldValue(oldValue); + setNewValue(newValue); + } + + public Cache getCache() { + return cache; + } + + public void setCache(Cache cache) { + this.cache = cache; + } + + public Object getKey() { + return key; + } + + public void setKey(Object key) { + this.key = key; + } + + public Object getNewValue() { + return newValue; + } + + public void setNewValue(Object newValue) { + this.newValue = newValue; + } + + public Object getOldValue() { + return oldValue; + } + + public void setOldValue(Object oldValue) { + this.oldValue = oldValue; + } +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheException.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheException.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheException.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheException.java Tue May 23 08:13:52 2006 @@ -0,0 +1,42 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache; + +/** + * general cache exception + * + * $Rev$ $Date$ + */ +public class CacheException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public CacheException() { + super(); + } + + public CacheException(String message) { + super(message); + } + + public CacheException(String message, Throwable cause) { + super(message, cause); + } + + public CacheException(Throwable cause) { + super(cause); + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheListener.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheListener.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheListener.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheListener.java Tue May 23 08:13:52 2006 @@ -0,0 +1,39 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache; + +/** + * Implement this to listen to local changes on a cache + * + * $Rev$ $Date$ + */ +public interface CacheListener { + /** + * An entry was added, key and newValue will be set, oldValue wil be null + * @param event + */ + public void entryAdded(CacheEvent event); + /** + * An entry was removed, key and oldValue will be set, newValue will be null + * @param event + */ + public void entryRemoved(CacheEvent event); + /** + * An entry was updated, key, newValue and oldValue will be set + * @param event + */ + public void entryUpdated(CacheEvent event); +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheManager.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheManager.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheManager.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheManager.java Tue May 23 08:13:52 2006 @@ -0,0 +1,183 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.cache.comm.impl.CacheChannelUDPImpl; +import org.apache.geronimo.cache.config.CacheConfig; +import org.apache.geronimo.cache.config.CacheStorageConfig; +import org.apache.geronimo.cache.xmlbeans.GCacheConfigDocument; +import org.apache.geronimo.cache.xmlbeans.GCacheType; +import org.apache.geronimo.cache.xmlbeans.GStorageType; +import org.apache.xmlbeans.XmlException; + +/** + * the entry point to get a handle on a local cache + * + * $Rev$ $Date$ + */ +public class CacheManager { + private Log log = LogFactory.getLog(CacheChannelUDPImpl.class); + + private Map caches = new HashMap(); + + private ClassLoader classLoader = Thread.currentThread() + .getContextClassLoader(); + + public CacheManager() { + try { + parseConfiguration(); + } catch (IOException e) { + log.error("could not read configuration", e); + throw new CacheConfigurationException( + "could not read configuration", e); + } catch (XmlException e) { + log.error("could not parse configuration", e); + throw new CacheConfigurationException( + "could not parse configuration", e); + } + } + + public CacheManager(ClassLoader loader) { + classLoader = loader; + try { + parseConfiguration(); + } catch (IOException e) { + log.error("could not read configuration", e); + throw new CacheConfigurationException( + "could not read configuration", e); + } catch (XmlException e) { + log.error("could not parse configuration", e); + throw new CacheConfigurationException( + "could not parse configuration", e); + } + } + + public Cache getCache(String name) { + return (Cache) caches.get(name); + } + + /** + * Get the configration for the cache. First look in the classpath for + * META-INF/geronimo-cache-config.xml first instance found takes precedence. + * Override on the command line with -Dgeronimo-cache-config=my-config.xml + * + * Implementations are expected to be using XMLBeans to do the parsing, thus + * the XmlException + * + * @return + * @throws XmlException + */ + protected void parseConfiguration() throws IOException, XmlException { + String overridePath = System.getProperty("geronimo-cache-config"); + InputStream stream = null; + if (null != overridePath) { + File file = new File(overridePath); + if (file.exists()) { + stream = new FileInputStream(file); + } else { + URL configURL = Thread.currentThread().getContextClassLoader() + .getResource(overridePath); + stream = configURL.openStream(); + } + } else { + // use the classpath + URL configURL = Thread.currentThread().getContextClassLoader() + .getResource("META-INF/geronimo-cache-config.xml"); + stream = configURL.openStream(); + } + parseConfiguration(stream); + } + + private void parseConfiguration(InputStream config) throws XmlException, + IOException { + GCacheConfigDocument cacheDoc = GCacheConfigDocument.Factory + .parse(config); + Map storageConfigs = getStorageConfigs(cacheDoc.getCacheConfig() + .getStorageArray()); + Map cacheConfigs = getCacheConfigs(cacheDoc.getCacheConfig() + .getCacheArray(), storageConfigs); + createCaches(cacheConfigs); + } + + private void createCaches(Map cacheConfigs) + throws CacheConfigurationException { + Iterator itr = cacheConfigs.keySet().iterator(); + while (itr.hasNext()) { + String key = (String) itr.next(); + CacheConfig config = (CacheConfig) cacheConfigs.get(key); + try { + Class cacheImpl = Class.forName(config.getCacheImpl(), true, + classLoader); + Cache cache = (Cache) cacheImpl.newInstance(); + cache.setConfiguration(config); + caches.put(config.getName(), cache); + } catch (ClassNotFoundException e) { + String msg = "Configuration of cache is incorrect: class " + + config.getCacheImpl() + " not found"; + log.error(msg, e); + throw new CacheConfigurationException(msg, e); + } catch (InstantiationException e) { + String msg = "Configuration of cache is incorrect: class " + + config.getCacheImpl() + " could not be instanciated"; + log.error(msg, e); + throw new CacheConfigurationException(msg, e); + } catch (IllegalAccessException e) { + String msg = "Configuration of cache is incorrect: class " + + config.getCacheImpl() + + " or its default constructor could not be accessed."; + log.error(msg, e); + throw new CacheConfigurationException(msg, e); + } + } + } + + private Map getCacheConfigs(GCacheType[] cacheTypes, Map storageConfigs) { + Map cacheConfigs = new HashMap(cacheTypes.length); + for (int i = 0; i < cacheTypes.length; i++) { + CacheConfig cacheConfig = new CacheConfig(); + cacheConfig.setName(cacheTypes[i].getCacheName()); + cacheConfig.setCacheImpl(cacheTypes[i].getCacheImpl()); + cacheConfig.setStorageConfig((CacheStorageConfig) storageConfigs + .get(cacheTypes[i].getStorageRef().getStorageNameRef())); + cacheConfig.setPolicy(cacheTypes[i].getEvictionPolicy()); + cacheConfigs.put(cacheTypes[i].getCacheName(), cacheConfig); + } + return cacheConfigs; + } + + private Map getStorageConfigs(GStorageType[] storageTypes) { + Map storageConfigs = new HashMap(storageTypes.length); + for (int i = 0; i < storageTypes.length; i++) { + CacheStorageConfig storageConfig = new CacheStorageConfig(); + storageConfig.setName(storageTypes[i].getStorageName()); + storageConfig.setBuiltInType(storageTypes[i].getStorageStrategy()); + storageConfig.setStorageImpl(storageTypes[i].getStorageImpl()); + storageConfigs.put(storageTypes[i].getStorageName(), storageConfig); + } + return storageConfigs; + } +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheStore.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheStore.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheStore.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/CacheStore.java Tue May 23 08:13:52 2006 @@ -0,0 +1,28 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache; + +import java.util.Map; +import java.util.Set; + +/** + * Local caches keep their entries in a store. + * + * $Rev$ $Date$ + */ +public interface CacheStore extends Map { + public Map getAll(Set keys); +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/LocalCache.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/LocalCache.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/LocalCache.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/LocalCache.java Tue May 23 08:13:52 2006 @@ -0,0 +1,33 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache; + +/** + * Local (in vm) cache + * + * $Rev$ $Date$ + */ +public interface LocalCache extends Cache { + /** + * The store for this cache, where all the objects are to be put. + * + * @see CacheStore + * @return + */ + public CacheStore getStore(); + + public void setStore(CacheStore store); +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/ReplicatedCache.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/ReplicatedCache.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/ReplicatedCache.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/ReplicatedCache.java Tue May 23 08:13:52 2006 @@ -0,0 +1,50 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache; + +import java.net.InetAddress; + +import org.apache.geronimo.cache.comm.CacheChannel; + +/** + * A replicated cache keeps in sync will all other caches of the same name. + * + * $Rev$ $Date$ + */ +public interface ReplicatedCache extends Cache { + /** + * The inet address of this cache + * + * @return + */ + public InetAddress getCacheAddress(); + + /** + * The channel this cache uses to communicate with the rest of the caches in + * this cluster + * + * @return + */ + public CacheChannel getChannel(); + + /** + * Set the channel this cache uses to communicate with the rest of the + * caches in this cluster + * + * @return + */ + public void setChannel(CacheChannel channel); +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/CacheChannel.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/CacheChannel.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/CacheChannel.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/CacheChannel.java Tue May 23 08:13:52 2006 @@ -0,0 +1,55 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm; + +import org.apache.geronimo.cache.ReplicatedCache; + +/** + * Implement this to provide a channel for remote caches to communicate with each other. + * + * $Rev$ $Date$ + */ +public interface CacheChannel { + /** + * Get the cache this channel is connected to + */ + public ReplicatedCache getCache(); + /** + * Set the cache this channel acts on the behalf of + * @param cache + */ + public void setCache(ReplicatedCache cache); + /** + * Send and forget, this method will send the data but won't block. + * @param update + * @throws CacheCommunicationException if any IO errors occur. + */ + public void send(RemoteEvent update); + /** + * This method blocks until the update is received. + * @param update + */ + public void recieve(RemoteEvent update); + /** + * close the channel + */ + public void close(); + + /** + * set to send events or not + */ + public void setSendEvents(boolean flag); +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/CacheCommunicationException.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/CacheCommunicationException.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/CacheCommunicationException.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/CacheCommunicationException.java Tue May 23 08:13:52 2006 @@ -0,0 +1,41 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm; + +/** + * + * $Rev$ $Date$ + */ +public class CacheCommunicationException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public CacheCommunicationException() { + super(); + } + + public CacheCommunicationException(String message) { + super(message); + } + + public CacheCommunicationException(String message, Throwable cause) { + super(message, cause); + } + + public CacheCommunicationException(Throwable cause) { + super(cause); + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/HeartbeatEvent.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/HeartbeatEvent.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/HeartbeatEvent.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/HeartbeatEvent.java Tue May 23 08:13:52 2006 @@ -0,0 +1,32 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm; + +import org.apache.geronimo.cache.ReplicatedCache; + +/** + * + * $Rev$ $Date$ + */ +public class HeartbeatEvent extends RemoteEvent { + private static final long serialVersionUID = 1L; + + public void invoke(ReplicatedCache cache) { + // TODO: update last heard from #'s for the id of the cache + // that sent this message + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/JoinedEvent.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/JoinedEvent.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/JoinedEvent.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/JoinedEvent.java Tue May 23 08:13:52 2006 @@ -0,0 +1,51 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.cache.ReplicatedCache; + +/** + * Caches send a 'JoinedEvent' when they wake up, then everyone responds with a + * 'ProvideContentEvent' the original sender of the JoinedEvent gets the values + * from the ProvideContentEvent. + * + * This is a really bad impl because it takes so much bandwidth to send (each + * cache sends the whole thing) this will be replaced when the events are + * replaced with a protocol. + * + * $Rev$ $Date$ + */ +public class JoinedEvent extends RemoteEvent { + private static final long serialVersionUID = 1L; + + private Log log = LogFactory.getLog(JoinedEvent.class); + + public void invoke(ReplicatedCache cache) { + if (log.isDebugEnabled()) { + log.debug("processing a joined event for " + getCacheId()); + } + // when the joined event is sent everyone respondes with "i've got it" + ProvideContentEvent event = new ProvideContentEvent(); + event.setCacheId(cache.getId()); + event.setCacheName(cache.getName()); + event.setDestinationCacheId(getCacheId()); + event.setValues(cache.getAll(cache.keySet())); + cache.getChannel().send(event); + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/MessageID.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/MessageID.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/MessageID.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/MessageID.java Tue May 23 08:13:52 2006 @@ -0,0 +1,134 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm; + +import java.io.ByteArrayOutputStream; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.rmi.server.UID; +import java.security.DigestOutputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.cache.CacheException; + +/** + * An identifier for messages that is unique across time and vm's. Uses the UID + * class and + * + * $Rev$ $Date$ + */ +public class MessageID { + private static final int HASH_LENTGH = 8; + + private Log log = LogFactory.getLog(MessageID.class); + + private UID uniqueIdentifier = new UID(); + + private InetAddress address = null; + + private byte[] hashAddress = null; + + public MessageID() { + super(); + } + + public int hashCode() { + return uniqueIdentifier.hashCode(); + } + + public boolean equals(Object o) { + boolean flag = false; + if(o == this) { + flag = true; + } + if (!flag && (o instanceof MessageID)) { + MessageID other = (MessageID) o; + if (other.uniqueIdentifier.equals(this.uniqueIdentifier)) { + byte otherData[] = other.getLocalHash(); + byte thisData[] = getLocalHash(); + if(otherData.length == thisData.length) { + flag = true; + for(int i = 0;i < otherData.length;i++) { + if(otherData[i] != thisData[i]) flag = false; + } + } + } + } + return flag; + } + + public void write(DataOutput out) throws IOException { + uniqueIdentifier.write(out); + byte data[] = getLocalHash(); + out.writeInt(data.length); + out.write(data); + } + + public static MessageID read(DataInput in) throws IOException { + UID uid = UID.read(in); + int length = in.readInt(); + byte data[] = new byte[length]; + for (int i = 0; i < length; i++) { + data[i] = in.readByte(); + } + MessageID id = new MessageID(); + id.hashAddress = data; + id.uniqueIdentifier = uid; + return id; + } + + private byte[] getLocalHash() { + if (hashAddress == null) { + try { + if (null == address) { + address = InetAddress.getLocalHost(); + } + MessageDigest sha = MessageDigest.getInstance("SHA"); + DataOutputStream stream = new DataOutputStream( + new DigestOutputStream(new ByteArrayOutputStream(64), + sha)); + byte addressBytes[] = address.getAddress(); + stream.write(addressBytes, 0, addressBytes.length); + stream.flush(); + + byte data[] = sha.digest(); + int length = Math.min(HASH_LENTGH, data.length); + hashAddress = new byte[length]; + System.arraycopy(data, 0, hashAddress, 0, length); + } catch (UnknownHostException e) { + String msg = "Could not find localhost"; + log.error(msg, e); + throw new CacheException(msg, e); + } catch (NoSuchAlgorithmException e) { + String msg = "Could not find SHA"; + log.error(msg, e); + throw new CacheException(msg, e); + } catch (IOException e) { + String msg = "Could not write to buffers"; + log.error(msg, e); + throw new CacheException(msg, e); + } + } + return hashAddress; + } +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/ProvideContentEvent.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/ProvideContentEvent.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/ProvideContentEvent.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/ProvideContentEvent.java Tue May 23 08:13:52 2006 @@ -0,0 +1,72 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm; + +import java.rmi.server.UID; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.cache.ReplicatedCache; + +/** + * The ProvideContentEvent is sent from each cache when a new cache joins the + * cache. + * + * $Rev$ $Date$ + */ +public class ProvideContentEvent extends RemoteEvent { + private static final long serialVersionUID = 1L; + + private Log log = LogFactory.getLog(ProvideContentEvent.class); + + private Map values = null; + + private UID destinationCacheId = null; + + public UID getDestinationCacheId() { + return destinationCacheId; + } + + public void setDestinationCacheId(UID destinationCache) { + this.destinationCacheId = destinationCache; + } + + public Map getValues() { + return values; + } + + public void setValues(Map values) { + this.values = values; + } + + public void invoke(ReplicatedCache cache) { + if (log.isDebugEnabled()) { + log.debug("processing a provide content event for " + + getDestinationCacheId()); + } + if (cache.getId().equals(this.getDestinationCacheId())) { + if (log.isDebugEnabled()) { + log.debug("provide content event - origin = " + getOrigin() + + " source id = " + getCacheId()); + } + cache.getChannel().setSendEvents(false); + cache.putAll(getValues()); + cache.getChannel().setSendEvents(true); + } + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteAddEvent.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteAddEvent.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteAddEvent.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteAddEvent.java Tue May 23 08:13:52 2006 @@ -0,0 +1,48 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm; + +import java.io.Serializable; + +import org.apache.geronimo.cache.ReplicatedCache; + +/** + * + * $Rev$ $Date$ + */ +public class RemoteAddEvent extends RemoteEvent implements Serializable { + private static final long serialVersionUID = 1L; + + private Object newValue = null; + + public RemoteAddEvent() { + } + + public Object getNewValue() { + return newValue; + } + + public void setNewValue(Object newValue) { + this.newValue = newValue; + } + + public void invoke(ReplicatedCache cache) { + cache.getChannel().setSendEvents(false); + cache.put(getKey(), getNewValue()); + cache.getChannel().setSendEvents(true); + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteEvent.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteEvent.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteEvent.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteEvent.java Tue May 23 08:13:52 2006 @@ -0,0 +1,75 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm; + +import java.io.Serializable; +import java.net.SocketAddress; +import java.rmi.server.UID; + +import org.apache.geronimo.cache.ReplicatedCache; + +/** + * First cut at remote event propigation. This will be replaced with a protocol insted of sending + * serialized objects over the net. + * + * $Rev$ $Date$ + */ +public abstract class RemoteEvent implements Serializable { + private static final long serialVersionUID = 1L; + + private Object key = null; + + private String cacheName = null; + + private UID cacheId = null; + + private SocketAddress origin = null; + + public String getCacheName() { + return cacheName; + } + + public void setCacheName(String cacheName) { + this.cacheName = cacheName; + } + + public UID getCacheId() { + return cacheId; + } + + public void setCacheId(UID cacheId) { + this.cacheId = cacheId; + } + + public Object getKey() { + return key; + } + + public void setKey(Object key) { + this.key = key; + } + + public SocketAddress getOrigin() { + return origin; + } + + public void setOrigin(SocketAddress origin) { + this.origin = origin; + } + + public abstract void invoke(ReplicatedCache cache); + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteRemoveEvent.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteRemoveEvent.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteRemoveEvent.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteRemoveEvent.java Tue May 23 08:13:52 2006 @@ -0,0 +1,48 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm; + +import java.io.Serializable; + +import org.apache.geronimo.cache.ReplicatedCache; + +/** + * + * $Rev$ $Date$ + */ +public class RemoteRemoveEvent extends RemoteEvent implements Serializable { + private static final long serialVersionUID = 1L; + + private Object oldValue = null; + + public RemoteRemoveEvent() { + } + + public Object getOldValue() { + return oldValue; + } + + public void setOldValue(Object oldValue) { + this.oldValue = oldValue; + } + + public void invoke(ReplicatedCache cache) { + cache.getChannel().setSendEvents(false); + cache.remove(getKey()); + cache.getChannel().setSendEvents(true); + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteUpdateEvent.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteUpdateEvent.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteUpdateEvent.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/RemoteUpdateEvent.java Tue May 23 08:13:52 2006 @@ -0,0 +1,53 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm; + +import java.io.Serializable; + +import org.apache.geronimo.cache.ReplicatedCache; + +public class RemoteUpdateEvent extends RemoteEvent implements Serializable { + private static final long serialVersionUID = 1L; + + private Object oldValue = null; + + private Object newValue = null; + + public RemoteUpdateEvent() { + } + + public Object getNewValue() { + return newValue; + } + + public void setNewValue(Object newValue) { + this.newValue = newValue; + } + + public Object getOldValue() { + return oldValue; + } + + public void setOldValue(Object oldValue) { + this.oldValue = oldValue; + } + public void invoke(ReplicatedCache cache) { + cache.getChannel().setSendEvents(false); + cache.put(getKey(), getNewValue()); + cache.getChannel().setSendEvents(true); + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/aioimpl/CacheActiveIOCommListener.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/aioimpl/CacheActiveIOCommListener.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/aioimpl/CacheActiveIOCommListener.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/aioimpl/CacheActiveIOCommListener.java Tue May 23 08:13:52 2006 @@ -0,0 +1,67 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm.aioimpl; + +import org.apache.geronimo.cache.CacheEvent; +import org.apache.geronimo.cache.CacheListener; +import org.apache.geronimo.cache.comm.CacheChannel; +import org.apache.geronimo.cache.comm.RemoteAddEvent; +import org.apache.geronimo.cache.comm.RemoteRemoveEvent; +import org.apache.geronimo.cache.comm.RemoteUpdateEvent; + +/** + * This listener is added to the replicated cache and is what sends out the + * changes messages to the channel which in turn sends them out to the clulster + * of caches. + * + * $Rev$ $Date$ + */ +public class CacheActiveIOCommListener implements CacheListener { + private CacheChannel channel = null; + + public CacheActiveIOCommListener(CacheChannel channel) { + this.channel = channel; + } + + public void entryAdded(CacheEvent event) { + RemoteAddEvent addEvent = new RemoteAddEvent(); + addEvent.setCacheName(event.getCache().getName()); + addEvent.setCacheId(event.getCache().getId()); + addEvent.setKey(event.getKey()); + addEvent.setNewValue(event.getNewValue()); + channel.send(addEvent); + } + + public void entryRemoved(CacheEvent event) { + RemoteRemoveEvent removeEvent = new RemoteRemoveEvent(); + removeEvent.setCacheName(event.getCache().getName()); + removeEvent.setCacheId(event.getCache().getId()); + removeEvent.setKey(event.getKey()); + removeEvent.setOldValue(event.getOldValue()); + channel.send(removeEvent); + } + + public void entryUpdated(CacheEvent event) { + RemoteUpdateEvent updateEvent = new RemoteUpdateEvent(); + updateEvent.setCacheName(event.getCache().getName()); + updateEvent.setCacheId(event.getCache().getId()); + updateEvent.setKey(event.getKey()); + updateEvent.setNewValue(event.getNewValue()); + updateEvent.setOldValue(event.getOldValue()); + channel.send(updateEvent); + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/aioimpl/CacheChannelActiveIOImpl.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/aioimpl/CacheChannelActiveIOImpl.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/aioimpl/CacheChannelActiveIOImpl.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/aioimpl/CacheChannelActiveIOImpl.java Tue May 23 08:13:52 2006 @@ -0,0 +1,183 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm.aioimpl; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.ByteBuffer; +import java.nio.channels.Pipe; + +import org.apache.activeio.AcceptListener; +import org.apache.activeio.Channel; +import org.apache.activeio.ChannelFactory; +import org.apache.activeio.packet.Packet; +import org.apache.activeio.packet.async.AsyncChannel; +import org.apache.activeio.packet.async.AsyncChannelListener; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.cache.CacheException; +import org.apache.geronimo.cache.ReplicatedCache; +import org.apache.geronimo.cache.comm.CacheChannel; +import org.apache.geronimo.cache.comm.CacheCommunicationException; +import org.apache.geronimo.cache.comm.JoinedEvent; +import org.apache.geronimo.cache.comm.RemoteEvent; +import org.apache.geronimo.cache.comm.impl.CacheChannelUDPImpl; + +/** + * First cut at the aio impl, does not work + * + * $Rev$ $Date$ + */ +public class CacheChannelActiveIOImpl implements CacheChannel, AsyncChannelListener, AcceptListener { + private static final String DEFAULT_URI = "nio://localhost:10101"; + public static final int MAX_PACKET_SIZE = 65507; + private Log log = LogFactory.getLog(CacheChannelUDPImpl.class); + private ReplicatedCache cache = null; + private ThreadLocal sendEvents = new ThreadLocal(); + private Pipe eventPipe = null; + private boolean awake = false; + // either a peer or the server + private AsyncChannel asyncChannel = null; + // TODO: what to do case of server death? + //private AsyncChannelServer server = null; + + public CacheChannelActiveIOImpl() { + super(); + String uri = DEFAULT_URI; + try { + eventPipe = Pipe.open(); + ChannelFactory activeIOChannelFactory = new ChannelFactory(); + asyncChannel = activeIOChannelFactory.openAsyncChannel(new URI(uri)); + asyncChannel.setAsyncChannelListener(this); + } catch (IOException e) { + String msg = "Could not open pipe for " + cache.getId(); + log.error(msg, e); + throw new CacheException(msg, e); + } catch (URISyntaxException e) { + String msg = "Could not parse URI " + uri; + log.error(msg, e); + throw new CacheException(msg, e); + } + } + + public void onPacket(Packet data) { + } + + public void onPacketError(IOException error) { + } + + public void onAccept(Channel arg0) { + // TODO Auto-generated method stub + } + + public void onAcceptError(IOException arg0) { + // TODO Auto-generated method stub + } + + public ReplicatedCache getCache() { + return cache; + } + + public void setCache(ReplicatedCache cache) { + if (!awake) { + this.cache = cache; + try { + asyncChannel.start(); + } catch (IOException e) { + String msg = "Could start channel for " + cache.getId(); + log.error(msg, e); + throw new CacheException(msg, e); + } + awake = true; + RemoteEvent event = new JoinedEvent(); + event.setCacheId(cache.getId()); + event.setCacheName(cache.getName()); + if (log.isDebugEnabled()) { + log.debug("joining " + cache.getId() + " to the cluster"); + } + send(event); + } else { + // TODO: should this throw an exception? + } + } + + public void send(RemoteEvent update) { + Boolean value = (Boolean) sendEvents.get(); + boolean flag = true; + if (null == value) { + sendEvents.set(new Boolean(true)); + } else { + flag = value.booleanValue(); + } + if (flag) { + ByteArrayOutputStream out = new ByteArrayOutputStream(256); + try { + ObjectOutputStream stream = new ObjectOutputStream(out); + stream.writeObject(update); + stream.flush(); + } catch (IOException e) { + String msg = "Could not write the event " + + update.getCacheName() + " into the buffer"; + log.error(msg, e); + throw new CacheCommunicationException(msg, e); + } + try { + byte data[] = out.toByteArray(); + out.close(); + ByteBuffer src = ByteBuffer.wrap(data); + eventPipe.sink().write(src); + src.clear(); + } catch (IOException e) { + String msg = "Could not write the event for cache " + + update.getCacheName(); + log.error(msg, e); + throw new CacheCommunicationException(msg, e); + } + } + } + + public void recieve(RemoteEvent event) { + if (log.isDebugEnabled()) { + log.debug("Recieved update for " + event.getCacheId()); + } + event.invoke(cache); + } + + public void close() { + try { + //sender.finished(); + //receiver.finished(); + eventPipe.sink().close(); + eventPipe.source().close(); + awake = false; + //sender = null; + //receiver = null; + eventPipe = null; + } catch (IOException e) { + String msg = "Could not close channel for " + cache.getId(); + log.error(msg, e); + throw new CacheException(msg, e); + } + } + + public void setSendEvents(boolean flag) { + this.sendEvents.set(new Boolean(flag)); + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/CacheChannelUDPImpl.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/CacheChannelUDPImpl.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/CacheChannelUDPImpl.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/CacheChannelUDPImpl.java Tue May 23 08:13:52 2006 @@ -0,0 +1,188 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm.impl; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.nio.ByteBuffer; +import java.nio.channels.Pipe; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.cache.CacheException; +import org.apache.geronimo.cache.ReplicatedCache; +import org.apache.geronimo.cache.comm.CacheCommunicationException; +import org.apache.geronimo.cache.comm.CacheChannel; +import org.apache.geronimo.cache.comm.JoinedEvent; +import org.apache.geronimo.cache.comm.RemoteEvent; + +/** + * UDP impl, works for small object changes + * + * $Rev$ $Date$ + */ +public class CacheChannelUDPImpl implements CacheChannel { + public static final int UDP_MAX_PACKET_SIZE = 65507; + + public static final String DEFAULT_GROUP = "230.2.2.1"; + + public static final int DEFAULT_PORT = 10057; + + private Log log = LogFactory.getLog(CacheChannelUDPImpl.class); + + private ReplicatedCache cache = null; + + private Pipe eventPipe = null; + + private boolean awake = false; + + private ClusterSenderRunnable sender; + + private ClusterReceiverRunnable receiver; + + private ThreadLocal sendEvents = new ThreadLocal(); + + private String groupName; + + private int port; + + public CacheChannelUDPImpl() { + try { + eventPipe = Pipe.open(); + } catch (IOException e) { + String msg = "Could not open pipe for " + cache.getId(); + log.error(msg, e); + throw new CacheException(msg, e); + } + } + + public void setSendEvents(boolean shouldSendEvents) { + this.sendEvents.set(new Boolean(shouldSendEvents)); + } + + /* + * puts the update object into the pipe that connects the local cache to the + * thread waiting to send out the change + * + * @see org.apache.geronimo.cache.comm.CacheChannel#send(org.apache.geronimo.cache.comm.RemoteEvent) + * + */ + public void send(RemoteEvent update) { + Boolean value = (Boolean) sendEvents.get(); + boolean flag = true; + if (null == value) { + sendEvents.set(new Boolean(true)); + } else { + flag = value.booleanValue(); + } + if (flag) { + ByteArrayOutputStream out = new ByteArrayOutputStream(256); + try { + ObjectOutputStream stream = new ObjectOutputStream(out); + stream.writeObject(update); + stream.flush(); + } catch (IOException e) { + String msg = "Could not write the event " + + update.getCacheName() + " into the buffer"; + log.error(msg, e); + throw new CacheCommunicationException(msg, e); + } + try { + byte data[] = out.toByteArray(); + out.close(); + ByteBuffer src = ByteBuffer.wrap(data); + eventPipe.sink().write(src); + src.clear(); + } catch (IOException e) { + String msg = "Could not write the event for cache " + + update.getCacheName(); + log.error(msg, e); + throw new CacheCommunicationException(msg, e); + } + } + } + + /* + * A remote peer has been updated, post the change here (non-Javadoc) + * + * @see org.apache.geronimo.cache.comm.CacheChannel#recieve(org.apache.geronimo.cache.comm.RemoteEvent) + */ + public void recieve(RemoteEvent event) { + if (log.isDebugEnabled()) { + log.debug("Recieved update for " + event.getCacheId()); + } + event.invoke(cache); + } + + public void close() { + try { + sender.finished(); + receiver.finished(); + eventPipe.sink().close(); + eventPipe.source().close(); + awake = false; + sender = null; + receiver = null; + eventPipe = null; + } catch (IOException e) { + String msg = "Could not close channel for " + cache.getId(); + log.error(msg, e); + throw new CacheException(msg, e); + } + } + + public ReplicatedCache getCache() { + return cache; + } + + public void setCache(ReplicatedCache cache) { + if (!awake) { + this.cache = cache; + sender = new ClusterSenderRunnable(eventPipe.source(), "sender"); + receiver = new ClusterReceiverRunnable(cache, "receiver"); + receiver.start(); + sender.start(); + awake = true; + RemoteEvent event = new JoinedEvent(); + event.setCacheId(cache.getId()); + event.setCacheName(cache.getName()); + if (log.isDebugEnabled()) { + log.debug("joining " + cache.getId() + " to the cluster"); + } + send(event); + } else { + // TODO: should this throw an exception? + } + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String hostName) { + this.groupName = hostName; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + +} Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/CacheCommListener.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/CacheCommListener.java?rev=408925&view=auto ============================================================================== --- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/CacheCommListener.java (added) +++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/CacheCommListener.java Tue May 23 08:13:52 2006 @@ -0,0 +1,66 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.cache.comm.impl; + +import org.apache.geronimo.cache.CacheEvent; +import org.apache.geronimo.cache.CacheListener; +import org.apache.geronimo.cache.comm.CacheChannel; +import org.apache.geronimo.cache.comm.RemoteAddEvent; +import org.apache.geronimo.cache.comm.RemoteRemoveEvent; +import org.apache.geronimo.cache.comm.RemoteUpdateEvent; + +/** + * This listener is added to the replicated cache and is what sends out the + * changes messages to the rest of the cluster. + * + * $Rev$ $Date$ + */ +public class CacheCommListener implements CacheListener { + private CacheChannel channel = null; + + public CacheCommListener(CacheChannel channel) { + this.channel = channel; + } + + public void entryAdded(CacheEvent event) { + RemoteAddEvent addEvent = new RemoteAddEvent(); + addEvent.setCacheName(event.getCache().getName()); + addEvent.setCacheId(event.getCache().getId()); + addEvent.setKey(event.getKey()); + addEvent.setNewValue(event.getNewValue()); + channel.send(addEvent); + } + + public void entryRemoved(CacheEvent event) { + RemoteRemoveEvent removeEvent = new RemoteRemoveEvent(); + removeEvent.setCacheName(event.getCache().getName()); + removeEvent.setCacheId(event.getCache().getId()); + removeEvent.setKey(event.getKey()); + removeEvent.setOldValue(event.getOldValue()); + channel.send(removeEvent); + } + + public void entryUpdated(CacheEvent event) { + RemoteUpdateEvent updateEvent = new RemoteUpdateEvent(); + updateEvent.setCacheName(event.getCache().getName()); + updateEvent.setCacheId(event.getCache().getId()); + updateEvent.setKey(event.getKey()); + updateEvent.setNewValue(event.getNewValue()); + updateEvent.setOldValue(event.getOldValue()); + channel.send(updateEvent); + } + +}