You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jg...@apache.org on 2006/05/23 17:13:55 UTC
svn commit: r408925 [2/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...
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/ClusterReceiverRunnable.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/ClusterReceiverRunnable.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/ClusterReceiverRunnable.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/ClusterReceiverRunnable.java Tue May 23 08:13:52 2006
@@ -0,0 +1,132 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.net.DatagramPacket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.cache.ReplicatedCache;
+import org.apache.geronimo.cache.comm.CacheCommunicationException;
+import org.apache.geronimo.cache.comm.RemoteEvent;
+
+/**
+ * Reads data from the cluster and posts it locally to the cache so it can be in
+ * sync with the remote sender.
+ *
+ * $Rev$ $Date$
+ */
+class ClusterReceiverRunnable extends Thread {
+ public Log log = LogFactory.getLog(ClusterReceiverRunnable.class);
+
+ private ReplicatedCache cache = null;
+
+ private boolean finished = false;
+
+ private MulticastSocket socket = null;
+
+ public ClusterReceiverRunnable(ReplicatedCache cache, String name) {
+ super(name);
+ this.cache = cache;
+ }
+
+ /**
+ * This is ugly - make a better way
+ */
+ public void finished() {
+ finished = true;
+ if (socket != null) {
+ socket.close();
+ }
+ }
+
+ /**
+ * @throws
+ */
+ public void run() {
+ String host = CacheChannelUDPImpl.DEFAULT_GROUP;
+ int port = CacheChannelUDPImpl.DEFAULT_PORT;
+ try {
+ InetAddress group = InetAddress.getByName(host);
+ socket = new MulticastSocket(port);
+ socket.joinGroup(group);
+ } catch (UnknownHostException e) {
+ String msg = "Could not find host " + host + ":" + port;
+ log.error(msg, e);
+ throw new CacheCommunicationException(msg, e);
+ } catch (IOException e) {
+ String msg = "Host " + host + " is not a multi-cast address";
+ log.error(msg, e);
+ throw new CacheCommunicationException(msg, e);
+ }
+ while (!finished) {
+ try {
+ // read the data
+ DatagramPacket recv = receiveDatagram();
+ // make it into an object
+ RemoteEvent event = convertToObject(recv);
+ // receive the event - but not on the cache that sent it
+ if (!cache.getId().equals(event.getCacheId())) {
+ cache.getChannel().recieve((RemoteEvent) event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Ignored receipt for " + cache.getId());
+ }
+ }
+ } catch (SocketException e) {
+ if (!finished) {
+ String msg = "Error in underlying protocol";
+ log.error(msg, e);
+ throw new CacheCommunicationException(msg, e);
+ }
+ // if we are finished then we can ignore the exception
+ } catch (IOException e) {
+ String msg = "Error reading datagram";
+ log.error(msg, e);
+ throw new CacheCommunicationException(msg, e);
+ } catch (ClassNotFoundException e) {
+ String msg = "Error instanciating RemoteEvent";
+ log.error(msg, e);
+ throw new CacheCommunicationException(msg, e);
+ }
+ }
+
+ }
+
+ private DatagramPacket receiveDatagram() throws IOException {
+ byte[] buf = new byte[CacheChannelUDPImpl.UDP_MAX_PACKET_SIZE];
+ DatagramPacket recv = new DatagramPacket(buf, buf.length);
+ socket.receive(recv);
+ return recv;
+ }
+
+ private RemoteEvent convertToObject(DatagramPacket recv)
+ throws IOException, ClassNotFoundException {
+ ByteArrayInputStream in = new ByteArrayInputStream(recv.getData());
+ ObjectInputStream input = new ObjectInputStream(in);
+ RemoteEvent value = (RemoteEvent) input.readObject();
+ value.setOrigin(recv.getSocketAddress());
+ return value;
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/ClusterSenderRunnable.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/ClusterSenderRunnable.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/ClusterSenderRunnable.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/comm/impl/ClusterSenderRunnable.java Tue May 23 08:13:52 2006
@@ -0,0 +1,122 @@
+/*
+ * 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.IOException;
+import java.net.DatagramPacket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.Pipe;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.Pipe.SourceChannel;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.cache.CacheConfigurationException;
+
+/**
+ * Reads data from the source side of a pipe and writes it to the cluster.
+ *
+ * The local cluster writes events into the SinkChannel of the pipe, this
+ * runnable is blocked waiting for that write. Once the data is read it is
+ * written out to the cluster to be picked up and applied to the local caches of
+ * the various elements of the cluster.
+ *
+ * $Rev$ $Date$
+ */
+class ClusterSenderRunnable extends Thread {
+ public Log log = LogFactory.getLog(ClusterSenderRunnable.class);
+
+ private Pipe.SourceChannel pipeSource;
+
+ private boolean finished = false;
+
+ public ClusterSenderRunnable(Pipe.SourceChannel channel, String name) {
+ super(name);
+ this.pipeSource = channel;
+ try {
+ pipeSource.configureBlocking(false);
+ } catch (IOException e) {
+ String msg = "Could not mark pipe source as non-blocking";
+ log.error(msg, e);
+ throw new CacheConfigurationException(msg, e);
+ }
+ }
+
+ public void finished() {
+ finished = true;
+ }
+
+ public void run() {
+ try {
+ Selector selector = null;
+ selector = Selector.open();
+ pipeSource.register(selector, SelectionKey.OP_READ);
+ ByteBuffer buffer = ByteBuffer
+ .allocate(CacheChannelUDPImpl.UDP_MAX_PACKET_SIZE);
+ while (!finished) {
+ getDataFromPipeAndSendEvent(buffer, selector);
+ }
+ } catch (ClosedChannelException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (SocketException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ private void getDataFromPipeAndSendEvent(ByteBuffer buffer,
+ Selector selector) throws IOException, UnknownHostException {
+ buffer.clear();
+ // TODO: before continuing need to see if we have read all the
+ // data
+ // this blocks for 250milliseconds waiting for data to be written
+ // on the sink side of the pipe
+ int selectedCount = selector.select(250);
+ if (selectedCount != 0) {
+ InetAddress group = InetAddress
+ .getByName(CacheChannelUDPImpl.DEFAULT_GROUP);
+ MulticastSocket socket = new MulticastSocket(
+ CacheChannelUDPImpl.DEFAULT_PORT);
+ socket.joinGroup(group);
+ Iterator itr = selector.selectedKeys().iterator();
+ while (itr.hasNext()) {
+ SelectionKey key = (SelectionKey) itr.next();
+ SourceChannel channel = (SourceChannel) key.channel();
+ if (channel != pipeSource) {
+ continue;
+ }
+ channel.read(buffer);
+ buffer.flip();
+ byte data[] = buffer.array();
+ DatagramPacket hi = new DatagramPacket(data, buffer.limit(),
+ group, CacheChannelUDPImpl.DEFAULT_PORT);
+ socket.send(hi);
+ itr.remove();
+ }
+ }
+ }
+}
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/config/CacheConfig.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/config/CacheConfig.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/config/CacheConfig.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/config/CacheConfig.java Tue May 23 08:13:52 2006
@@ -0,0 +1,112 @@
+/*
+ * 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.config;
+
+import java.util.Map;
+
+import org.apache.geronimo.cache.xmlbeans.GEvictionPolicyType;
+
+/**
+ * The cache configuration. The data is read from the XML config file
+ * and used to specify the way the caches should be configured.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CacheConfig {
+
+ /**
+ * The policy used to evict elements
+ */
+ private GEvictionPolicyType.Enum policy = GEvictionPolicyType.LEAST_RECENTLY_USED;
+ /**
+ * Cache name, usually used as a rendevous hook for distributed caches
+ */
+ private String name;
+ /**
+ * max elements this cache will allow in memory at once.
+ * additional elmements will be evicted according to the policy
+ */
+ private Integer maxElementCount;
+ /**
+ * Once the max element count is reached elements will be evicted
+ * until this min count is reached
+ */
+ private Integer minElementsCount;
+ /**
+ * How to store the elements
+ */
+ private CacheStorageConfig storageConfig = null;
+ /**
+ * The impl class to use
+ *
+ */
+ private String cacheImpl = null;
+
+ public CacheConfig() {
+ }
+
+ public Integer getMaxElementCount() {
+ return maxElementCount;
+ }
+
+ public void setMaxElementCount(Integer maxElementCount) {
+ this.maxElementCount = maxElementCount;
+ }
+
+ public Integer getMinElementsCount() {
+ return minElementsCount;
+ }
+
+ public void setMinElementsCount(Integer minElementsCount) {
+ this.minElementsCount = minElementsCount;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public GEvictionPolicyType.Enum getPolicy() {
+ return policy;
+ }
+
+ public void setPolicy(GEvictionPolicyType.Enum policy) {
+ this.policy = policy;
+ }
+
+ public CacheStorageConfig getStorageConfig() {
+ return storageConfig;
+ }
+
+ public String getCacheImpl() {
+ return cacheImpl;
+ }
+
+ public void setCacheImpl(String cacheImpl) {
+ this.cacheImpl = cacheImpl;
+ }
+
+ public void setStorageConfig(CacheStorageConfig storageConfig) {
+ this.storageConfig = storageConfig;
+ }
+
+ public void setAdditionalConfiguration(Map values) {
+ // default does nothing
+ }
+}
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/config/CacheStorageConfig.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/config/CacheStorageConfig.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/config/CacheStorageConfig.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/config/CacheStorageConfig.java Tue May 23 08:13:52 2006
@@ -0,0 +1,58 @@
+/*
+ * 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.config;
+
+import org.apache.geronimo.cache.xmlbeans.GStorageImplType;
+
+/**
+ * The storage specification for the cache.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CacheStorageConfig {
+ private String name;
+ private GStorageImplType.Enum builtInType = GStorageImplType.MEMORY;
+
+ private String storageImpl = null;
+
+ public CacheStorageConfig() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public GStorageImplType.Enum getBuiltInType() {
+ return builtInType;
+ }
+
+ public void setBuiltInType(GStorageImplType.Enum builtInType) {
+ this.builtInType = builtInType;
+ }
+
+ public String getStorageImpl() {
+ return storageImpl;
+ }
+
+ public void setStorageImpl(String storageImpl) {
+ this.storageImpl = storageImpl;
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/AbstractCache.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/AbstractCache.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/AbstractCache.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/AbstractCache.java Tue May 23 08:13:52 2006
@@ -0,0 +1,25 @@
+/*
+ * 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.impl;
+
+/**
+ * needs to be deleted
+ *
+ * $Rev$ $Date$
+ */
+public class AbstractCache {
+
+}
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/CacheMemoryStoreImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/CacheMemoryStoreImpl.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/CacheMemoryStoreImpl.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/CacheMemoryStoreImpl.java Tue May 23 08:13:52 2006
@@ -0,0 +1,95 @@
+/*
+ * 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.impl;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.cache.CacheStore;
+
+/**
+ * Simple storage into a hashmap
+ *
+ * $Rev$ $Date$
+ */
+public class CacheMemoryStoreImpl implements CacheStore {
+ private Map elements = new HashMap();
+
+ public CacheMemoryStoreImpl() {
+ }
+
+ public Map getAll(Set keys) {
+ Map values = new HashMap();
+ Iterator itr = keys.iterator();
+ while(itr.hasNext()) {
+ Object key = itr.next();
+ Object value = get(key);
+ values.put(key, value);
+ }
+ return values;
+ }
+ public int size() {
+ return elements.size();
+ }
+
+ public boolean isEmpty() {
+ return elements.isEmpty();
+ }
+
+ public boolean containsKey(Object key) {
+ return elements.containsKey(key);
+ }
+
+ public boolean containsValue(Object value) {
+ return elements.containsValue(value);
+ }
+
+ public Object get(Object key) {
+ return elements.get(key);
+ }
+
+ public Object put(Object key, Object value) {
+ return elements.put(key, value);
+ }
+
+ public Object remove(Object key) {
+ return elements.remove(key);
+ }
+
+ public void putAll(Map t) {
+ elements.putAll(t);
+ }
+
+ public void clear() {
+ elements.clear();
+ }
+
+ public Set keySet() {
+ return elements.keySet();
+ }
+
+ public Collection values() {
+ return elements.values();
+ }
+
+ public Set entrySet() {
+ return elements.entrySet();
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/LocalCacheImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/LocalCacheImpl.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/LocalCacheImpl.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/LocalCacheImpl.java Tue May 23 08:13:52 2006
@@ -0,0 +1,357 @@
+/*
+ * 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.impl;
+
+import java.rmi.server.UID;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.cache.CacheEvent;
+import org.apache.geronimo.cache.CacheListener;
+import org.apache.geronimo.cache.CacheStore;
+import org.apache.geronimo.cache.LocalCache;
+import org.apache.geronimo.cache.config.CacheConfig;
+
+/**
+ * Simple local cache implementation
+ *
+ * TODO: build out the eviction policy stuff
+ *
+ * $Rev$ $Date$
+ */
+public class LocalCacheImpl extends AbstractCache implements LocalCache {
+ public final String DEFAULT_CACHE_NAME = "DefaultCacheName";
+
+ private CacheStore store = null;
+
+ private UID id = null;
+
+ private String name = DEFAULT_CACHE_NAME;
+
+ // simple impl
+ private boolean locked = false;
+
+ // simple impl of locking elements
+ private Map locks = new HashMap();
+
+ private List listeners = new ArrayList();
+
+ private Map keyListeners = new HashMap();
+
+ public LocalCacheImpl() {
+ super();
+ }
+
+ public LocalCacheImpl(String name) {
+ super();
+ this.name = name;
+ }
+
+ public UID getId() {
+ if (id == null) {
+ id = new UID();
+ }
+ return id;
+ }
+
+ public CacheStore getStore() {
+ if (null == store) {
+ store = new CacheMemoryStoreImpl();
+ }
+ return store;
+ }
+
+ public void setStore(CacheStore store) {
+ this.store = store;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public synchronized boolean lock() {
+ // simple impl
+ locked = true;
+ return locked;
+ }
+
+ public synchronized boolean lock(long timeoutMilliSeconds) {
+ // simple impl
+ locked = true;
+ return locked;
+ }
+
+ public synchronized boolean unlock() {
+ locked = false;
+ return true;
+ }
+
+ public boolean lock(Object key) {
+ synchronized (locks) {
+ locks.put(key, Boolean.TRUE);
+ }
+ return true;
+ }
+
+ public boolean lock(Object key, long timeoutMilliSeconds) {
+ boolean flag = false;
+ if (containsKey(key)) {
+ synchronized (locks) {
+ locks.put(key, Boolean.TRUE);
+ }
+ flag = true;
+ }
+ return flag;
+ }
+
+ public boolean unlock(Object key) {
+ synchronized (locks) {
+ locks.remove(key);
+ }
+ return true;
+ }
+
+ public void addListener(CacheListener listener) {
+ checkListener(listener);
+ synchronized (listeners) {
+ listeners.add(listener);
+ }
+ }
+
+ public void addListener(CacheListener listener, Object key) {
+ checkListener(listener);
+ synchronized (keyListeners) {
+ List stuff = (List) keyListeners.get(key);
+ if (null == stuff) {
+ stuff = new ArrayList(2);
+ keyListeners.put(key, stuff);
+ }
+ stuff.add(listener);
+ }
+ }
+
+ public void removeListener(CacheListener listener) {
+ synchronized (listeners) {
+ listeners.remove(listener);
+ }
+ }
+
+ public void removeListener(CacheListener listener, Object key) {
+ synchronized (keyListeners) {
+ List stuff = (List) keyListeners.get(key);
+ if (stuff != null) {
+ stuff.remove(listener);
+ }
+ }
+ }
+
+ public void setConfiguration(CacheConfig config) {
+ name = config.getName();
+ }
+
+ public Map getAll(Set keys) {
+ return getStore().getAll(keys);
+ }
+
+ public synchronized int size() {
+ return getStore().size();
+ }
+
+ public synchronized boolean isEmpty() {
+ return getStore().isEmpty();
+ }
+
+ public synchronized boolean containsKey(Object key) {
+ return getStore().containsKey(key);
+ }
+
+ public synchronized boolean containsValue(Object value) {
+ return getStore().containsValue(value);
+ }
+
+ public synchronized Object get(Object key) {
+ return getStore().get(key);
+ }
+
+ public synchronized Object put(Object key, Object value) {
+ checkLock(key);
+ Object oldValue = getStore().put(key, value);
+ if (oldValue == null) {
+ informListenersOfPut(key, value);
+ } else {
+ informListenersOfUpdate(key, oldValue, value);
+ }
+ return oldValue;
+ }
+
+ public synchronized Object remove(Object key) {
+ checkLock(key);
+ Object oldValue = getStore().remove(key);
+ informListenersOfRemove(key, oldValue);
+ return oldValue;
+ }
+
+ public synchronized void putAll(Map t) {
+ Set keySet = t.keySet();
+ checkLocks(keySet);
+ // TODO: this is a lazy way to do things
+ Iterator itr = keySet.iterator();
+ while (itr.hasNext()) {
+ Object key = itr.next();
+ put(key, t.get(key));
+ }
+ }
+
+ public synchronized void clear() {
+ if (locked) {
+ throw new IllegalStateException("Cache '" + name + "' is locked");
+ }
+ // TODO: this is a lazy way to do things
+ Set keySet = new HashSet(keySet());
+ checkLocks(keySet);
+ Iterator itr = keySet.iterator();
+ while (itr.hasNext()) {
+ remove(itr.next());
+ }
+ }
+
+ public synchronized Set keySet() {
+ return getStore().keySet();
+ }
+
+ public synchronized Collection values() {
+ return getStore().values();
+ }
+
+ public synchronized Set entrySet() {
+ return getStore().entrySet();
+ }
+
+ private void checkListener(CacheListener listener) {
+ if (listener == null) {
+ throw new NullPointerException("listner must not be null");
+ }
+ }
+
+ private void informListenersOfPut(Object key, Object value) {
+ synchronized (keyListeners) {
+ if (keyListeners.containsKey(key)) {
+ Iterator itr = ((List) keyListeners.get(key)).iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, null, value, this);
+ listener.entryAdded(event);
+ }
+ }
+ }
+ synchronized (listeners) {
+ Iterator itr = listeners.iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, null, value, this);
+ listener.entryAdded(event);
+ }
+ }
+ }
+
+ private void informListenersOfUpdate(Object key, Object oldValue,
+ Object value) {
+ synchronized (keyListeners) {
+ if (keyListeners.containsKey(key)) {
+ Iterator itr = ((List) keyListeners.get(key)).iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, oldValue, value,
+ this);
+ listener.entryUpdated(event);
+ }
+ }
+ }
+ synchronized (listeners) {
+ Iterator itr = listeners.iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, oldValue, value, this);
+ listener.entryUpdated(event);
+ }
+ }
+ }
+
+ private void informListenersOfRemove(Object key, Object oldValue) {
+ synchronized (keyListeners) {
+ if (keyListeners.containsKey(key)) {
+ Iterator itr = ((List) keyListeners.get(key)).iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, oldValue, null, this);
+ listener.entryRemoved(event);
+ }
+ }
+ }
+ synchronized (listeners) {
+ Iterator itr = listeners.iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, oldValue, null, this);
+ listener.entryRemoved(event);
+ }
+ }
+ }
+
+ private void checkLock(Object key) {
+ if (locked) {
+ throw new IllegalStateException("Cache '" + name + "' is locked");
+ } else {
+ synchronized (locks) {
+ if (locks.containsKey(key)) {
+ throw new IllegalStateException("Key " + key
+ + " is locked in cache " + name);
+ }
+ }
+ }
+ }
+
+ private void checkLocks(Set keys) {
+ if (locked) {
+ throw new IllegalStateException("Cache '" + name + "' is locked");
+ } else {
+ synchronized (locks) {
+ if (!locks.isEmpty()) {
+ Set lockKeys = new HashSet(locks.keySet());
+ lockKeys.retainAll(keys);
+ if (!lockKeys.isEmpty()) {
+ throw new IllegalStateException("Keys " + lockKeys
+ + " are locked in cache " + name);
+ }
+ /*
+ * Object key = null; Iterator itr = keys.iterator(); while
+ * (itr.hasNext()) { key = itr.next(); if
+ * (locks.containsKey(key)) { throw new
+ * IllegalStateException("Key " + key + " is locked in cache " +
+ * name); } }
+ */
+ }
+ }
+ }
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/ReplicatedCacheImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/ReplicatedCacheImpl.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/ReplicatedCacheImpl.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/impl/ReplicatedCacheImpl.java Tue May 23 08:13:52 2006
@@ -0,0 +1,376 @@
+/*
+ * 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.impl;
+
+import java.net.InetAddress;
+import java.rmi.server.UID;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.cache.CacheEvent;
+import org.apache.geronimo.cache.CacheListener;
+import org.apache.geronimo.cache.LocalCache;
+import org.apache.geronimo.cache.ReplicatedCache;
+import org.apache.geronimo.cache.comm.CacheChannel;
+import org.apache.geronimo.cache.config.CacheConfig;
+
+/**
+ * Simple local cache implementation
+ *
+ * TODO: build out the eviction policy stuff
+ *
+ * TODO: this does not do everything it should in terms of distribution, locking
+ * is not propigated for example
+ *
+ * TODO: the code here is copied from the LocalCacheImpl, need to abstract them
+ * and get rid of duplicated code
+ *
+ * $Rev$ $Date$
+ */
+public class ReplicatedCacheImpl extends AbstractCache implements
+ ReplicatedCache {
+ public final String DEFAULT_CACHE_NAME = "DefaultCacheName";
+
+ private LocalCache backingCache = null;
+
+ private CacheChannel channel = null;
+
+ private InetAddress cacheAddress;
+
+ private String name = DEFAULT_CACHE_NAME;
+
+ private UID id = null;
+
+ // simple impl
+ private boolean locked = false;
+
+ // simple impl of locking elements
+ private Map locks = new HashMap();
+
+ private List listeners = new ArrayList();
+
+ private Map keyListeners = new HashMap();
+
+ public ReplicatedCacheImpl(CacheChannel channel) {
+ super();
+ setChannel(channel);
+ }
+
+ public ReplicatedCacheImpl(CacheChannel channel, String name) {
+ super();
+ this.name = name;
+ setChannel(channel);
+ }
+
+ public CacheChannel getChannel() {
+ return channel;
+ }
+
+ public void setChannel(CacheChannel channel) {
+ this.channel = channel;
+ channel.setCache(this);
+ }
+
+ public LocalCache getBackingCache() {
+ if (backingCache == null) {
+ backingCache = new LocalCacheImpl();
+ }
+ return backingCache;
+ }
+
+ public InetAddress getCacheAddress() {
+ return cacheAddress;
+ }
+
+ public UID getId() {
+ if (id == null) {
+ id = new UID();
+ }
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public synchronized boolean lock() {
+ // simple impl
+ locked = true;
+ return locked;
+ }
+
+ public synchronized boolean lock(long timeoutMilliSeconds) {
+ // simple impl
+ locked = true;
+ return locked;
+ }
+
+ public synchronized boolean unlock() {
+ locked = false;
+ return true;
+ }
+
+ public boolean lock(Object key) {
+ synchronized (locks) {
+ locks.put(key, Boolean.TRUE);
+ }
+ return true;
+ }
+
+ public boolean lock(Object key, long timeoutMilliSeconds) {
+ boolean flag = false;
+ if (containsKey(key)) {
+ synchronized (locks) {
+ locks.put(key, Boolean.TRUE);
+ }
+ flag = true;
+ }
+ return flag;
+ }
+
+ public boolean unlock(Object key) {
+ synchronized (locks) {
+ locks.remove(key);
+ }
+ return true;
+ }
+
+ public void addListener(CacheListener listener) {
+ checkListener(listener);
+ synchronized (listeners) {
+ listeners.add(listener);
+ }
+ }
+
+ public void addListener(CacheListener listener, Object key) {
+ checkListener(listener);
+ synchronized (keyListeners) {
+ List stuff = (List) keyListeners.get(key);
+ if (null == stuff) {
+ stuff = new ArrayList(2);
+ keyListeners.put(key, stuff);
+ }
+ stuff.add(listener);
+ }
+ }
+
+ public void removeListener(CacheListener listener) {
+ synchronized (listeners) {
+ listeners.remove(listener);
+ }
+ }
+
+ public void removeListener(CacheListener listener, Object key) {
+ synchronized (keyListeners) {
+ List stuff = (List) keyListeners.get(key);
+ if (stuff != null) {
+ stuff.remove(listener);
+ }
+ }
+ }
+
+ public void setConfiguration(CacheConfig config) {
+ name = config.getName();
+ }
+
+ public Map getAll(Set keys) {
+ return getBackingCache().getAll(keys);
+ }
+
+ public synchronized int size() {
+ return getBackingCache().size();
+ }
+
+ public synchronized boolean isEmpty() {
+ return getBackingCache().isEmpty();
+ }
+
+ public synchronized boolean containsKey(Object key) {
+ return getBackingCache().containsKey(key);
+ }
+
+ public synchronized boolean containsValue(Object value) {
+ return getBackingCache().containsValue(value);
+ }
+
+ public synchronized Object get(Object key) {
+ return getBackingCache().get(key);
+ }
+
+ public synchronized Object put(Object key, Object value) {
+ checkLock(key);
+ Object oldValue = getBackingCache().put(key, value);
+ if (oldValue == null) {
+ informListenersOfPut(key, value);
+ } else {
+ informListenersOfUpdate(key, oldValue, value);
+ }
+ return oldValue;
+ }
+
+ public synchronized Object remove(Object key) {
+ checkLock(key);
+ Object oldValue = getBackingCache().remove(key);
+ informListenersOfRemove(key, oldValue);
+ return oldValue;
+ }
+
+ public synchronized void putAll(Map t) {
+ Set keySet = t.keySet();
+ checkLocks(keySet);
+ // TODO: this is a lazy way to do things
+ // should be posting a group event of all the changes
+ // but that would be prohibative
+ Iterator itr = keySet.iterator();
+ while (itr.hasNext()) {
+ Object key = itr.next();
+ put(key, t.get(key));
+ }
+ }
+
+ public synchronized void clear() {
+ if (locked) {
+ throw new IllegalStateException("Cache '" + name + "' is locked");
+ }
+ // TODO: this is a lazy way to do things
+ Set keySet = new HashSet(keySet());
+ checkLocks(keySet);
+ Iterator itr = keySet.iterator();
+ while (itr.hasNext()) {
+ remove(itr.next());
+ }
+ }
+
+ public synchronized Set keySet() {
+ return getBackingCache().keySet();
+ }
+
+ public synchronized Collection values() {
+ return getBackingCache().values();
+ }
+
+ public synchronized Set entrySet() {
+ return getBackingCache().entrySet();
+ }
+
+ private void checkListener(CacheListener listener) {
+ if (listener == null) {
+ throw new NullPointerException("listner must not be null");
+ }
+ }
+
+ private void informListenersOfPut(Object key, Object value) {
+ synchronized (keyListeners) {
+ if (keyListeners.containsKey(key)) {
+ Iterator itr = ((List) keyListeners.get(key)).iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, null, value, this);
+ listener.entryAdded(event);
+ }
+ }
+ }
+ synchronized (listeners) {
+ Iterator itr = listeners.iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, null, value, this);
+ listener.entryAdded(event);
+ }
+ }
+ }
+
+ private void informListenersOfUpdate(Object key, Object oldValue,
+ Object value) {
+ synchronized (keyListeners) {
+ if (keyListeners.containsKey(key)) {
+ Iterator itr = ((List) keyListeners.get(key)).iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, oldValue, value,
+ this);
+ listener.entryUpdated(event);
+ }
+ }
+ }
+ synchronized (listeners) {
+ Iterator itr = listeners.iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, oldValue, value, this);
+ listener.entryUpdated(event);
+ }
+ }
+ }
+
+ private void informListenersOfRemove(Object key, Object oldValue) {
+ synchronized (keyListeners) {
+ if (keyListeners.containsKey(key)) {
+ Iterator itr = ((List) keyListeners.get(key)).iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, oldValue, null, this);
+ listener.entryRemoved(event);
+ }
+ }
+ }
+ synchronized (listeners) {
+ Iterator itr = listeners.iterator();
+ while (itr.hasNext()) {
+ CacheListener listener = (CacheListener) itr.next();
+ CacheEvent event = new CacheEvent(key, oldValue, null, this);
+ listener.entryRemoved(event);
+ }
+ }
+ }
+
+ private void checkLock(Object key) {
+ if (locked) {
+ throw new IllegalStateException("Cache '" + name + "' is locked");
+ } else {
+ synchronized (locks) {
+ if (locks.containsKey(key)) {
+ throw new IllegalStateException("Key " + key
+ + " is locked in cache " + name);
+ }
+ }
+ }
+ }
+
+ private void checkLocks(Set keys) {
+ if (locked) {
+ throw new IllegalStateException("Cache '" + name + "' is locked");
+ } else {
+ synchronized (locks) {
+ if (!locks.isEmpty()) {
+ Set lockKeys = new HashSet(locks.keySet());
+ lockKeys.retainAll(keys);
+ if (!lockKeys.isEmpty()) {
+ throw new IllegalStateException("Keys " + lockKeys
+ + " are locked in cache " + name);
+ }
+ }
+ }
+ }
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheLocator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheLocator.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheLocator.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheLocator.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.session.impl;
+
+import org.apache.geronimo.session.Locator;
+import org.apache.geronimo.session.Server;
+import org.apache.geronimo.session.Session;
+import org.apache.geronimo.session.SessionAlreadyExistsException;
+import org.apache.geronimo.session.SessionLocation;
+
+/**
+ * A locator for a cached session.
+ *
+ * $Rev$ $Date$
+ */
+public class CacheLocator implements Locator {
+
+ public CacheLocator() {
+ super();
+ }
+
+ public SessionLocation getSessionLocation(String clientId) {
+ return null;
+ }
+
+ public Session createSession(String clientId)
+ throws SessionAlreadyExistsException {
+ return null;
+ }
+
+ public Server getLocalServer() {
+ return null;
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheServer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheServer.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheServer.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheServer.java Tue May 23 08:13:52 2006
@@ -0,0 +1,49 @@
+/*
+ * 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.session.impl;
+
+import org.apache.geronimo.session.Server;
+
+/**
+ *
+ * $Rev$ $Date$
+ */
+public class CacheServer implements Server {
+
+ public CacheServer() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String[] getAddresses(String protocol) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setAddresses(String protocol, String[] addresses) {
+ // TODO Auto-generated method stub
+ }
+
+ public boolean isLocalServer() {
+ return true;
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheSession.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheSession.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheSession.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheSession.java Tue May 23 08:13:52 2006
@@ -0,0 +1,62 @@
+/*
+ * 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.session.impl;
+
+import org.apache.geronimo.session.Session;
+
+/**
+ * $Rev$ $Date$
+ */
+public class CacheSession implements Session {
+
+ public CacheSession() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public String getSessionId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void release() {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.session.Session#addState(java.lang.String, java.lang.Object)
+ */
+ public void addState(String key, Object value) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.session.Session#getState(java.lang.String)
+ */
+ public Object getState(String key) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.session.Session#removeState(java.lang.String)
+ */
+ public Object removeState(String key) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheSessionLocation.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheSessionLocation.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheSessionLocation.java (added)
+++ geronimo/sandbox/geronimo-cache/src/main/java/org/apache/geronimo/cache/session/impl/CacheSessionLocation.java Tue May 23 08:13:52 2006
@@ -0,0 +1,93 @@
+/*
+ * 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.session.impl;
+
+import org.apache.geronimo.session.NoSuchSessionException;
+import org.apache.geronimo.session.Server;
+import org.apache.geronimo.session.Session;
+import org.apache.geronimo.session.SessionLocation;
+import org.apache.geronimo.session.SessionNotLocalException;
+import org.apache.geronimo.session.SessionNotMovableException;
+import org.apache.geronimo.session.WriteLockTimedOutException;
+
+/**
+ * $Rev$ $Date$
+ */
+public class CacheSessionLocation implements SessionLocation {
+
+ public CacheSessionLocation() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.session.SessionLocation#isLocal()
+ */
+ public boolean isLocal() {
+ // a fully replicated session is always local
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.session.SessionLocation#isMovable()
+ */
+ public boolean isMovable() {
+ // can't move an item in a replicated cache, its always local
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.session.SessionLocation#getSessionId()
+ */
+ public String getSessionId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.session.SessionLocation#getServer()
+ */
+ public Server getServer() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.session.SessionLocation#getSession()
+ */
+ public Session getSession() throws SessionNotLocalException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.session.SessionLocation#moveLocally()
+ */
+ public Session moveLocally() throws NoSuchSessionException,
+ WriteLockTimedOutException, SessionNotLocalException,
+ SessionNotMovableException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.geronimo.session.SessionLocation#destroy()
+ */
+ public void destroy() throws SessionNotLocalException {
+ // TODO Auto-generated method stub
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/main/xsd/geronimo-cache-1.0.xsd
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/xsd/geronimo-cache-1.0.xsd?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/xsd/geronimo-cache-1.0.xsd (added)
+++ geronimo/sandbox/geronimo-cache/src/main/xsd/geronimo-cache-1.0.xsd Tue May 23 08:13:52 2006
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+ $Rev$ $Date$
+ -->
+<xs:schema xmlns:cache="http://geronimo.apache.org/xml/ns/cache-1.0"
+ targetNamespace="http://geronimo.apache.org/xml/ns/cache-1.0"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
+
+ <xs:element name="cache-config" type="cache:cache-configType">
+ <xs:key name="cacheNameKey">
+ <xs:selector xpath="./cache" />
+ <xs:field xpath="@cacheName" />
+ </xs:key>
+ <xs:key name="storageNameKey">
+ <xs:selector xpath="./storage" />
+ <xs:field xpath="@storageName" />
+ </xs:key>
+ <xs:keyref refer="cache:storageNameKey"
+ name="storageNameKeyRef">
+ <xs:selector xpath="./cache-config/cache/storageRef" />
+ <xs:field xpath="@storageNameRef" />
+ </xs:keyref>
+ </xs:element>
+
+ <xs:element name="cache" type="cache:cacheType" />
+ <xs:element name="storage" type="cache:storageType" />
+ <xs:element name="cache-impl" type="xs:string" />
+ <xs:element name="storage-strategy" type="cache:storage-impl-type" />
+ <xs:element name="storage-impl" type="xs:string" />
+ <xs:element name="storageRef" type="cache:storageRefType" />
+
+ <xs:complexType name="cache-configType">
+ <xs:sequence>
+ <xs:element ref="cache:cache" minOccurs="1"
+ maxOccurs="unbounded" />
+ <xs:element ref="cache:storage" minOccurs="1"
+ maxOccurs="unbounded" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="cacheType">
+ <xs:sequence>
+ <xs:element ref="cache:cache-impl" minOccurs="1"
+ maxOccurs="1" />
+ <xs:element ref="cache:storageRef" minOccurs="1"
+ maxOccurs="1" />
+ <xs:any minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ <xs:attribute name="cacheName" type="xs:string" use="required" />
+ <xs:attribute name="evictionPolicy"
+ type="cache:eviction-policy-type" />
+ </xs:complexType>
+
+ <xs:complexType name="storageType">
+ <xs:sequence>
+ <xs:element ref="cache:storage-strategy" minOccurs="1"
+ maxOccurs="1" />
+ <xs:element ref="cache:storage-impl" minOccurs="0"
+ maxOccurs="1" />
+ <xs:any namespace="##other" minOccurs="0"
+ maxOccurs="unbounded" />
+ </xs:sequence>
+ <xs:attribute name="storageName" type="xs:string"
+ use="required" />
+ </xs:complexType>
+
+ <xs:complexType name="storageRefType">
+ <xs:attribute name="storageNameRef" type="xs:string"
+ use="required" />
+ </xs:complexType>
+
+
+ <xs:simpleType name="eviction-policy-type">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="LEAST_RECENTLY_USED" />
+ <xs:enumeration value="LEAST_FREQUENTLY_USED" />
+ <xs:enumeration value="HYBRID_USED" />
+ <xs:enumeration value="FIRST_IN_FIRST_OUT" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:simpleType name="storage-impl-type">
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="MEMORY" /><!-- no disk storage at all -->
+ <xs:enumeration value="FILE" /><!-- memory backed by disk -->
+ <xs:enumeration value="CUSTOM" /><!-- if this is specified you must specify the impl class -->
+ </xs:restriction>
+ </xs:simpleType>
+
+</xs:schema>
Added: geronimo/sandbox/geronimo-cache/src/main/xsd/xmlconfig.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/main/xsd/xmlconfig.xml?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/main/xsd/xmlconfig.xml (added)
+++ geronimo/sandbox/geronimo-cache/src/main/xsd/xmlconfig.xml Tue May 23 08:13:52 2006
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+ -->
+<!-- @version $Rev$ $Date$ -->
+<xb:config xmlns:xb="http://www.bea.com/2002/09/xbean/config">
+ <xb:namespace uri="http://geronimo.apache.org/xml/ns/cache-1.0">
+ <xb:package>org.apache.geronimo.cache.xmlbeans</xb:package>
+ <xb:prefix>G</xb:prefix>
+ </xb:namespace>
+</xb:config>
Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheConfigurationExceptionTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheConfigurationExceptionTest.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheConfigurationExceptionTest.java (added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheConfigurationExceptionTest.java Tue May 23 08:13:52 2006
@@ -0,0 +1,61 @@
+/*
+ * 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 junit.framework.TestCase;
+
+/**
+ *
+ * $Rev$ $Date$
+ */
+public class CacheConfigurationExceptionTest extends TestCase {
+
+ public CacheConfigurationExceptionTest(String arg0) {
+ super(arg0);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testCacheConfigurationException() {
+ CacheConfigurationException e = new CacheConfigurationException();
+ assertNull(e.getCause());
+ }
+
+ public void testCacheConfigurationExceptionString() {
+ CacheConfigurationException e = new CacheConfigurationException("message");
+ assertEquals("message", e.getMessage());
+ }
+
+ public void testCacheConfigurationExceptionStringThrowable() {
+ Throwable t = new Throwable("wowzer");
+ CacheConfigurationException e = new CacheConfigurationException(t);
+ assertEquals(t, e.getCause());
+ }
+
+ public void testCacheConfigurationExceptionThrowable() {
+ Throwable t = new Throwable("wowzer");
+ CacheConfigurationException e = new CacheConfigurationException("wonder", t);
+ assertEquals("wonder", e.getMessage());
+ assertEquals(t, e.getCause());
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheEventTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheEventTest.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheEventTest.java (added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheEventTest.java Tue May 23 08:13:52 2006
@@ -0,0 +1,64 @@
+/*
+ * 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 junit.framework.TestCase;
+
+/**
+ *
+ * $Rev$ $Date$
+ */
+public class CacheEventTest extends TestCase {
+
+ public CacheEventTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testCacheEvent() {
+ CacheEvent event = new CacheEvent("key", "oldValue", "newValue", null);
+ assertEquals("key", event.getKey());
+ assertEquals("oldValue", event.getOldValue());
+ assertEquals("newValue", event.getNewValue());
+ assertNull(event.getCache());
+ }
+
+ public void testKey() {
+ CacheEvent event = new CacheEvent("key", "oldValue", "newValue", null);
+ event.setKey("foo");
+ assertEquals("foo", event.getKey());
+ }
+
+ public void testOldValue() {
+ CacheEvent event = new CacheEvent("key", "oldValue", "newValue", null);
+ event.setOldValue("foo");
+ assertEquals("foo", event.getOldValue());
+ }
+
+ public void testNewValue() {
+ CacheEvent event = new CacheEvent("key", "oldValue", "newValue", null);
+ event.setNewValue("foo");
+ assertEquals("foo", event.getNewValue());
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheExceptionTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheExceptionTest.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheExceptionTest.java (added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheExceptionTest.java Tue May 23 08:13:52 2006
@@ -0,0 +1,61 @@
+/*
+ * 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 junit.framework.TestCase;
+
+/**
+ *
+ * $Rev$ $Date$
+ */
+public class CacheExceptionTest extends TestCase {
+
+ public CacheExceptionTest(String arg0) {
+ super(arg0);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testCacheConfigurationException() {
+ CacheException e = new CacheException();
+ assertNull(e.getCause());
+ }
+
+ public void testCacheConfigurationExceptionString() {
+ CacheException e = new CacheException("message");
+ assertEquals("message", e.getMessage());
+ }
+
+ public void testCacheConfigurationExceptionStringThrowable() {
+ Throwable t = new Throwable("wowzer");
+ CacheException e = new CacheException(t);
+ assertEquals(t, e.getCause());
+ }
+
+ public void testCacheConfigurationExceptionThrowable() {
+ Throwable t = new Throwable("wowzer");
+ CacheException e = new CacheException("wonder", t);
+ assertEquals("wonder", e.getMessage());
+ assertEquals(t, e.getCause());
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheManagerTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheManagerTest.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheManagerTest.java (added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/CacheManagerTest.java Tue May 23 08:13:52 2006
@@ -0,0 +1,76 @@
+/*
+ * 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 junit.framework.TestCase;
+
+/**
+ *
+ * $Rev$ $Date$
+ */
+public class CacheManagerTest extends TestCase {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(CacheManagerTest.class);
+ }
+
+ public CacheManagerTest(String arg0) {
+ super(arg0);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /*
+ * Test method for 'org.apache.gernoimo.cache.GCacheManager.GCacheManager()'
+ */
+ public void testGCacheManager() {
+ CacheManager manager = new CacheManager();
+ Cache cache = manager.getCache("testCache");
+ assertNotNull(cache);
+ assertEquals("testCache", cache.getName());
+ }
+
+ /*
+ * Test method for
+ * 'org.apache.gernoimo.cache.GCacheManager.GCacheManager(ClassLoader)'
+ */
+ public void testGCacheManagerClassLoader() {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ CacheManager manager = new CacheManager(loader);
+ Cache cache = manager.getCache("testCache");
+ assertNotNull(cache);
+ assertEquals("testCache", cache.getName());
+ assertEquals(loader, cache.getClass().getClassLoader());
+ }
+
+ /*
+ * Test method for
+ * 'org.apache.gernoimo.cache.GCacheManager.getCache(String)'
+ */
+ public void testGetCache() {
+ CacheManager manager = new CacheManager();
+ Cache cache = manager.getCache("testCache");
+ assertNotNull(cache);
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/LocalCacheTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/LocalCacheTest.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/LocalCacheTest.java (added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/LocalCacheTest.java Tue May 23 08:13:52 2006
@@ -0,0 +1,368 @@
+/*
+ * 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.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * $Rev$ $Date$
+ */
+public class LocalCacheTest extends TestCase {
+ private LocalCache subject = null;
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(LocalCacheTest.class);
+ }
+
+ public LocalCacheTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ // TODO: this will get slow running for each test...
+ CacheManager cacheManager = new CacheManager();
+ subject = (LocalCache) cacheManager.getCache("testCache");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ subject = null;
+ }
+
+ /*
+ * Test method for 'org.apache.geronimo.cache.GCache.getName()'
+ */
+ public void testGetName() {
+ assertEquals("testCache", subject.getName());
+ }
+
+ /*
+ * Test method for 'org.apache.geronimo.cache.GCache.getStore()'
+ */
+ public void testGetStore() {
+ assertNotNull(subject.getStore());
+ }
+
+ /*
+ * Test method for 'org.apache.geronimo.cache.GCache.lock()'
+ */
+ public void testLock() {
+ assertTrue(subject.lock());
+ try {
+ subject.put("one", "two");
+ fail("Should have thrown an exception");
+ } catch (Throwable t) {
+ // intentionally blank
+ }
+ }
+
+ /*
+ * Test method for 'org.apache.geronimo.cache.GCache.lock(long)'
+ */
+ public void testLockLong() {
+ assertTrue(subject.lock(100));
+ try {
+ subject.put("one", "two");
+ fail("Should have thrown an exception");
+ } catch (Throwable t) {
+ // intentionally blank
+ }
+ }
+
+ /*
+ * Test method for 'org.apache.geronimo.cache.GCache.unlock()'
+ */
+ public void testUnlock() {
+ assertTrue(subject.lock());
+ subject.unlock();
+ subject.put("one", "two");
+ }
+
+ /*
+ * Test method for 'org.apache.geronimo.cache.GCache.lock(Object)'
+ */
+ public void testLockObject() {
+ assertTrue(subject.lock("one"));
+ try {
+ subject.put("one", "two");
+ fail("Should have thrown an exception");
+ } catch (Throwable t) {
+ // intentionally blank
+ }
+ subject.put("two", "two");
+ }
+
+ /*
+ * Test method for 'org.apache.geronimo.cache.GCache.lock(Object, long)'
+ */
+ public void testLockObjectLong() {
+ assertFalse(subject.lock("one", 100));
+ subject.put("one", "two");
+ assertTrue(subject.lock("one", 100));
+ try {
+ subject.put("one", "two");
+ fail("Should have thrown an exception");
+ } catch (Throwable t) {
+ // intentionally blank
+ }
+ subject.put("two", "two");
+ }
+
+ /*
+ * Test method for 'org.apache.geronimo.cache.GCache.unlock(Object)'
+ */
+ public void testUnlockObject() {
+ assertTrue(subject.lock("one"));
+ subject.unlock("one");
+ subject.put("one", "two");
+ }
+
+ /*
+ * Test method for
+ * 'org.apache.geronimo.cache.GCache.setConfiguration(CacheConfig)'
+ */
+ public void testSetConfiguration() {
+ }
+
+ /*
+ * Test method for
+ * 'org.apache.geronimo.cache.GCache.addListener(CacheListener)'
+ */
+ public void testAddListenerGCacheListener() {
+ MockCacheListener listener = new MockCacheListener();
+ subject.addListener(listener);
+ subject.put("one", "two");
+ assertEquals(1, listener.getEntryAddedCount());
+ }
+
+ public void testListener() {
+ MockCacheListener listener = new MockCacheListener();
+ subject.addListener(listener);
+ subject.put("one", "two");
+ assertEquals(1, listener.getEntryAddedCount());
+ assertEquals(0, listener.getEntryRemovedCount());
+ assertEquals(0, listener.getEntryUpdateCount());
+ subject.put("one", "three");
+ assertEquals(1, listener.getEntryAddedCount());
+ assertEquals(0, listener.getEntryRemovedCount());
+ assertEquals(1, listener.getEntryUpdateCount());
+ subject.remove("one");
+ assertEquals(1, listener.getEntryAddedCount());
+ assertEquals(1, listener.getEntryRemovedCount());
+ assertEquals(1, listener.getEntryUpdateCount());
+ }
+
+ public void testKeyListener() {
+ MockCacheListener listener = new MockCacheListener();
+ subject.addListener(listener, "one");
+ subject.put("one", "two");
+ assertEquals(1, listener.getEntryAddedCount());
+ assertEquals(0, listener.getEntryRemovedCount());
+ assertEquals(0, listener.getEntryUpdateCount());
+ subject.put("one", "three");
+ assertEquals(1, listener.getEntryAddedCount());
+ assertEquals(0, listener.getEntryRemovedCount());
+ assertEquals(1, listener.getEntryUpdateCount());
+ subject.remove("one");
+ assertEquals(1, listener.getEntryAddedCount());
+ assertEquals(1, listener.getEntryRemovedCount());
+ assertEquals(1, listener.getEntryUpdateCount());
+ }
+
+ /*
+ * Test method for
+ * 'org.apache.geronimo.cache.GCache.addListener(CacheListener, Object)'
+ */
+ public void testAddListenerGCacheListenerObject() {
+ MockCacheListener listnerOne = new MockCacheListener();
+ MockCacheListener listnerTwo = new MockCacheListener();
+ subject.addListener(listnerOne, "one");
+ subject.addListener(listnerTwo, "two");
+ subject.put("one", "two");
+ assertEquals(1, listnerOne.getEntryAddedCount());
+ assertEquals(0, listnerTwo.getEntryAddedCount());
+ subject.put("two", "two");
+ assertEquals(1, listnerOne.getEntryAddedCount());
+ assertEquals(1, listnerTwo.getEntryAddedCount());
+ }
+
+ /*
+ * Test method for
+ * 'org.apache.geronimo.cache.GCache.removeListener(CacheListener)'
+ */
+ public void testRemoveListenerGCacheListener() {
+ MockCacheListener listener = new MockCacheListener();
+ subject.addListener(listener);
+ subject.put("one", "two");
+ assertEquals(1, listener.getEntryAddedCount());
+ subject.removeListener(listener);
+ subject.put("foo", "bar");
+ assertEquals(1, listener.getEntryAddedCount());
+ }
+
+ /*
+ * Test method for
+ * 'org.apache.geronimo.cache.GCache.removeListener(CacheListener, Object)'
+ */
+ public void testRemoveListenerGCacheListenerObject() {
+ MockCacheListener listnerOne = new MockCacheListener();
+ MockCacheListener listnerTwo = new MockCacheListener();
+ subject.addListener(listnerOne, "one");
+ subject.addListener(listnerTwo, "two");
+ subject.put("one", "two");
+ assertEquals(1, listnerOne.getEntryAddedCount());
+ assertEquals(0, listnerTwo.getEntryAddedCount());
+ subject.put("two", "two");
+ assertEquals(1, listnerOne.getEntryAddedCount());
+ assertEquals(1, listnerTwo.getEntryAddedCount());
+ subject.removeListener(listnerOne, "one");
+ subject.remove("one");
+ subject.put("one", "two");
+ assertEquals(1, listnerOne.getEntryAddedCount());
+ }
+
+ /*
+ * Test method for 'java.util.Map.size()'
+ */
+ public void testSize() {
+ subject.put("one", "two");
+ subject.put("two", "three");
+ assertEquals(2, subject.size());
+ }
+
+ /*
+ * Test method for 'java.util.Map.isEmpty()'
+ */
+ public void testIsEmpty() {
+ assertTrue(subject.isEmpty());
+ subject.put("one", "two");
+ assertFalse(subject.isEmpty());
+ }
+
+ /*
+ * Test method for 'java.util.Map.containsKey(Object)'
+ */
+ public void testContainsKey() {
+ subject.put("one", "two");
+ assertTrue(subject.containsKey("one"));
+ assertFalse(subject.containsKey("two"));
+ }
+
+ /*
+ * Test method for 'java.util.Map.containsValue(Object)'
+ */
+ public void testContainsValue() {
+ subject.put("one", "two");
+ assertTrue(subject.containsValue("two"));
+ assertFalse(subject.containsValue("one"));
+ }
+
+ /*
+ * Test method for 'java.util.Map.get(Object)'
+ */
+ public void testGet() {
+ subject.put("one", "two");
+ assertEquals("two", subject.get("one"));
+ assertNull(subject.get("foo"));
+ }
+
+ /*
+ * Test method for 'java.util.Map.remove(Object)'
+ */
+ public void testRemove() {
+ subject.put("one", "two");
+ assertEquals("two", subject.get("one"));
+ subject.remove("one");
+ assertNull(subject.get("one"));
+ }
+
+ /*
+ * Test method for 'java.util.Map.putAll(Map)'
+ */
+ public void testPutAll() {
+ MockCacheListener listener = new MockCacheListener();
+ subject.addListener(listener);
+ Map gak = new HashMap();
+ gak.put("one", "two");
+ gak.put("two", "three");
+ subject.putAll(gak);
+ assertEquals(2, listener.getEntryAddedCount());
+ subject.lock("two");
+ gak = new HashMap();
+ gak.put("two", "four");
+ gak.put("aaa", "fibe");
+ try {
+ subject.putAll(gak);
+ fail("Should have thrown");
+ } catch (Throwable t) {
+ // intentionally blank
+ }
+ assertNull(subject.get("aaa"));
+ }
+
+ /*
+ * Test method for 'java.util.Map.clear()'
+ */
+ public void testClear() {
+ Map gak = new HashMap();
+ gak.put("one", "two");
+ gak.put("two", "three");
+ subject.putAll(gak);
+ assertEquals(2, subject.size());
+ subject.clear();
+ assertEquals(0, subject.size());
+ }
+
+ /*
+ * Test method for 'java.util.Map.keySet()'
+ */
+ public void testKeySet() {
+ Map gak = new HashMap();
+ gak.put("one", "two");
+ gak.put("two", "three");
+ subject.putAll(gak);
+ assertEquals(gak.keySet(), subject.keySet());
+ }
+
+ /*
+ * Test method for 'java.util.Map.values()'
+ */
+ public void testValues() {
+ Map gak = new HashMap();
+ gak.put("one", "two");
+ gak.put("two", "three");
+ subject.putAll(gak);
+ assertEquals(new HashSet(gak.values()), new HashSet(subject.values()));
+ }
+
+ /*
+ * Test method for 'java.util.Map.entrySet()'
+ */
+ public void testEntrySet() {
+ Map gak = new HashMap();
+ gak.put("one", "two");
+ gak.put("two", "three");
+ subject.putAll(gak);
+ assertEquals(gak.entrySet(), subject.entrySet());
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/MockCacheListener.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/MockCacheListener.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/MockCacheListener.java (added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/MockCacheListener.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;
+
+/**
+ *
+ * $Rev$ $Date$
+ */
+public class MockCacheListener implements CacheListener {
+ private int entryAddedCount = 0;
+
+ private int entryRemovedCount = 0;
+
+ private int entryUpdateCount = 0;
+
+ public void entryAdded(CacheEvent event) {
+ entryAddedCount++;
+ }
+
+ public void entryRemoved(CacheEvent event) {
+ entryRemovedCount++;
+ }
+
+ public void entryUpdated(CacheEvent event) {
+ entryUpdateCount++;
+ }
+
+ public int getEntryAddedCount() {
+ return entryAddedCount;
+ }
+
+ public int getEntryRemovedCount() {
+ return entryRemovedCount;
+ }
+
+ public int getEntryUpdateCount() {
+ return entryUpdateCount;
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/MockReplicatedCache.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/MockReplicatedCache.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/MockReplicatedCache.java (added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/MockReplicatedCache.java Tue May 23 08:13:52 2006
@@ -0,0 +1,145 @@
+/*
+ * 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 java.rmi.server.UID;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.cache.comm.CacheChannel;
+import org.apache.geronimo.cache.config.CacheConfig;
+
+/**
+ *
+ * $Rev$ $Date$
+ */
+public class MockReplicatedCache implements ReplicatedCache {
+ private CacheChannel channel = null;
+
+ public InetAddress getCacheAddress() {
+ return null;
+ }
+
+ public CacheChannel getChannel() {
+ return channel;
+ }
+
+ public void setChannel(CacheChannel channel) {
+ this.channel = channel;
+ }
+
+ public void addListener(CacheListener listener) {
+ }
+
+ public void addListener(CacheListener listener, Object key) {
+ }
+
+ public Map getAll(Set keys) {
+ return new HashMap();
+ }
+
+ public UID getId() {
+ return null;
+ }
+
+ public String getName() {
+ return "MockReplicatedCache";
+ }
+
+ public boolean lock() {
+ return false;
+ }
+
+ public boolean lock(long timeoutMilliSeconds) {
+ return false;
+ }
+
+ public boolean lock(Object key) {
+ return false;
+ }
+
+ public boolean lock(Object key, long timeoutMilliSeconds) {
+ return false;
+ }
+
+ public void removeListener(CacheListener listener) {
+ }
+
+ public void removeListener(CacheListener listener, Object key) {
+ }
+
+ public void setConfiguration(CacheConfig config) {
+ }
+
+ public boolean unlock() {
+ return false;
+ }
+
+ public boolean unlock(Object key) {
+ return false;
+ }
+
+ public void clear() {
+ }
+
+ public boolean containsKey(Object key) {
+ return false;
+ }
+
+ public boolean containsValue(Object value) {
+ return false;
+ }
+
+ public Set entrySet() {
+ return new HashSet();
+ }
+
+ public Object get(Object key) {
+ return null;
+ }
+
+ public boolean isEmpty() {
+ return true;
+ }
+
+ public Set keySet() {
+ return new HashSet();
+ }
+
+ public Object put(Object arg0, Object arg1) {
+ return null;
+ }
+
+ public void putAll(Map arg0) {
+ }
+
+ public Object remove(Object key) {
+ return null;
+ }
+
+ public int size() {
+ return 0;
+ }
+
+ public Collection values() {
+ return null;
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/aiotest/Peer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/aiotest/Peer.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/aiotest/Peer.java (added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/aiotest/Peer.java Tue May 23 08:13:52 2006
@@ -0,0 +1,106 @@
+/*
+ * 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.aiotest;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+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.activeio.packet.async.AsyncChannelServer;
+
+/**
+ *
+ * $Rev$ $Date$
+ */
+public class Peer implements AsyncChannelListener, AcceptListener {
+ // either a peer or the server
+ private AsyncChannelServer server = null;
+
+ private AsyncChannel channel = null;
+
+ public static void main(String args[]) {
+ Peer peer = new Peer();
+ peer.run();
+ }
+
+ public Peer() {
+ super();
+ ChannelFactory activeIOChannelFactory = new ChannelFactory();
+ try {
+ server = activeIOChannelFactory.bindAsyncChannel(new URI(
+ "nio://localhost:10101"));
+ System.out.println("acting as server");
+ server.setAcceptListener(this);
+ server.start();
+ } catch (IOException e) {
+ server = null;
+ } catch (URISyntaxException e) {
+ server = null;
+ }
+ if (server == null) {
+ try {
+ channel = activeIOChannelFactory.openAsyncChannel(new URI(
+ "nio://localhost:10101"));
+ System.out.println("acting as client");
+ channel.setAsyncChannelListener(this);
+ channel.start();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ for (int i = 0; i < 30; i++) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void run() {
+ }
+
+ public void onPacket(Packet arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onPacketError(IOException arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onAccept(Channel arg0) {
+ System.out.println("got a connected channel: " + arg0);
+ }
+
+ public void onAcceptError(IOException arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/CacheCommunicationExceptionTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/CacheCommunicationExceptionTest.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/CacheCommunicationExceptionTest.java (added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/CacheCommunicationExceptionTest.java Tue May 23 08:13:52 2006
@@ -0,0 +1,63 @@
+/*
+ * 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 junit.framework.TestCase;
+
+/**
+ *
+ * $Rev$ $Date$
+ */
+public class CacheCommunicationExceptionTest extends TestCase {
+
+ public CacheCommunicationExceptionTest(String arg0) {
+ super(arg0);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testCacheConfigurationException() {
+ CacheCommunicationException e = new CacheCommunicationException();
+ assertNull(e.getCause());
+ }
+
+ public void testCacheConfigurationExceptionString() {
+ CacheCommunicationException e = new CacheCommunicationException(
+ "message");
+ assertEquals("message", e.getMessage());
+ }
+
+ public void testCacheConfigurationExceptionStringThrowable() {
+ Throwable t = new Throwable("wowzer");
+ CacheCommunicationException e = new CacheCommunicationException(t);
+ assertEquals(t, e.getCause());
+ }
+
+ public void testCacheConfigurationExceptionThrowable() {
+ Throwable t = new Throwable("wowzer");
+ CacheCommunicationException e = new CacheCommunicationException(
+ "wonder", t);
+ assertEquals("wonder", e.getMessage());
+ assertEquals(t, e.getCause());
+ }
+
+}
Added: geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/JoinedEventTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/JoinedEventTest.java?rev=408925&view=auto
==============================================================================
--- geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/JoinedEventTest.java (added)
+++ geronimo/sandbox/geronimo-cache/src/test/java/org/apache/geronimo/cache/comm/JoinedEventTest.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;
+
+import junit.framework.TestCase;
+
+import org.apache.geronimo.cache.MockReplicatedCache;
+import org.apache.geronimo.cache.ReplicatedCache;
+
+/**
+ *
+ * $Rev$ $Date$
+ */
+public class JoinedEventTest extends TestCase {
+
+ public JoinedEventTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testInvoke() {
+ ReplicatedCache cache = new MockReplicatedCache();
+ MockCacheChannel channel = new MockCacheChannel();
+ channel.setCache(cache);
+ cache.setChannel(channel);
+ JoinedEvent event = new JoinedEvent();
+ event.invoke(cache);
+ assertEquals(1, channel.getSendCount());
+ }
+ /*
+ * public void testGetCacheName() { fail("Not yet implemented"); }
+ *
+ * public void testSetCacheName() { fail("Not yet implemented"); }
+ *
+ * public void testGetCacheId() { fail("Not yet implemented"); }
+ *
+ * public void testSetCacheId() { fail("Not yet implemented"); }
+ *
+ * public void testGetKey() { fail("Not yet implemented"); }
+ *
+ * public void testSetKey() { fail("Not yet implemented"); }
+ *
+ * public void testGetOrigin() { fail("Not yet implemented"); }
+ *
+ * public void testSetOrigin() { fail("Not yet implemented"); }
+ */
+}