Author: tv
Date: Sun Nov 11 14:38:08 2012
New Revision: 1408014
URL: http://svn.apache.org/viewvc?rev=1408014&view=rev
Log:
JCS94: Add getGroupNames() to all caches. LateralTCPService should implement getGroupKeys.
Modified:
commons/proper/jcs/trunk/src/changes/changes.xml
commons/proper/jcs/trunk/src/java/org/apache/jcs/access/GroupCacheAccess.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/AbstractRemoteAuxiliaryCache.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClient.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/AbstractRemoteCacheService.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestUtil.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/ZombieCacheServiceNonLocal.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICacheServiceNonLocal.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java
commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java
commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java
commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/AbstractDiskCacheUnitTest.java
commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java
commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheService.java
commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/MockCacheServiceNonLocal.java
commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java
commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/memory/MockMemoryCache.java
Modified: commons/proper/jcs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/changes/changes.xml?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/changes/changes.xml (original)
+++ commons/proper/jcs/trunk/src/changes/changes.xml Sun Nov 11 14:38:08 2012
@@ -20,6 +20,12 @@
</properties>
<body>
<release version="2.0" date="unreleased" description="JDK 1.5 based major release">
+ <action dev="tv" type="add" issue="JCS-94" due-to="Andrew Leamon">
+ Add getGroupNames() to all caches.
+ </action>
+ <action dev="tv" type="add" issue="JCS-94" due-to="Andrew Leamon">
+ LateralTCPService should implement getGroupKeys.
+ </action>
<action dev="tv" type="update" issue="JCS-75" due-to="Chiat Lam">
CompositeCache: Add method to get auxiliary caches, changed
visibility of isExpired() to protected.
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/access/GroupCacheAccess.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/access/GroupCacheAccess.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/access/GroupCacheAccess.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/access/GroupCacheAccess.java Sun Nov 11 14:38:08 2012
@@ -211,6 +211,16 @@ public class GroupCacheAccess<K extends
}
/**
+ * Gets the set of group names in the cache
+ * <p>
+ * @return A Set of group names.
+ */
+ public Set<String> getGroupNames()
+ {
+ return this.cacheControl.getGroupNames();
+ }
+
+ /**
* Invalidates a group: remove all the group members
* <p>
* @param group
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java Sun Nov 11 14:38:08 2012
@@ -47,6 +47,14 @@ public interface AuxiliaryCache<K extend
throws IOException;
/**
+ * Gets the set of group names currently in the cache
+ * @return a set of group names
+ * @throws IOException
+ */
+ Set<String> getGroupNames()
+ throws IOException;
+
+ /**
* @return the historical and statistical data for a region's auxiliary cache.
*/
IStats getStatistics();
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java Sun Nov 11 14:38:08 2012
@@ -362,12 +362,18 @@ public abstract class AbstractDiskCache<
/**
* The keys in a group.
* <p>
- * (non-Javadoc)
* @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String)
*/
public abstract Set<K> getGroupKeys( String groupName );
/**
+ * The group names in the cache.
+ * <p>
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupNames()
+ */
+ public abstract Set<String> getGroupNames();
+
+ /**
* Removes are not queued. A call to remove is immediate.
* <p>
* @param key
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java Sun Nov 11 14:38:08 2012
@@ -205,7 +205,6 @@ public class BlockDiskCache<K extends Se
/**
* This requires a full iteration through the keys.
* <p>
- * (non-Javadoc)
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#getGroupKeys(java.lang.String)
*/
@Override
@@ -237,6 +236,38 @@ public class BlockDiskCache<K extends Se
}
/**
+ * This requires a full iteration through the keys.
+ * <p>
+ * @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#getGroupNames()
+ */
+ @Override
+ public Set<String> getGroupNames()
+ {
+ HashSet<String> names = new HashSet<String>();
+
+ storageLock.readLock().lock();
+
+ try
+ {
+ for ( Serializable key : this.keyStore.keySet())
+ {
+ if ( key instanceof GroupAttrName )
+ {
+ @SuppressWarnings("unchecked") // Type checked with instanceof
+ GroupId groupID = ((GroupAttrName<K>) key ).groupId;
+ names.add( groupID.groupName );
+ }
+ }
+ }
+ finally
+ {
+ storageLock.readLock().unlock();
+ }
+
+ return names;
+ }
+
+ /**
* Gets matching items from the cache.
* <p>
* @param pattern
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java Sun Nov 11 14:38:08 2012
@@ -135,8 +135,10 @@ public class FileDiskCache<K extends Ser
}
/**
- * @param groupName
- * @return Set
+ * Gets the set of keys of objects currently in the group.
+ * <p>
+ * @param group
+ * @return a Set of group keys.
*/
@Override
public Set<K> getGroupKeys(String groupName)
@@ -145,6 +147,17 @@ public class FileDiskCache<K extends Ser
}
/**
+ * Gets the set of group names in the cache
+ * <p>
+ * @return a Set of group names.
+ */
+ @Override
+ public Set<String> getGroupNames()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
* @return dir.list().length
*/
@Override
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java Sun Nov 11 14:38:08 2012
@@ -770,6 +770,37 @@ public class IndexedDiskCache<K extends
}
/**
+ * Gets the group names from the disk.
+ * <p>
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String)
+ */
+ @Override
+ public Set<String> getGroupNames()
+ {
+ HashSet<String> names = new HashSet<String>();
+ try
+ {
+ storageLock.readLock().lock();
+
+ for (K k : keyHash.keySet())
+ {
+ if ( k instanceof GroupAttrName )
+ {
+ @SuppressWarnings("unchecked") // Type checked with instanceof
+ GroupAttrName<K> groupAttrName = (GroupAttrName<K>) k;
+ names.add( groupAttrName.groupId.groupName );
+ }
+ }
+ }
+ finally
+ {
+ storageLock.readLock().unlock();
+ }
+
+ return names;
+ }
+
+ /**
* Returns true if the removal was successful; or false if there is nothing to remove. Current
* implementation always result in a disk orphan.
* <p>
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java Sun Nov 11 14:38:08 2012
@@ -1047,6 +1047,16 @@ public class JDBCDiskCache<K extends Ser
throw new UnsupportedOperationException( "Groups not implemented." );
// return null;
}
+
+ /**
+ * @return Set
+ */
+ @Override
+ public Set<String> getGroupNames()
+ {
+ throw new UnsupportedOperationException( "Groups not implemented." );
+ // return null;
+ }
/**
* @param elementSerializer The elementSerializer to set.
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java Sun Nov 11 14:38:08 2012
@@ -206,8 +206,10 @@ public class LateralCache<K extends Seri
}
/**
- * @param groupName
- * @return A set of group keys.
+ * Gets the set of keys of objects currently in the group.
+ * <p>
+ * @param group
+ * @return a Set of group keys.
* @throws IOException
*/
public Set<K> getGroupKeys( String groupName )
@@ -226,6 +228,27 @@ public class LateralCache<K extends Seri
}
/**
+ * Gets the set of group names in the cache
+ * <p>
+ * @return a Set of group names.
+ * @throws IOException
+ */
+ public Set<String> getGroupNames()
+ throws IOException
+ {
+ try
+ {
+ return lateralCacheService.getGroupNames( cacheName );
+ }
+ catch ( Exception ex )
+ {
+ handleException( ex, "Failed to get group names from " + lateralCacheAttribures.getCacheName() + "@"
+ + lateralCacheAttribures );
+ }
+ return Collections.emptySet();
+ }
+
+ /**
* Synchronously remove from the remote cache; if failed, replace the remote handle with a
* zombie.
* <p>
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java Sun Nov 11 14:38:08 2012
@@ -240,6 +240,23 @@ public class LateralCacheNoWait<K extend
}
return Collections.emptySet();
}
+
+ /**
+ * @return Set
+ */
+ public Set<String> getGroupNames()
+ {
+ try
+ {
+ return cache.getGroupNames( );
+ }
+ catch ( IOException ex )
+ {
+ log.error( ex );
+ eventQueue.destroy();
+ }
+ return Collections.emptySet();
+ }
/**
* Adds a remove request to the lateral cache.
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java Sun Nov 11 14:38:08 2012
@@ -285,8 +285,10 @@ public class LateralCacheNoWaitFacade<K
}
/**
+ * Gets the set of keys of objects currently in the group.
+ * <p>
* @param group
- * @return Set
+ * @return a Set of group keys.
*/
public Set<K> getGroupKeys( String group )
{
@@ -298,7 +300,41 @@ public class LateralCacheNoWaitFacade<K
{
try
{
- allKeys.addAll( aux.getGroupKeys( group ) );
+ Set<K> groupKeys = aux.getGroupKeys( group );
+ if(groupKeys != null)
+ {
+ allKeys.addAll( groupKeys );
+ }
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+ }
+ return allKeys;
+ }
+
+ /**
+ * Gets the set of group names in the cache
+ * <p>
+ * @return a Set of group names.
+ */
+ public Set<String> getGroupNames()
+ {
+ HashSet<String> allKeys = new HashSet<String>();
+ for ( int i = 0; i < noWaits.length; i++ )
+ {
+ AuxiliaryCache<K, V> aux = noWaits[i];
+ if ( aux != null )
+ {
+ try
+ {
+ Set<String> groupNames = aux.getGroupNames();
+ if(groupNames != null)
+ {
+ allKeys.addAll( groupNames );
+ }
}
catch ( IOException e )
{
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java Sun Nov 11 14:38:08 2012
@@ -52,6 +52,12 @@ public class LateralElementDescriptor<K
/** Command to return an object. */
public final static int GET_MATCHING = 6;
+ /** Command to get all group keys */
+ public final static int GET_GROUP_KEYS = 7;
+
+ /** Command to get all group keys */
+ public final static int GET_GROUP_NAMES = 8;
+
/** The Cache Element that we are distributing. */
public ICacheElement<K, V> ce;
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java Sun Nov 11 14:38:08 2012
@@ -28,6 +28,7 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
@@ -303,8 +304,8 @@ public class LateralTCPListener<K extend
/**
* Gets the cache that was injected by the lateral factory. Calls get on the cache.
* <p>
- * @param cacheName
- * @param pattern
+ * @param cacheName the name of the cache
+ * @param pattern the matching pattern
* @return Map
* @throws IOException
*/
@@ -330,6 +331,31 @@ public class LateralTCPListener<K extend
}
/**
+ * Gets the cache that was injected by the lateral factory. Calls getGroupKeys on the cache.
+ * <p>
+ * @param cacheName the name of the cache
+ * @param group the group name
+ * @return a set of keys
+ * @throws IOException
+ */
+ public Set<K> handleGetGroupKeys( String cacheName, String group ) throws IOException
+ {
+ return getCache( cacheName ).getGroupKeys(group, true);
+ }
+
+ /**
+ * Gets the cache that was injected by the lateral factory. Calls getGroupNames on the cache.
+ * <p>
+ * @param cacheName the name of the cache
+ * @return a set of group names
+ * @throws IOException
+ */
+ public Set<String> handleGetGroupNames( String cacheName ) throws IOException
+ {
+ return getCache( cacheName ).getGroupNames(true);
+ }
+
+ /**
* Right now this does nothing.
* <p>
* @see org.apache.jcs.engine.behavior.ICacheListener#handleDispose(java.lang.String)
@@ -632,7 +658,6 @@ public class LateralTCPListener<K extend
Serializable obj = handleGet( cacheName, key );
ObjectOutputStream oos = new ObjectOutputStream( socket.getOutputStream() );
-
oos.writeObject( obj );
oos.flush();
}
@@ -641,7 +666,23 @@ public class LateralTCPListener<K extend
Map<K, ICacheElement<K, V>> obj = handleGetMatching( cacheName, (String) key );
ObjectOutputStream oos = new ObjectOutputStream( socket.getOutputStream() );
+ oos.writeObject( obj );
+ oos.flush();
+ }
+ else if ( led.command == LateralElementDescriptor.GET_GROUP_KEYS )
+ {
+ String groupName = (String) key;
+ Set<K> obj = handleGetGroupKeys(cacheName, groupName);
+ ObjectOutputStream oos = new ObjectOutputStream( socket.getOutputStream() );
+ oos.writeObject( obj );
+ oos.flush();
+ }
+ else if ( led.command == LateralElementDescriptor.GET_GROUP_NAMES )
+ {
+ Set<String> obj = handleGetGroupNames(cacheName);
+
+ ObjectOutputStream oos = new ObjectOutputStream( socket.getOutputStream() );
oos.writeObject( obj );
oos.flush();
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java Sun Nov 11 14:38:08 2012
@@ -362,16 +362,52 @@ public class LateralTCPService<K extends
}
/**
- * Gets the set of keys of objects currently in the group throws UnsupportedOperationException
+ * Gets the set of keys of objects currently in the group
* <p>
* @param cacheName
* @param group
* @return Set
*/
+ @SuppressWarnings("unchecked") // Need cast from Object
public Set<K> getGroupKeys( String cacheName, String group )
+ throws IOException
+ {
+ CacheElement<String, String> ce = new CacheElement<String, String>(cacheName, group, null);
+ LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String, String>(ce);
+ // led.requesterId = requesterId; // later
+ led.command = LateralElementDescriptor.GET_GROUP_KEYS;
+ Object response = sender.sendAndReceive(led);
+ if (response != null)
+ {
+ return (Set<K>) response;
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets the set of groups currently in the cache throws
+ * UnsupportedOperationException
+ * <p>
+ *
+ * @param cacheName
+ * @return Set
+ */
+ @SuppressWarnings("unchecked") // Need cast from Object
+ public Set<String> getGroupNames(String cacheName)
+ throws IOException
{
- throw new UnsupportedOperationException( "Groups not implemented." );
- // return null;
+ CacheElement<String, String> ce = new CacheElement<String, String>(cacheName, null, null);
+ LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String, String>(ce);
+ // led.requesterId = requesterId; // later
+ led.command = LateralElementDescriptor.GET_GROUP_NAMES;
+ Object response = sender.sendAndReceive(led);
+ if (response != null)
+ {
+ return (Set<String>) response;
+ }
+
+ return null;
}
/**
@@ -513,4 +549,6 @@ public class LateralTCPService<K extends
{
return tcpLateralCacheAttributes;
}
+
+
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/AbstractRemoteAuxiliaryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/AbstractRemoteAuxiliaryCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/AbstractRemoteAuxiliaryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/AbstractRemoteAuxiliaryCache.java Sun Nov 11 14:38:08 2012
@@ -457,6 +457,19 @@ public abstract class AbstractRemoteAuxi
{
return getRemoteCacheService().getGroupKeys( cacheName, groupName );
}
+
+ /**
+ * Returns all the group names for a cache.
+ * <p>
+ * @return Set
+ * @throws java.rmi.RemoteException
+ * @throws IOException
+ */
+ public Set<String> getGroupNames()
+ throws java.rmi.RemoteException, IOException
+ {
+ return getRemoteCacheService().getGroupNames( cacheName );
+ }
/**
* Allows other member of this package to access the listener. This is mainly needed for
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java Sun Nov 11 14:38:08 2012
@@ -237,13 +237,43 @@ public abstract class AbstractRemoteCach
AuxiliaryCache<K, V> aux = noWaits[i];
if ( aux != null )
{
- allKeys.addAll( aux.getGroupKeys( group ) );
+ Set<K> groupKeys = aux.getGroupKeys( group );
+ if(groupKeys != null)
+ {
+ allKeys.addAll( groupKeys );
+ }
}
}
return allKeys;
}
/**
+ * Gets the group names in the cache
+ * <p>
+ *
+ * @return the set of group names
+ * @throws IOException
+ */
+ public Set<String> getGroupNames() throws IOException
+ {
+ HashSet<String> names = new HashSet<String>();
+ for (int i = 0; i < noWaits.length; i++)
+ {
+ AuxiliaryCache<K, V> aux = noWaits[i];
+ if (aux != null)
+ {
+ Set<String> groupNames = aux.getGroupNames();
+ if (groupNames != null)
+ {
+ names.addAll(groupNames);
+ }
+ }
+ }
+
+ return names;
+ }
+
+ /**
* Adds a remove request to the remote cache.
* <p>
* @param key
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java Sun Nov 11 14:38:08 2012
@@ -285,6 +285,16 @@ public class RemoteCacheNoWait<K extends
{
return remoteCacheClient.getGroupKeys( groupName );
}
+
+ /**
+ * @return the group names
+ * @throws IOException
+ */
+ public Set<String> getGroupNames()
+ throws IOException
+ {
+ return remoteCacheClient.getGroupNames( );
+ }
/**
* Adds a remove request to the remote cache.
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClient.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClient.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClient.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClient.java Sun Nov 11 14:38:08 2012
@@ -372,9 +372,11 @@ public class RemoteHttpCacheClient<K ext
}
/**
- * @param cacheName
- * @param groupName
- * @return A Set of keys
+ * Gets the set of keys of objects currently in the group.
+ * <p>
+ * @param cacheName the name of the cache
+ * @param groupName the name of the group
+ * @return a Set of group keys.
* @throws IOException
*/
public Set<K> getGroupKeys( String cacheName, String groupName )
@@ -402,6 +404,36 @@ public class RemoteHttpCacheClient<K ext
}
/**
+ * Gets the set of group names in the cache
+ * <p>
+ * @return a Set of group names.
+ * @throws IOException
+ */
+ public Set<String> getGroupNames( String cacheName )
+ throws IOException
+ {
+ if ( !isInitialized() )
+ {
+ String message = "The Remote Http Client is not initialized. Cannot process request.";
+ log.warn( message );
+ throw new IOException( message );
+ }
+
+ RemoteCacheRequest<String, String> remoteHttpCacheRequest =
+ RemoteCacheRequestFactory.createGetGroupNamesRequest( cacheName, 0 );
+
+ RemoteCacheResponse<K, V> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
+
+ if ( remoteHttpCacheResponse != null && remoteHttpCacheResponse.getPayload() != null )
+ {
+ // FIXME: Unchecked cast
+ return (Set<String>)remoteHttpCacheResponse.getPayload().get( cacheName );
+ }
+
+ return Collections.emptySet();
+ }
+
+ /**
* Make and alive request.
* <p>
* @return true if we make a successful alive request.
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java Sun Nov 11 14:38:08 2012
@@ -171,6 +171,9 @@ public class RemoteHttpCacheDispatcher
case RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_KEYS:
keyValue = remoteCacheRequest.getKey() + "";
break;
+ case RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_NAMES:
+ keyValue = remoteCacheRequest.getKey() + "";
+ break;
case RemoteCacheRequest.REQUEST_TYPE_UPDATE:
keyValue = remoteCacheRequest.getCacheElement().getKey() + "";
break;
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/AbstractRemoteCacheService.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/AbstractRemoteCacheService.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/AbstractRemoteCacheService.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/AbstractRemoteCacheService.java Sun Nov 11 14:38:08 2012
@@ -328,6 +328,31 @@ public abstract class AbstractRemoteCach
}
/**
+ * Gets the set of group names currently in the cache.
+ * <p>
+ * @param cacheName
+ * @param group
+ * @return A Set of group names
+ */
+ public Set<String> getGroupNames( String cacheName )
+ {
+ return processGetGroupNames( cacheName );
+ }
+
+ /**
+ * Gets the set of keys of objects currently in the group.
+ * <p>
+ * @param cacheName
+ * @param groupName
+ * @return Set
+ */
+ public Set<String> processGetGroupNames( String cacheName )
+ {
+ CompositeCache<?, ?> cache = getCacheManager().getCache( cacheName );
+ return cache.getGroupNames();
+ }
+
+ /**
* Removes the given key from the specified remote cache. Defaults the listener id to 0.
* <p>
* @param cacheName
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java Sun Nov 11 14:38:08 2012
@@ -140,6 +140,15 @@ public class RemoteCacheServiceAdaptor<K
// FIXME: Re-enable
//response.getPayload().put( request.getKey(), groupKeys );
break;
+ case RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_NAMES:
+ Set<String> groupNames = getRemoteCacheService().getGroupNames( request.getCacheName() );
+ if ( groupNames == null )
+ {
+ groupNames = Collections.emptySet();
+ }
+ // FIXME: Re-enable
+ //response.getPayload().put( request.getKey(), groupNames );
+ break;
default:
String message = "Unknown event type. Cannot process " + request;
log.warn( message );
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java Sun Nov 11 14:38:08 2012
@@ -867,6 +867,44 @@ public class RemoteCacheServer<K extends
}
/**
+ * Gets the set of group names currently in the cache.
+ * <p>
+ * @param cacheName the name of the region
+ * @return A Set of group names
+ */
+ public Set<String> getGroupNames(String cacheName)
+ {
+ return processGetGroupNames(cacheName);
+ }
+
+ /**
+ * Gets the set of group names currently in the cache.
+ * <p>
+ * @param cacheName the name of the region
+ * @return A Set of group names
+ */
+ protected Set<String> processGetGroupNames(String cacheName)
+ {
+ CacheListeners<K, V> cacheDesc = null;
+ try
+ {
+ cacheDesc = getCacheListeners(cacheName);
+ }
+ catch (Exception e)
+ {
+ log.error("Problem getting listeners.", e);
+ }
+
+ if (cacheDesc == null)
+ {
+ return Collections.emptySet();
+ }
+
+ CompositeCache<K, V> c = (CompositeCache<K, V>) cacheDesc.cache;
+ return c.getGroupNames();
+ }
+
+ /**
* Removes the given key from the specified remote cache. Defaults the listener id to 0.
* <p>
* @param cacheName
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java Sun Nov 11 14:38:08 2012
@@ -138,6 +138,29 @@ public class RemoteCacheRequestFactory
}
/**
+ * Creates a GetGroupNames Request.
+ * <p>
+ * @param cacheName
+ * @param requesterId
+ * @return RemoteHttpCacheRequest
+ */
+ public static RemoteCacheRequest<String, String> createGetGroupNamesRequest( String cacheName, int requesterId)
+ {
+ RemoteCacheRequest<String, String> request = new RemoteCacheRequest<String, String>();
+ request.setCacheName( cacheName );
+ request.setKey( cacheName );
+ request.setRequesterId( requesterId );
+ request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_NAMES );
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Created: " + request );
+ }
+
+ return request;
+ }
+
+ /**
* Creates a removeAll Request.
* <p>
* @param cacheName
@@ -231,4 +254,6 @@ public class RemoteCacheRequestFactory
return request;
}
+
+
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestUtil.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestUtil.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestUtil.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestUtil.java Sun Nov 11 14:38:08 2012
@@ -29,6 +29,8 @@ public class RemoteCacheRequestUtil
return "Update";
case RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_KEYS:
return "GetGroupKeys";
+ case RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_NAMES:
+ return "GetGroupNames";
case RemoteCacheRequest.REQUEST_TYPE_DISPOSE:
return "Dispose";
default:
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java Sun Nov 11 14:38:08 2012
@@ -38,12 +38,15 @@ public class RemoteCacheRequest<K extend
/** Remove All request type. */
public static final byte REQUEST_TYPE_REMOVE_ALL = 6;
- /** Remove All request type. */
+ /** Get group keys request type. */
public static final byte REQUEST_TYPE_GET_GROUP_KEYS = 7;
- /** Remove All request type. */
+ /** Dispose request type. */
public static final byte REQUEST_TYPE_DISPOSE = 8;
+ /** Get group keys request type. */
+ public static final byte REQUEST_TYPE_GET_GROUP_NAMES = 9;
+
/** The request type specifies the type of request: get, put, remove, . . */
private byte requestType = -1;
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/ZombieCacheServiceNonLocal.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/ZombieCacheServiceNonLocal.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/ZombieCacheServiceNonLocal.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/ZombieCacheServiceNonLocal.java Sun Nov 11 14:38:08 2012
@@ -188,6 +188,17 @@ public class ZombieCacheServiceNonLocal<
}
/**
+ * Does nothing.
+ * <p>
+ * @param cacheName - region name
+ * @return empty set
+ */
+ public Set<String> getGroupNames( String cacheName )
+ {
+ return Collections.emptySet();
+ }
+
+ /**
* Walk the queue, calling the service for each queue operation.
* <p>
* @param service
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICacheServiceNonLocal.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICacheServiceNonLocal.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICacheServiceNonLocal.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICacheServiceNonLocal.java Sun Nov 11 14:38:08 2012
@@ -107,13 +107,23 @@ public interface ICacheServiceNonLocal<K
throws IOException;
/**
- * Likely not implemented. This probably should be deprecated.
+ * Gets the set of keys of objects currently in the group.
* <p>
- * @param cacheName
- * @param groupName
- * @return A Set of keys
+ * @param cacheName the name of the cache
+ * @param groupName the name of the group
+ * @return a Set of group keys.
* @throws IOException
*/
Set<K> getGroupKeys( String cacheName, String groupName )
throws IOException;
+
+ /**
+ * Gets the set of group names in the cache
+ * <p>
+ * @param cacheName the name of the cache
+ * @return a Set of group names.
+ * @throws IOException
+ */
+ Set<String> getGroupNames( String cacheName )
+ throws IOException;
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java Sun Nov 11 14:38:08 2012
@@ -1106,11 +1106,22 @@ public class CompositeCache<K extends Se
/**
* Gets the set of keys of objects currently in the group.
* <p>
- * @param group
+ * @param group the name of the group
* @return A Set of keys, or null.
*/
public Set<K> getGroupKeys( String group )
{
+ return getGroupKeys(group, false);
+ }
+
+ /**
+ * Gets the set of keys of objects currently in the group.
+ * <p>
+ * @param group the name of the group
+ * @return A Set of keys, or null.
+ */
+ public Set<K> getGroupKeys( String group, boolean localOnly )
+ {
HashSet<K> allKeys = new HashSet<K>();
allKeys.addAll( memCache.getGroupKeys( group ) );
for ( int i = 0; i < auxCaches.length; i++ )
@@ -1118,13 +1129,61 @@ public class CompositeCache<K extends Se
AuxiliaryCache<K, V> aux = auxCaches[i];
if ( aux != null )
{
- try
+ if(!localOnly || aux.getCacheType() == CacheType.DISK_CACHE)
{
- allKeys.addAll( aux.getGroupKeys( group ) );
+ try
+ {
+ allKeys.addAll( aux.getGroupKeys( group ) );
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
}
- catch ( IOException e )
+ }
+ }
+ return allKeys;
+ }
+
+ /**
+ * Gets the set of group names in the cache
+ * <p>
+ * @return a Set of group names.
+ */
+ public Set<String> getGroupNames()
+ {
+ return getGroupNames( false );
+ }
+
+ /**
+ * Gets the set of group names in the cache
+ * <p>
+ * @param localOnly whether to get the group names only from local caches or not
+ * @return a Set of group names.
+ */
+ public Set<String> getGroupNames(boolean localOnly)
+ {
+ HashSet<String> allKeys = new HashSet<String>();
+ allKeys.addAll( memCache.getGroupNames() );
+ for ( int i = 0; i < auxCaches.length; i++ )
+ {
+ AuxiliaryCache<K, V> aux = auxCaches[i];
+ if ( aux != null )
+ {
+ if(!localOnly || aux.getCacheType() == CacheType.DISK_CACHE)
{
- // ignore
+ try
+ {
+ Set<String> groupNames = aux.getGroupNames();
+ if(groupNames != null)
+ {
+ allKeys.addAll( groupNames );
+ }
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
}
}
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java Sun Nov 11 14:38:08 2012
@@ -279,7 +279,10 @@ public abstract class AbstractMemoryCach
*/
public String getCacheName()
{
- return this.cacheAttributes.getCacheName();
+ String attributeCacheName = this.cacheAttributes.getCacheName();
+ if(attributeCacheName != null)
+ return attributeCacheName;
+ return cacheName;
}
/**
@@ -372,6 +375,29 @@ public abstract class AbstractMemoryCach
}
/**
+ * Gets the set of group names in the cache
+ * <p>
+ * @return a Set of group names.
+ */
+ public Set<String> getGroupNames()
+ {
+ HashSet<String> names = new HashSet<String>();
+ synchronized ( map )
+ {
+ for (Map.Entry<K, MemoryElementDescriptor<K, V>> entry : map.entrySet())
+ {
+ K k = entry.getKey();
+
+ if ( k instanceof GroupAttrName )
+ {
+ names.add(( (GroupAttrName<K>) k ).groupId.groupName );
+ }
+ }
+ }
+ return names;
+ }
+
+ /**
* Allows us to set the daemon status on the clockdaemon
*/
protected static class MyThreadFactory
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java Sun Nov 11 14:38:08 2012
@@ -59,7 +59,7 @@ public interface IMemoryCache<K extends
/**
* Returns the historical and statistical data for a region's memory cache.
* <p>
- * @return Statistics and Infor for the Memory Cache.
+ * @return Statistics and Info for the Memory Cache.
*/
IStats getStatistics();
@@ -204,4 +204,11 @@ public interface IMemoryCache<K extends
* @return a Set of group keys.
*/
Set<K> getGroupKeys( String group );
+
+ /**
+ * Gets the set of group names in the cache
+ * <p>
+ * @return a Set of group names.
+ */
+ Set<String> getGroupNames();
}
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java Sun Nov 11 14:38:08 2012
@@ -163,6 +163,16 @@ public class MockAuxiliaryCache<K extend
{
return null;
}
+
+ /**
+ * @return null
+ * @throws IOException
+ */
+ public Set<String> getGroupNames()
+ throws IOException
+ {
+ return null;
+ }
/**
* @return null
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/AbstractDiskCacheUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/AbstractDiskCacheUnitTest.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/AbstractDiskCacheUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/AbstractDiskCacheUnitTest.java Sun Nov 11 14:38:08 2012
@@ -194,6 +194,15 @@ public class AbstractDiskCacheUnitTest
}
/**
+ * @return Collections.EMPTY_SET
+ */
+ @Override
+ public Set<String> getGroupNames()
+ {
+ return Collections.emptySet();
+ }
+
+ /**
* @return map.size()
*/
@Override
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java Sun Nov 11 14:38:08 2012
@@ -20,6 +20,7 @@ package org.apache.jcs.auxiliary.lateral
*/
import java.util.Map;
+import java.util.Set;
import junit.framework.TestCase;
@@ -32,6 +33,8 @@ import org.apache.jcs.engine.behavior.IC
import org.apache.jcs.engine.control.CompositeCache;
import org.apache.jcs.engine.control.CompositeCacheManager;
import org.apache.jcs.engine.control.MockCompositeCacheManager;
+import org.apache.jcs.engine.control.group.GroupAttrName;
+import org.apache.jcs.engine.control.group.GroupId;
import org.apache.jcs.utils.timing.SleepUtil;
/**
@@ -272,6 +275,112 @@ public class TestTCPLateralUnitTest
}
/**
+ * Create a listener. Add an element to the listeners cache. Setup a service. Try to get group keys from
+ * the service.
+ * <p>
+ * @throws Exception
+ */
+ public void testGetGroupKeys_SendAndReceived() throws Exception
+ {
+ // SETUP
+ // setup a listener
+ TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
+ lattr.setTcpListenerPort( 1150 );
+ MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
+ CompositeCache<GroupAttrName<String>, String> cache = cacheMgr.getCache( "test" );
+ System.out.println( "mock cache = " + cache );
+
+ // get the listener started
+ // give it our mock cache manager
+ LateralTCPListener.getInstance( lattr, cacheMgr );
+
+ // add the item to the listeners cache
+ GroupAttrName<String> groupKey = new GroupAttrName<String>(new GroupId("test", "group"), "key");
+ ICacheElement<GroupAttrName<String>, String> element =
+ new CacheElement<GroupAttrName<String>, String>( "test", groupKey, "value1" );
+ cache.update( element );
+
+ // setup a service to talk to the listener started above.
+ TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
+ lattr2.setTcpListenerPort( 1151 );
+ lattr2.setTcpServer( "localhost:1150" );
+
+ LateralTCPService<GroupAttrName<String>, String> service =
+ new LateralTCPService<GroupAttrName<String>, String>( lattr2 );
+ service.setListenerId( 123459 );
+
+ SleepUtil.sleepAtLeast( 500 );
+
+ // DO WORK
+ Set<GroupAttrName<String>> result = service.getGroupKeys("test", "group");
+
+ // SleepUtil.sleepAtLeast( 5000000 );
+
+ // VERIFY
+ System.out.println( "testSendAndReceived, result = " + result );
+ assertNotNull( "Result should not be null.", result );
+ assertEquals( "Didn't get the correct object", "key", result.toArray()[0] );
+
+ result = service.getGroupKeys("test", "");
+ System.out.println( "testSendAndReceived, result = " + result );
+ assertTrue("List should be empty", result.size() == 0);
+ }
+
+ /**
+ * Create a listener. Add an element to the listeners cache. Setup a service. Try to get group names from
+ * the service.
+ * <p>
+ * @throws Exception
+ */
+ public void testGetGroupNames_SendAndReceived() throws Exception
+ {
+ // SETUP
+ // setup a listener
+ TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
+ lattr.setTcpListenerPort( 1157 );
+ MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
+ CompositeCache<GroupAttrName<String>, String> cache = cacheMgr.getCache( "test" );
+ System.out.println( "mock cache = " + cache );
+
+ // get the listener started
+ // give it our mock cache manager
+ LateralTCPListener.getInstance( lattr, cacheMgr );
+
+ // add the item to the listeners cache
+ GroupAttrName<String> groupKey = new GroupAttrName<String>(new GroupId("test", "group"), "key");
+ ICacheElement<GroupAttrName<String>, String> element =
+ new CacheElement<GroupAttrName<String>, String>( "test", groupKey, "value1" );
+ cache.update( element );
+
+ groupKey = new GroupAttrName<String>(new GroupId("test", "group2"), "key2");
+ element = new CacheElement<GroupAttrName<String>, String>( "test", groupKey, "value2" );
+ cache.update( element );
+
+ // setup a service to talk to the listener started above.
+ TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
+ lattr2.setTcpListenerPort( 1156 );
+ lattr2.setTcpServer( "localhost:1157" );
+
+ LateralTCPService<GroupAttrName<String>, String> service =
+ new LateralTCPService<GroupAttrName<String>, String>( lattr2 );
+ service.setListenerId( 123469 );
+
+ SleepUtil.sleepAtLeast( 500 );
+
+ // DO WORK
+ Set<String> result = service.getGroupNames("test");
+
+ // SleepUtil.sleepAtLeast( 5000000 );
+
+ // VERIFY
+ System.out.println( "testSendAndReceived, result = " + result );
+ assertNotNull( "Result should not be null.", result );
+ assertTrue( "Size is wrong" , result.size() == 2);
+ assertTrue( "Didn't get the correct object", result.contains("group"));
+ assertTrue( "Didn't get the correct object", result.contains("group2"));
+ }
+
+ /**
* Create a listener. Add an element to the listeners cache. Setup a service. Try to get from
* the service.
* <p>
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java Sun Nov 11 14:38:08 2012
@@ -204,6 +204,14 @@ public class MockRemoteCacheClient<K ext
{
return null;
}
+
+ /**
+ * @return null
+ */
+ public Set<String> getGroupNames()
+ {
+ return null;
+ }
/**
* @return null
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheService.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheService.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheService.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheService.java Sun Nov 11 14:38:08 2012
@@ -84,6 +84,15 @@ public class MockRemoteCacheService<K ex
}
/**
+ * @param cacheName
+ * @return empty set
+ */
+ public Set<String> getGroupNames(String cacheName) throws IOException
+ {
+ return new HashSet<String>();
+ }
+
+ /**
* Set the last remove key.
* <p>
* @param cacheName
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/MockCacheServiceNonLocal.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/MockCacheServiceNonLocal.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/MockCacheServiceNonLocal.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/MockCacheServiceNonLocal.java Sun Nov 11 14:38:08 2012
@@ -84,6 +84,15 @@ public class MockCacheServiceNonLocal<K
}
/**
+ * @param cacheName
+ * @return empty set
+ */
+ public Set<String> getGroupNames(String cacheName) throws IOException
+ {
+ return new HashSet<String>();
+ }
+
+ /**
* Set the last remove key.
* <p>
* @param cacheName
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java Sun Nov 11 14:38:08 2012
@@ -414,6 +414,16 @@ public class CompositeCacheDiskUsageUnit
{
return null;
}
+
+ /**
+ * @return null
+ * @throws IOException
+ */
+ public Set<String> getGroupNames()
+ throws IOException
+ {
+ return null;
+ }
/** @return null */
public IStats getStatistics()
@@ -484,6 +494,8 @@ public class CompositeCacheDiskUsageUnit
{
return Collections.emptyMap();
}
+
+
}
}
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/memory/MockMemoryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/memory/MockMemoryCache.java?rev=1408014&r1=1408013&r2=1408014&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/memory/MockMemoryCache.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/engine/memory/MockMemoryCache.java Sun Nov 11 14:38:08 2012
@@ -224,6 +224,14 @@ public class MockMemoryCache<K extends S
{
return null;
}
+
+ /**
+ * @return null
+ */
+ public Set<String> getGroupNames()
+ {
+ return null;
+ }
/**
* @param numberToFree
|