/** * Gets an arbitrary open instance of {@link Cache} produced by an earlier call to {@link * #create()}. * * @throws CacheClosedException if a cache has not been created or the only created one is {@link * Cache#isClosed closed} */ public static synchronized Cache getAnyInstance() { GemFireCacheImpl instance = GemFireCacheImpl.getInstance(); if (instance == null) { throw new CacheClosedException( LocalizedStrings.CacheFactory_A_CACHE_HAS_NOT_YET_BEEN_CREATED.toLocalizedString()); } else { instance.getCancelCriterion().checkCancelInProgress(null); return instance; } }
private static Cache basicGetInstancePart2(DistributedSystem system, boolean closeOk) { GemFireCacheImpl instance = GemFireCacheImpl.getInstance(); if (instance == null) { throw new CacheClosedException( LocalizedStrings.CacheFactory_A_CACHE_HAS_NOT_YET_BEEN_CREATED.toLocalizedString()); } else { if (instance.isClosed() && !closeOk) { throw instance.getCacheClosedException( LocalizedStrings.CacheFactory_THE_CACHE_HAS_BEEN_CLOSED.toLocalizedString(), null); } if (!instance.getDistributedSystem().equals(system)) { throw new CacheClosedException( LocalizedStrings .CacheFactory_A_CACHE_HAS_NOT_YET_BEEN_CREATED_FOR_THE_GIVEN_DISTRIBUTED_SYSTEM .toLocalizedString()); } return instance; } }