Reputation: 31
I am planning to write a coherence explorer for our project. There are several caches, both distributed and replicated ones. The first part tries to fetch details of all the caches, made some headway.
One bottleneck is for programmatically exploring clusters, members and caches, the starting point is a named cache. If I do not have a named cache, there's no way to identify all caches, members and cluster details. Also at a given point of time , its either distributed or replicated.
Can someone give me an insight how to proceed further. Here's the code snapshot
// Get hold of the cache
NamedCache cache = CacheFactory.getCache("ias.connection.segment");
// Fetch the reference of Cache Service
CacheService cacheService = cache.getCacheService();
// Get the cluster from the service
Cluster theCluster = cacheService.getCluster();
// Print the name of this cluster
String theClusterName = theCluster.getClusterName();
System.out.println("\n Cluster Name : "+ theClusterName);
System.out.println("-------------------------------------");
int countOne = 0;
// Iterate through the services running in this cluster
for ( Enumeration enumService = theCluster.getServiceNames() ; enumService.hasMoreElements(); )
{
countOne = countOne+1;
// Get Service Name
String serviceName = (String) enumService.nextElement();
// Extract the Service Info Object from this service
ServiceInfo info = theCluster.getServiceInfo(serviceName);
//Emit out the service Name & its type
System.out.println(countOne+ " Service Name : [ "+serviceName + " ]"+" Service Type : [ "+ info.getServiceType() +" ]");
System.out.println("--------------------------------------------");
}
// Try to extract cache names from the service
System.out.println("\nHere's the List of Caches \n");
String cacheName ;
ServiceInfo serviceInformation;
CacheService service;
int count = 0;
for ( Enumeration enums = cacheService.getCacheNames() ; enums.hasMoreElements(); )
{
cacheName = (String) enums.nextElement();
count=count+1;
cache = CacheFactory.getCache(cacheName);
service = cache.getCacheService();
serviceInformation= service.getInfo();
System.out.println(count +" Cache : ["+cacheName+" ]"+ " Service Type : [ "+ serviceInformation.getServiceType()+" ] \n");
}
ServiceInfo theServiceInfo = cacheService.getInfo();
int countThree = 0;
Set clusterMemebers = theCluster.getMemberSet();
Iterator iter = clusterMemebers.iterator();
while (iter.hasNext()) {
countThree = countThree +1;
Member theMember =(Member) iter.next();
System.out.println(countThree+ " Member Details : [ "+ theMember+" ]");
}
CacheFactory.shutdown();
}
Upvotes: 0
Views: 465
Reputation: 1236
You could always start with CacheFactory.getCluster() and work "down" from there ...
Upvotes: 1