/** * Returns the last created instance of GemFireCache * * @deprecated use DM.getCache instead */ @Deprecated public static GemFireCacheImpl getInstance() { InternalDistributedSystem system = InternalDistributedSystem.getAnyInstance(); if (system == null) { return null; } GemFireCacheImpl cache = (GemFireCacheImpl) system.getCache(); if (cache == null) { return null; } if (cache.isClosing) { return null; } return cache; }
public RegionService createAuthenticatedCacheView(Properties properties) { if (!this.multiuserSecureModeEnabled) { throw new UnsupportedOperationException( "Operation not supported when multiuser-authentication is false."); } if (properties == null || properties.isEmpty()) { throw new IllegalArgumentException("Security properties cannot be empty."); } Properties props = new Properties(); for (Entry<Object, Object> entry : properties.entrySet()) { props.setProperty((String) entry.getKey(), (String) entry.getValue()); } if (cache == null && dsys != null) { cache = dsys.getCache(); if (cache == null) { throw new IllegalStateException( "Cache must be created before creating pool"); } } ProxyCache proxy = new ProxyCache(props, cache, this); synchronized (this.proxyCacheList) { this.proxyCacheList.add(proxy); } return proxy; }
public void waitTilServerFullyReconnected() { vm.invoke(() -> { try { await().until(() -> { InternalDistributedSystem internalDistributedSystem = InternalDistributedSystem.getConnectedInstance(); return internalDistributedSystem != null && internalDistributedSystem.getCache() != null && !internalDistributedSystem.getCache().getCacheServers().isEmpty(); }); } catch (Exception e) { // provide more information when condition is not satisfied after awaitility timeout InternalDistributedSystem ids = InternalDistributedSystem.getConnectedInstance(); logger.info("ds is: " + (ids != null ? "not null" : "null")); logger.info("cache is: " + (ids.getCache() != null ? "not null" : "null")); logger.info("has cache server: " + (!ids.getCache().getCacheServers().isEmpty())); throw e; } }); }
public static void backup(String targetDir) throws AdminException { InternalDistributedSystem ads = getAdminCnx(); // Baseline directory should be null if it was not provided on the command line BackupStatus status = new BackupOperation(ads.getDistributionManager(), ads.getCache()).backupAllMembers( targetDir, SystemAdmin.baselineDir); boolean incomplete = !status.getOfflineDiskStores().isEmpty(); System.out.println("The following disk stores were backed up:"); for (Set<PersistentID> memberStores : status.getBackedUpDiskStores().values()) { for (PersistentID store : memberStores) { System.out.println("\t" + store); } } if (incomplete) { System.err.println("The backup may be incomplete. The following disk stores are not online:"); for (PersistentID store : status.getOfflineDiskStores()) { System.err.println("\t" + store); } } else { System.out.println("Backup successful."); } }
when(system.createAtomicStatistics(any(), any(), anyLong())).thenReturn(stats); when(system.createAtomicStatistics(any(), any())).thenReturn(stats); when(system.getCache()).thenReturn(cache);
/** * Pdx is allowed to obtain the cache even while it is being closed * * @deprecated Rather than fishing for a cache with this static method, use a cache that is passed * in to your method. */ public static GemFireCacheImpl getForPdx(String reason) { InternalDistributedSystem system = getAnyInstance(); if (system == null) { throw new CacheClosedException(reason); } GemFireCacheImpl cache = (GemFireCacheImpl) system.getCache(); if (cache == null) { throw new CacheClosedException(reason); } return cache; }
private static GemFireCacheImpl checkExistingCache(boolean existingOk, CacheConfig cacheConfig, InternalDistributedSystem system) { GemFireCacheImpl instance = ALLOW_MULTIPLE_SYSTEMS ? (GemFireCacheImpl) system.getCache() : getInstance(); if (instance != null && !instance.isClosed()) { if (existingOk) { // Check if cache configuration matches. cacheConfig.validateCacheConfig(instance); return instance; } else { // instance.creationStack argument is for debugging... throw new CacheExistsException(instance, String.format("%s: An open cache already exists.", instance), instance.creationStack); } } return null; }
@Before public void setUp() { system = mock(InternalDistributedSystem.class); ManagementAdapter managementAdapter = mock(ManagementAdapter.class); readWriteLock = spy(ReadWriteLock.class); readLock = spy(Lock.class); writeLock = spy(Lock.class); when(system.getCache()).thenReturn(mock(InternalCache.class)); when(system.isConnected()).thenReturn(true); when(readWriteLock.readLock()).thenReturn(readLock); when(readWriteLock.writeLock()).thenReturn(writeLock); readLockInOrder = inOrder(readLock, readLock); writeLockInOrder = inOrder(writeLock, writeLock); managementListener = new ManagementListener(mock(CancelCriterion.class), system, managementAdapter, readWriteLock); }
@Test public void shouldProceedReturnsFalseIfNoCache() { when(system.getCache()).thenReturn(null); for (ResourceEvent resourceEvent : ResourceEvent.values()) { assertThat(managementListener.shouldProceed(resourceEvent)).isFalse(); } }
@Test public void clientCacheWouldNotRequestClusterConfig() { // we will need to set the value to true so that we can use a mock cache boolean oldValue = InternalDistributedSystem.ALLOW_MULTIPLE_SYSTEMS; InternalDistributedSystem.ALLOW_MULTIPLE_SYSTEMS = true; cache = mock(GemFireCacheImpl.class); when(distributedSystem.getCache()).thenReturn(cache); GemFireCacheImpl.createClient(distributedSystem, null, cacheConfig); verify(cache, times(0)).requestSharedConfiguration(); verify(cache, times(0)).applyJarAndXmlFromClusterConfig(); // reset it back to the old value InternalDistributedSystem.ALLOW_MULTIPLE_SYSTEMS = oldValue; } }
/** * Checks various conditions which might arise due to race condition for lock of * GemFireCacheImpl.class which is obtained while GemFireCacheImpl constructor, cache.close(), * DistributedSystem.disconnect(). * * As ManagementService creation logic is called in cache.init() method it leaves a small window * of loosing the lock of GemFireCacheImpl.class * * These checks ensures that something unwanted has not happened during that small window * * @return true or false depending on the status of Cache and System */ boolean shouldProceed(ResourceEvent event) { InternalDistributedSystem.getConnectedInstance(); // CACHE_REMOVE is a special event. ForcedDisconnectException may raise this event. if (!system.isConnected() && !event.equals(ResourceEvent.CACHE_REMOVE)) { return false; } InternalCache currentCache = system.getCache(); if (currentCache == null) { return false; } return !currentCache.isClosed(); }
private RuntimeException generatePoolOrCacheCancelledException(Throwable e) { RuntimeException re = getCancelCriterion().generateCancelledException(e); if (re != null) { return re; } if (cache == null) { if (cacheCriterion != null) { return cacheCriterion.generateCancelledException(e); } if (dsys != null) { cache = dsys.getCache(); if (cache == null) { throw new IllegalStateException( "Cache must be created before creating pool"); } } } else { if (cacheCriterion == null || cacheCriterion != cache.getCancelCriterion()) { cacheCriterion = cache.getCancelCriterion(); } return cacheCriterion.generateCancelledException(e); } return null; }
final List<Integer> bucketIds = me.getValue(); PartitionMessage m = createRequestMessage(rcp, processor, bucketIds); m.setTransactionDistributed(this.sys.getCache().getTxManager().isDistributed()); Set notReceivedMembers = sendMessage(m); if (th != null) {
try { if (cache == null && dsys != null) { cache = dsys.getCache(); if (cache == null) { throw new IllegalStateException(
if (reconnected) { system = (InternalDistributedSystem) system.getReconnectedSystem(); cache = system.getCache();
txLockId)); system.getDistributionManager().getCancelCriterion().checkCancelInProgress(e); Cache cache = system.getCache(); if (cache != null) { cache.getCancelCriterion().checkCancelInProgress(e);
InternalCache currentCache = getCache(); if (currentCache != null && !currentCache.isClosed()) {