Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6FE25D54A for ; Sun, 11 Nov 2012 14:38:52 +0000 (UTC) Received: (qmail 12499 invoked by uid 500); 11 Nov 2012 14:38:51 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 12434 invoked by uid 500); 11 Nov 2012 14:38:51 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 12407 invoked by uid 99); 11 Nov 2012 14:38:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Nov 2012 14:38:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Nov 2012 14:38:42 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4C33723889E2 for ; Sun, 11 Nov 2012 14:38:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1408014 - in /commons/proper/jcs/trunk/src: changes/ java/org/apache/jcs/access/ java/org/apache/jcs/auxiliary/ java/org/apache/jcs/auxiliary/disk/ java/org/apache/jcs/auxiliary/disk/block/ java/org/apache/jcs/auxiliary/disk/file/ java/org... Date: Sun, 11 Nov 2012 14:38:15 -0000 To: commits@commons.apache.org From: tv@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121111143819.4C33723889E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ + + Add getGroupNames() to all caches. + + + LateralTCPService should implement getGroupKeys. + 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 + * @return A Set of group names. + */ + public Set getGroupNames() + { + return this.cacheControl.getGroupNames(); + } + + /** * Invalidates a group: remove all the group members *

* @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 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. *

- * (non-Javadoc) * @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String) */ public abstract Set getGroupKeys( String groupName ); /** + * The group names in the cache. + *

+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupNames() + */ + public abstract Set getGroupNames(); + + /** * Removes are not queued. A call to remove is immediate. *

* @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 - * (non-Javadoc) * @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#getGroupKeys(java.lang.String) */ @Override @@ -237,6 +236,38 @@ public class BlockDiskCache + * @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#getGroupNames() + */ + @Override + public Set getGroupNames() + { + HashSet names = new HashSet(); + + storageLock.readLock().lock(); + + try + { + for ( Serializable key : this.keyStore.keySet()) + { + if ( key instanceof GroupAttrName ) + { + @SuppressWarnings("unchecked") // Type checked with instanceof + GroupId groupID = ((GroupAttrName) key ).groupId; + names.add( groupID.groupName ); + } + } + } + finally + { + storageLock.readLock().unlock(); + } + + return names; + } + + /** * Gets matching items from the cache. *

* @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 + * @param group + * @return a Set of group keys. */ @Override public Set getGroupKeys(String groupName) @@ -145,6 +147,17 @@ public class FileDiskCache + * @return a Set of group names. + */ + @Override + public Set 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 + * @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String) + */ + @Override + public Set getGroupNames() + { + HashSet names = new HashSet(); + try + { + storageLock.readLock().lock(); + + for (K k : keyHash.keySet()) + { + if ( k instanceof GroupAttrName ) + { + @SuppressWarnings("unchecked") // Type checked with instanceof + GroupAttrName groupAttrName = (GroupAttrName) 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. *

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 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 + * @param group + * @return a Set of group keys. * @throws IOException */ public Set getGroupKeys( String groupName ) @@ -226,6 +228,27 @@ public class LateralCache + * @return a Set of group names. + * @throws IOException + */ + public Set 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. *

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 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 * @param group - * @return Set + * @return a Set of group keys. */ public Set getGroupKeys( String group ) { @@ -298,7 +300,41 @@ public class LateralCacheNoWaitFacade 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 + *

+ * @return a Set of group names. + */ + public Set getGroupNames() + { + HashSet allKeys = new HashSet(); + for ( int i = 0; i < noWaits.length; i++ ) + { + AuxiliaryCache aux = noWaits[i]; + if ( aux != null ) + { + try + { + Set 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 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 - * @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 + * @param cacheName the name of the cache + * @param group the group name + * @return a set of keys + * @throws IOException + */ + public Set 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. + *

+ * @param cacheName the name of the cache + * @return a set of group names + * @throws IOException + */ + public Set handleGetGroupNames( String cacheName ) throws IOException + { + return getCache( cacheName ).getGroupNames(true); + } + + /** * Right now this does nothing. *

* @see org.apache.jcs.engine.behavior.ICacheListener#handleDispose(java.lang.String) @@ -632,7 +658,6 @@ public class LateralTCPListener> 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 obj = handleGetGroupKeys(cacheName, groupName); + ObjectOutputStream oos = new ObjectOutputStream( socket.getOutputStream() ); + oos.writeObject( obj ); + oos.flush(); + } + else if ( led.command == LateralElementDescriptor.GET_GROUP_NAMES ) + { + Set 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 * @param cacheName * @param group * @return Set */ + @SuppressWarnings("unchecked") // Need cast from Object public Set getGroupKeys( String cacheName, String group ) + throws IOException + { + CacheElement ce = new CacheElement(cacheName, group, null); + LateralElementDescriptor led = new LateralElementDescriptor(ce); + // led.requesterId = requesterId; // later + led.command = LateralElementDescriptor.GET_GROUP_KEYS; + Object response = sender.sendAndReceive(led); + if (response != null) + { + return (Set) response; + } + + return null; + } + + /** + * Gets the set of groups currently in the cache throws + * UnsupportedOperationException + *

+ * + * @param cacheName + * @return Set + */ + @SuppressWarnings("unchecked") // Need cast from Object + public Set getGroupNames(String cacheName) + throws IOException { - throw new UnsupportedOperationException( "Groups not implemented." ); - // return null; + CacheElement ce = new CacheElement(cacheName, null, null); + LateralElementDescriptor led = new LateralElementDescriptor(ce); + // led.requesterId = requesterId; // later + led.command = LateralElementDescriptor.GET_GROUP_NAMES; + Object response = sender.sendAndReceive(led); + if (response != null) + { + return (Set) response; + } + + return null; } /** @@ -513,4 +549,6 @@ public class LateralTCPService + * @return Set + * @throws java.rmi.RemoteException + * @throws IOException + */ + public Set 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 aux = noWaits[i]; if ( aux != null ) { - allKeys.addAll( aux.getGroupKeys( group ) ); + Set groupKeys = aux.getGroupKeys( group ); + if(groupKeys != null) + { + allKeys.addAll( groupKeys ); + } } } return allKeys; } /** + * Gets the group names in the cache + *

+ * + * @return the set of group names + * @throws IOException + */ + public Set getGroupNames() throws IOException + { + HashSet names = new HashSet(); + for (int i = 0; i < noWaits.length; i++) + { + AuxiliaryCache aux = noWaits[i]; + if (aux != null) + { + Set groupNames = aux.getGroupNames(); + if (groupNames != null) + { + names.addAll(groupNames); + } + } + } + + return names; + } + + /** * Adds a remove request to the remote cache. *

* @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 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 + * @param cacheName the name of the cache + * @param groupName the name of the group + * @return a Set of group keys. * @throws IOException */ public Set getGroupKeys( String cacheName, String groupName ) @@ -402,6 +404,36 @@ public class RemoteHttpCacheClient + * @return a Set of group names. + * @throws IOException + */ + public Set 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 remoteHttpCacheRequest = + RemoteCacheRequestFactory.createGetGroupNamesRequest( cacheName, 0 ); + + RemoteCacheResponse remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); + + if ( remoteHttpCacheResponse != null && remoteHttpCacheResponse.getPayload() != null ) + { + // FIXME: Unchecked cast + return (Set)remoteHttpCacheResponse.getPayload().get( cacheName ); + } + + return Collections.emptySet(); + } + + /** * Make and alive request. *

* @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. + *

+ * @param cacheName + * @param group + * @return A Set of group names + */ + public Set getGroupNames( String cacheName ) + { + return processGetGroupNames( cacheName ); + } + + /** + * Gets the set of keys of objects currently in the group. + *

+ * @param cacheName + * @param groupName + * @return Set + */ + public Set 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. *

* @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 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 + * @param cacheName the name of the region + * @return A Set of group names + */ + public Set getGroupNames(String cacheName) + { + return processGetGroupNames(cacheName); + } + + /** + * Gets the set of group names currently in the cache. + *

+ * @param cacheName the name of the region + * @return A Set of group names + */ + protected Set processGetGroupNames(String cacheName) + { + CacheListeners cacheDesc = null; + try + { + cacheDesc = getCacheListeners(cacheName); + } + catch (Exception e) + { + log.error("Problem getting listeners.", e); + } + + if (cacheDesc == null) + { + return Collections.emptySet(); + } + + CompositeCache c = (CompositeCache) cacheDesc.cache; + return c.getGroupNames(); + } + + /** * Removes the given key from the specified remote cache. Defaults the listener id to 0. *

* @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. + *

+ * @param cacheName + * @param requesterId + * @return RemoteHttpCacheRequest + */ + public static RemoteCacheRequest createGetGroupNamesRequest( String cacheName, int requesterId) + { + RemoteCacheRequest request = new RemoteCacheRequest(); + 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. *

* @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 + * @param cacheName - region name + * @return empty set + */ + public Set getGroupNames( String cacheName ) + { + return Collections.emptySet(); + } + + /** * Walk the queue, calling the service for each queue operation. *

* @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 - * @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 getGroupKeys( String cacheName, String groupName ) throws IOException; + + /** + * Gets the set of group names in the cache + *

+ * @param cacheName the name of the cache + * @return a Set of group names. + * @throws IOException + */ + Set 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 - * @param group + * @param group the name of the group * @return A Set of keys, or null. */ public Set getGroupKeys( String group ) { + return getGroupKeys(group, false); + } + + /** + * Gets the set of keys of objects currently in the group. + *

+ * @param group the name of the group + * @return A Set of keys, or null. + */ + public Set getGroupKeys( String group, boolean localOnly ) + { HashSet allKeys = new HashSet(); allKeys.addAll( memCache.getGroupKeys( group ) ); for ( int i = 0; i < auxCaches.length; i++ ) @@ -1118,13 +1129,61 @@ public class CompositeCache 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 + *

+ * @return a Set of group names. + */ + public Set getGroupNames() + { + return getGroupNames( false ); + } + + /** + * Gets the set of group names in the cache + *

+ * @param localOnly whether to get the group names only from local caches or not + * @return a Set of group names. + */ + public Set getGroupNames(boolean localOnly) + { + HashSet allKeys = new HashSet(); + allKeys.addAll( memCache.getGroupNames() ); + for ( int i = 0; i < auxCaches.length; i++ ) + { + AuxiliaryCache aux = auxCaches[i]; + if ( aux != null ) + { + if(!localOnly || aux.getCacheType() == CacheType.DISK_CACHE) { - // ignore + try + { + Set 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 + *

+ * @return a Set of group names. + */ + public Set getGroupNames() + { + HashSet names = new HashSet(); + synchronized ( map ) + { + for (Map.Entry> entry : map.entrySet()) + { + K k = entry.getKey(); + + if ( k instanceof GroupAttrName ) + { + names.add(( (GroupAttrName) 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 - * @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 getGroupKeys( String group ); + + /** + * Gets the set of group names in the cache + *

+ * @return a Set of group names. + */ + Set 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 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 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. + *

+ * @throws Exception + */ + public void testGetGroupKeys_SendAndReceived() throws Exception + { + // SETUP + // setup a listener + TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes(); + lattr.setTcpListenerPort( 1150 ); + MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager(); + CompositeCache, 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 groupKey = new GroupAttrName(new GroupId("test", "group"), "key"); + ICacheElement, String> element = + new CacheElement, 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, String> service = + new LateralTCPService, String>( lattr2 ); + service.setListenerId( 123459 ); + + SleepUtil.sleepAtLeast( 500 ); + + // DO WORK + Set> 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. + *

+ * @throws Exception + */ + public void testGetGroupNames_SendAndReceived() throws Exception + { + // SETUP + // setup a listener + TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes(); + lattr.setTcpListenerPort( 1157 ); + MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager(); + CompositeCache, 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 groupKey = new GroupAttrName(new GroupId("test", "group"), "key"); + ICacheElement, String> element = + new CacheElement, String>( "test", groupKey, "value1" ); + cache.update( element ); + + groupKey = new GroupAttrName(new GroupId("test", "group2"), "key2"); + element = new CacheElement, 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, String> service = + new LateralTCPService, String>( lattr2 ); + service.setListenerId( 123469 ); + + SleepUtil.sleepAtLeast( 500 ); + + // DO WORK + Set 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. *

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 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 getGroupNames(String cacheName) throws IOException + { + return new HashSet(); + } + + /** * Set the last remove key. *

* @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 getGroupNames(String cacheName) throws IOException + { + return new HashSet(); + } + + /** * Set the last remove key. *

* @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 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 getGroupNames() + { + return null; + } /** * @param numberToFree