Created
August 31, 2014 16:18
-
-
Save crudh/1c06d1c8479e5302179c to your computer and use it in GitHub Desktop.
Example code on how to get info about a Coherence cluster and caches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Enumeration; | |
import java.util.List; | |
import com.tangosol.coherence.component.net.Member; | |
import com.tangosol.net.CacheFactory; | |
import com.tangosol.net.CacheService; | |
import com.tangosol.net.Cluster; | |
import com.tangosol.net.NamedCache; | |
import com.tangosol.net.Service; | |
final Cluster cluster = CacheFactory.getCluster(); | |
final String clusterName = cluster.getClusterName(); | |
final int clusterTimeInMillis = cluster.getTimeMillis(); | |
for (Object m : cluster.getMemberSet()) { | |
final Member member = (Member)m; | |
System.out.println(member.getId()); | |
System.out.println(member.getMachineName()); | |
System.out.println(member.getAddress().getHostAddress()); | |
System.out.println(member.getPort()); | |
} | |
final Enumeration<String> serviceNames = cluster.getServiceNames(); | |
while (serviceNames.hasMoreElements()) { | |
final String serviceName = (String)serviceNames.nextElement(); | |
final Service service = cluster.getService(serviceName); | |
if (service instanceof CacheService) { | |
final CacheService cacheService = (CacheService)service; | |
final Enumeration<String> cacheNames = cacheService.getCacheNames(); | |
while (cacheNames.hasMoreElements()) { | |
final NamedCache cache = CacheFactory.getCache(cacheNames.nextElement()); | |
System.out.println(cache.getCacheName()); | |
System.out.println(cache.getCacheService().getInfo().getServiceType()); | |
System.out.println(cache.size()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment