user3912828
user3912828

Reputation: 43

How to get All Cache names present in Oracle Coherence cluster?

I am running Oracle coherence cluster and using extended clients to connect to the cluster. If there are multiple extended clients which keep joining and leaving oracle coherence cluster, then there are chances that one service created some caches and left the cluster but those caches are present in cluster.

I want all the cache names present in the cluster at any point of time.

Is it possible to get all cache names?

There is an API in cacheService called getCacheNames which returns all cache names corresponding to that service.

But how to get the cache names created by other services belonging to clients which are no more active but caches are present in cluster?

[UPDATE] :- There is a command called 'maps' which gives all the caches present in server(created by all clients). But i am not able to find any APi to do the same operation.

Is there any API to execute maps command or any way to execute this command directly using JAVA code.

Upvotes: 4

Views: 2818

Answers (1)

Paul Creasey
Paul Creasey

Reputation: 28824

Better late than never...

here is a rough example, needs a bit of tidying up if you want to use it in production...

Enumeration serviceNames = CacheFactory.getCluster().getServiceNames();
while(serviceNames.hasMoreElements()){
    String serviceName = (String)serviceNames.nextElement();
    Service service = null;
    try{
        service = CacheFactory.getService(serviceName);
    }catch(Exception e){
        continue;
    }
    if(service instanceof CacheService){
        CacheService cacheService = (CacheService)service;
        Enumeration cacheNames = cacheService.getCacheNames();
        while(cacheNames.hasMoreElements()){
            String cacheName = (String)cacheNames.nextElement();
            System.out.println("<<<" + cacheName);
        }
    }
}

Upvotes: 3

Related Questions