return embeddedCacheManager.getCacheNames().contains(cacheName);
}
public Response handle(CacheRpcCommand cmd) throws Throwable {
String cacheName = cmd.getCacheName();
ComponentRegistry cr = gcr.getNamedComponentRegistry(cacheName);
if (cr == null) {
if (embeddedCacheManager.getGlobalConfiguration().isStrictPeerToPeer()) {
// lets see if the cache is *defined* and perhaps just not started.
if (isDefined(cacheName)) {
log.info("Will try and wait for the cache to start");
long giveupTime = System.currentTimeMillis() + 30000; // arbitrary (?) wait time for caches to start
while (cr == null && System.currentTimeMillis() < giveupTime) {
Thread.sleep(100);
cr = gcr.getNamedComponentRegistry(cacheName);
}
} else {
log.info("Cache {0} is not defined. No point in waiting.", cacheName);
}
}
if (cr == null) {
if (log.isInfoEnabled()) log.info("Cache named {0} does not exist on this cache manager!", cacheName);
return new ExceptionResponse(new NamedCacheNotFoundException(cacheName));
}
}
Configuration localConfig = cr.getComponent(Configuration.class);
if (!cr.getStatus().allowInvocations()) {
long giveupTime = System.currentTimeMillis() + localConfig.getStateRetrievalTimeout();
while (cr.getStatus().startingUp() && System.currentTimeMillis() < giveupTime) Thread.sleep(100);
if (!cr.getStatus().allowInvocations()) {
log.warn("Cache named [{0}] exists but isn't in a state to handle invocations. Its state is {1}.", cacheName, cr.getStatus());
return RequestIgnoredResponse.INSTANCE;
}
}
CommandsFactory commandsFactory = cr.getLocalComponent(CommandsFactory.class);
// initialize this command with components specific to the intended cache instance
commandsFactory.initializeReplicableCommand(cmd, true);
try {
log.trace("Calling perform() on {0}", cmd);
Object retval = cmd.perform(null);
return cr.getComponent(ResponseGenerator.class).getResponse(cmd, retval);
} catch (Exception e) {
return new ExceptionResponse(e);
}
}