4 Replies Latest reply on Oct 12, 2012 1:13 PM by 967759

    Getting list of cache names

      I have been using this code to get the list of all the cache names of my cluster :

      Cluster cluster=CacheFactory.ensureCluster();
      for (Enumeration<String> services = cluster.getServiceNames(); services.hasMoreElements(); )
           String sName = (String) services.nextElement();
           Service service=cluster.getService(sName);      
           if (service instanceof CacheService){
                CacheService cService=(CacheService)service;
                Enumeration<String> caches = cService.getCacheNames();           
                for (caches = cService.getCacheNames(); caches.hasMoreElements();){
                     // add caches.nextElement() in a list


      It is working fine but in order to access multiple clusters I have to use Coherence proxy/extend.

      When I use proxy/extend, the code above does not work anymore. I explain: when using proxy/extend, cluster.getServiceNames() returns Management and Cluster but does not return the Cache Services anymore.

      I have tried to get a cluster object in a different way :

      ((InvocationService) CacheFactory.getConfigurableCacheFactory().ensureService("ExtendTcpInvocationService")).getCluster;

      where ExtendTcpInvocationService is defined with <remote-invocation-scheme> but the result is the same.

      To sum up : I would like to get the list of all my cache names in a multi-cluster application ; is it possible?
        • 1. Re: Getting list of cache names
          Use the Invocation Service to get a list of cache name when you are an extend client.

          Create an Invocable (which will run on proxy when you execute it through invocation service) to execute the same logic you have now and return the list of cache name.

          1 person found this helpful
          • 2. Re: Getting list of cache names
            Thank you for the clue.

            I tried executing a Query with an Invocable object but I am getting some other exception:

            (Wrapped) java.io.IOException: readObject failed: java.lang.ClassNotFoundException: com.app.data.ListTask
            at java.net.URLClassLoader$1.run(Unknown Source)
                 at java.security.AccessController.doPrivileged(Native Method)
                 at java.net.URLClassLoader.findClass(Unknown Source)
                 at java.lang.ClassLoader.loadClass(Unknown Source)
                 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
                 at java.lang.ClassLoader.loadClass(Unknown Source)
                 at java.lang.Class.forName0(Native Method)
                 at java.lang.Class.forName(Unknown Source)
                 at java.io.ObjectInputStream.resolveClass(Unknown Source)
                 at com.tangosol.io.ResolvingObjectInputStream.resolveClass(ResolvingObjectInputStream.java:66)
                 at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
                 at java.io.ObjectInputStream.readClassDesc(Unknown Source)
                 at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
                 at java.io.ObjectInputStream.readObject0(Unknown Source)
                 at java.io.ObjectInputStream.readObject(Unknown Source)
                 at com.tangosol.util.ExternalizableHelper.readSerializable(ExternalizableHelper.java:2217)
                 at com.tangosol.util.ExternalizableHelper.readObjectInternal(ExternalizableHelper.java:2348)
                 at com.tangosol.util.ExternalizableHelper.readObject(ExternalizableHelper.java:2291)
                 at com.tangosol.io.DefaultSerializer.deserialize(DefaultSerializer.java:74)
                 at com.tangosol.coherence.component.net.extend.Channel.deserialize(Channel.CDB:15)
                 at com.tangosol.io.pof.PofBufferReader.readAsObject(PofBufferReader.java:3316)
                 at com.tangosol.io.pof.PofBufferReader.readObject(PofBufferReader.java:2604)
                 at com.tangosol.coherence.component.net.extend.messageFactory.InvocationServiceFactory$InvocationRequest.readExternal(InvocationServiceFactory.CDB:5)
                 at com.tangosol.coherence.component.net.extend.Codec.decode(Codec.CDB:29)
                 at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Peer.decodeMessage(Peer.CDB:25)
                 at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Peer.onNotify(Peer.CDB:54)
                 at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:42)
                 at java.lang.Thread.run(Unknown Source)

            From what I understand, the "server" excecuting the "run" from my invocable does not know the invocable class (ListTask).
            I suppose I have to put this class in the server classpath?
            Is there any way to have the result hoped without making any modification to the "server" ?
            • 3. Re: Getting list of cache names

              Yes, your invocable needs to be on the server's classpath and as you are using POF it also needs to be in the server's POF configuration file.

              The easiest way to find the cache names on the server without needing code on the cluster is to use JMX - assuming you have enabled JMX on the cluster. You can easily run a JMX query from Java code or use something ike JConsole of VisualVM..

              • 4. Re: Getting list of cache names
                Adding the jar to the classPath worked.

                I keep in mind the possibility to gather the cache name list using JMX.

                Thank you all!