Search This Blog

Monday 20 September 2010

Display Cache Scheme from Coherence

Whenever I run coherence.cmd (windows) and I ask for a NamedCache using "cache pastest" for example it prints out the current scheme which I thought was handy for my own testing. After help from Patrick here is what your own code would like like to get that information yourself, if required.

 Note: I was using Coherence 3.6 but same code should work in 3.5 as well

1. Create a class as follows.
package pas.au.coherence.utils;

import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;
import com.tangosol.net.DefaultConfigurableCacheFactory.CacheInfo;
import com.tangosol.net.DefaultConfigurableCacheFactory;

public class DisplaySchemeName 
{
    private static final String CACHE_NAME = "repl-pas";
  
    public DisplaySchemeName() 
    {
    }

    public static void main(String[] args) 
    {
      // TODO Auto-generated method stub
      NamedCache pastest = CacheFactory.getCache(CACHE_NAME);
      
      DefaultConfigurableCacheFactory factory = 
       (DefaultConfigurableCacheFactory) CacheFactory.getConfigurableCacheFactory();

      CacheInfo info = factory.findSchemeMapping(CACHE_NAME);
      
      System.out.println(String.valueOf(factory.resolveScheme(info)));
      System.out.println("all done..");
  
    }
}

2. Run it to verify it displays the cache scheme we are using as shown below.

....
....
TcpRing{Connections=[]}
IpMonitor{AddressListSize=0}

2010-09-20 12:43:17.259/4.898 Oracle Coherence GE 3.6.0.0 <D5> (thread=Invocation:Management, member=1): Service Management joined the cluster with senior service member 1
2010-09-20 12:43:17.463/5.102 Oracle Coherence GE 3.6.0.0 <D5> (thread=ReplicatedCache, member=1): Service ReplicatedCache joined the cluster with senior service member 1
<replicated-scheme>
  <scheme-name>example-replicated</scheme-name>
  <service-name>ReplicatedCache</service-name>
  <backing-map-scheme>
    <local-scheme>
      <scheme-ref>unlimited-backing-map</scheme-ref>
    </local-scheme>
  </backing-map-scheme>
  <autostart>true</autostart>
</replicated-scheme>
all done..
2010-09-20 12:43:17.510/5.149 Oracle Coherence GE 3.6.0.0 <D4> (thread=ShutdownHook, member=1): ShutdownHook: stopping cluster node
2010-09-20 12:43:17.510/5.149 Oracle Coherence GE 3.6.0.0 <D5> (thread=Cluster, member=1): Service Cluster left the cluster

No comments: