@Test public void testClusterRejoined() { Toolkit toolkit = getMockToolkit(); ClusteredEntityManager entityManager = mock(ClusteredEntityManager.class); ClusteredCacheManager cmEntity = mock(ClusteredCacheManager.class); ClusteredCache cEntity = mock(ClusteredCache.class); when(cmEntity.getCache(CACHE_NAME)).thenReturn(cEntity); when(entityManager.getRootEntity(CACHE_MANAGER_NAME, ClusteredCacheManager.class)).thenReturn(cmEntity); when(entityManager.getEntityLock(any(String.class))).thenReturn(mock(ToolkitReadWriteLock.class)); ToolkitInstanceFactoryImpl toolkitInstanceFactory = new ToolkitInstanceFactoryImpl(toolkit, entityManager); toolkitInstanceFactory.linkClusteredCacheManager(CACHE_MANAGER_NAME, null); toolkitInstanceFactory.addCacheEntityInfo(CACHE_NAME, null, EhcacheEntitiesNaming.getToolkitCacheNameFor(CACHE_MANAGER_NAME, CACHE_NAME)); toolkitInstanceFactory.clusterRejoined(); verify(cmEntity, times(2)).markInUse(); verify(cmEntity, times(2)).markCacheInUse(cEntity); }
@Override public void clusterRejoined() { String cacheManagerName = entityNames.cacheManagerName; synchronized (entityNames) { ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); if (clusteredCacheManager == null) { LOGGER.error("Cache Manager {} has been destroyed by some other node - shutting down to prevent any further use of clustered features", cacheManagerName); shutdown(); } else { try { clusteredCacheManager.releaseUse(); } catch (Exception e) { LOGGER.trace("Exception trying to release cache manager {} after rejoin", entityNames.cacheManagerName); } for (String cacheName : entityNames.getCacheNames()) { ClusteredCache cacheEntity = clusteredCacheManagerEntity.getCache(cacheName); if (cacheEntity != null) { try { clusteredCacheManagerEntity.releaseCacheUse(cacheEntity); } catch (Exception e) { LOGGER.trace("Exception trying to release cache {} after rejoin", cacheName); } } } int retryCount = 0; boolean success = false; while (retryCount < RETRY_MARK_IN_USE_AFTER_REJOIN) { try { clusteredCacheManager.markInUse(); success = (clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class) != null); break; } catch (Exception e) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e1) { } retryCount++; } } if (!success) { LOGGER.error("Unable to mark cache manager {} in use - shutting down to prevent any further use of clustered features", cacheManagerName); shutdown(); } else { for (String cacheName : entityNames.getCacheNames()) { boolean successCache = false; int retryCountCache = 0; while (!successCache && retryCountCache < RETRY_MARK_IN_USE_AFTER_REJOIN) { ClusteredCache cacheEntity = clusteredCacheManagerEntity.getCache(cacheName); if (cacheEntity == null) { LOGGER.error("Cache " + cacheName + " has been destroyed by some other node"); successCache = true; } else { try { clusteredCacheManagerEntity.markCacheInUse(cacheEntity); successCache = true; } catch (Exception e) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e1) { } retryCountCache++; } } } } } } } }
ToolkitInstanceFactoryImpl implements ToolkitInstanceFactory { @Override public void clusterRejoined() { String cacheManagerName = entityNames.cacheManagerName; synchronized (entityNames) { ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); if (clusteredCacheManager == null) { LOGGER.error("Cache Manager {} has been destroyed by some other node - shutting down to prevent any further use of clustered features", cacheManagerName); shutdown(); } else { try { clusteredCacheManager.releaseUse(); } catch (Exception e) { LOGGER.trace("Exception trying to release cache manager {} after rejoin", entityNames.cacheManagerName); } for (String cacheName : entityNames.getCacheNames()) { ClusteredCache cacheEntity = clusteredCacheManagerEntity.getCache(cacheName); if (cacheEntity != null) { try { clusteredCacheManagerEntity.releaseCacheUse(cacheEntity); } catch (Exception e) { LOGGER.trace("Exception trying to release cache {} after rejoin", cacheName); } } } int retryCount = 0; boolean success = false; while (retryCount < RETRY_MARK_IN_USE_AFTER_REJOIN) { try { clusteredCacheManager.markInUse(); success = (clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class) != null); break; } catch (Exception e) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e1) { } retryCount++; } } if (!success) { LOGGER.error("Unable to mark cache manager {} in use - shutting down to prevent any further use of clustered features", cacheManagerName); shutdown(); } else { for (String cacheName : entityNames.getCacheNames()) { boolean successCache = false; int retryCountCache = 0; while (!successCache && retryCountCache < RETRY_MARK_IN_USE_AFTER_REJOIN) { ClusteredCache cacheEntity = clusteredCacheManagerEntity.getCache(cacheName); if (cacheEntity == null) { LOGGER.error("Cache " + cacheName + " has been destroyed by some other node"); successCache = true; } else { try { clusteredCacheManagerEntity.markCacheInUse(cacheEntity); successCache = true; } catch (Exception e) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e1) { } retryCountCache++; } } } } } } } } }
ToolkitInstanceFactoryImpl implements ToolkitInstanceFactory { @Override public void clusterRejoined() { String cacheManagerName = entityNames.cacheManagerName; synchronized (entityNames) { ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); if (clusteredCacheManager == null) { LOGGER.error("Cache Manager {} has been destroyed by some other node - shutting down to prevent any further use of clustered features", cacheManagerName); shutdown(); } else { try { clusteredCacheManager.releaseUse(); } catch (Exception e) { LOGGER.trace("Exception trying to release cache manager {} after rejoin", entityNames.cacheManagerName); } for (String cacheName : entityNames.getCacheNames()) { ClusteredCache cacheEntity = clusteredCacheManagerEntity.getCache(cacheName); if (cacheEntity != null) { try { clusteredCacheManagerEntity.releaseCacheUse(cacheEntity); } catch (Exception e) { LOGGER.trace("Exception trying to release cache {} after rejoin", cacheName); } } } int retryCount = 0; boolean success = false; while (retryCount < RETRY_MARK_IN_USE_AFTER_REJOIN) { try { clusteredCacheManager.markInUse(); success = (clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class) != null); break; } catch (Exception e) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e1) { } retryCount++; } } if (!success) { LOGGER.error("Unable to mark cache manager {} in use - shutting down to prevent any further use of clustered features", cacheManagerName); shutdown(); } else { for (String cacheName : entityNames.getCacheNames()) { boolean successCache = false; int retryCountCache = 0; while (!successCache && retryCountCache < RETRY_MARK_IN_USE_AFTER_REJOIN) { ClusteredCache cacheEntity = clusteredCacheManagerEntity.getCache(cacheName); if (cacheEntity == null) { LOGGER.error("Cache " + cacheName + " has been destroyed by some other node"); successCache = true; } else { try { clusteredCacheManagerEntity.markCacheInUse(cacheEntity); successCache = true; } catch (Exception e) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e1) { } retryCountCache++; } } } } } } } } ToolkitInstanceFactoryImpl(final TerracottaClientConfiguration terracottaClientConfiguration, final String productId);  ToolkitInstanceFactoryImpl(final TerracottaClientConfiguration terracottaClientConfiguration);   ToolkitInstanceFactoryImpl(final Toolkit toolkit, final ClusteredEntityManager clusteredEntityManager);   ToolkitInstanceFactoryImpl(final Toolkit toolkit, final ClusteredEntityManager clusteredEntityManager,
                             final WANUtil util, final Watchdog wanWatchdog); }
ToolkitInstanceFactoryImpl implements ToolkitInstanceFactory { @Override public void clusterRejoined() { String cacheManagerName = entityNames.cacheManagerName; synchronized (entityNames) { ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); if (clusteredCacheManager == null) { LOGGER.error("Cache Manager {} has been destroyed by some other node - shutting down to prevent any further use of clustered features", cacheManagerName); shutdown(); } else { try { clusteredCacheManager.releaseUse(); } catch (Exception e) { LOGGER.trace("Exception trying to release cache manager {} after rejoin", entityNames.cacheManagerName); } for (String cacheName : entityNames.getCacheNames()) { ClusteredCache cacheEntity = clusteredCacheManagerEntity.getCache(cacheName); if (cacheEntity != null) { try { clusteredCacheManagerEntity.releaseCacheUse(cacheEntity); } catch (Exception e) { LOGGER.trace("Exception trying to release cache {} after rejoin", cacheName); } } } int retryCount = 0; boolean success = false; while (retryCount < RETRY_MARK_IN_USE_AFTER_REJOIN) { try { clusteredCacheManager.markInUse(); success = (clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class) != null); break; } catch (Exception e) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e1) { } retryCount++; } } if (!success) { LOGGER.error("Unable to mark cache manager {} in use - shutting down to prevent any further use of clustered features", cacheManagerName); shutdown(); } else { for (String cacheName : entityNames.getCacheNames()) { boolean successCache = false; int retryCountCache = 0; while (!successCache && retryCountCache < RETRY_MARK_IN_USE_AFTER_REJOIN) { ClusteredCache cacheEntity = clusteredCacheManagerEntity.getCache(cacheName); if (cacheEntity == null) { LOGGER.error("Cache " + cacheName + " has been destroyed by some other node"); successCache = true; } else { try { clusteredCacheManagerEntity.markCacheInUse(cacheEntity); successCache = true; } catch (Exception e) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e1) { } retryCountCache++; } } } } } } } } ToolkitInstanceFactoryImpl(final TerracottaClientConfiguration terracottaClientConfiguration, final String productId);  ToolkitInstanceFactoryImpl(final TerracottaClientConfiguration terracottaClientConfiguration);   ToolkitInstanceFactoryImpl(final Toolkit toolkit, final ClusteredEntityManager clusteredEntityManager);   ToolkitInstanceFactoryImpl(final Toolkit toolkit, final ClusteredEntityManager clusteredEntityManager,
                             final WANUtil util, final Watchdog wanWatchdog); @Override void waitForOrchestrator(String cacheManagerName); @Override void markCacheWanDisabled(String cacheManagerName, String cacheName); @Override Toolkit getToolkit(); @Override ToolkitCacheInternal<String, Serializable> getOrCreateToolkitCache(final Ehcache cache); @Override WanAwareToolkitCache<String, Serializable> getOrCreateWanAwareToolkitCache(final String cacheManagerName,
                                                                                    final String cacheName,
                                                                                    final CacheConfiguration ehcacheConfig,
                                                                                    final boolean masterCache,
                                                                                    final boolean bidirectional); @Override ToolkitNotifier<CacheConfigChangeNotificationMsg> getOrCreateConfigChangeNotifier(Ehcache cache); @Override ToolkitNotifier<CacheEventNotificationMsg> getOrCreateCacheEventNotifier(Ehcache cache); @Override ToolkitNotifier<CacheDisposalNotification> getOrCreateCacheDisposalNotifier(Ehcache cache); @Override String getFullyQualifiedCacheName(Ehcache cache); @Override ToolkitLock getOrCreateStoreLock(Ehcache cache); @Override ToolkitMap<String, AttributeExtractor> getOrCreateExtractorsMap(final String cacheManagerName, String cacheName); @Override ToolkitMap<String, String> getOrCreateAttributeMap(final String cacheManagerName, String cacheName); @Override void shutdown(); @Override SerializedToolkitCache<ClusteredSoftLockIDKey, SerializedReadCommittedClusteredSoftLock> getOrCreateAllSoftLockMap(String cacheManagerName,
                                                                                                                            String cacheName); @Override ToolkitMap<SerializedReadCommittedClusteredSoftLock, Integer> getOrCreateNewSoftLocksSet(String cacheManagerName,
                                                                                                  String cacheName); @Override ToolkitMap<String, AsyncConfig> getOrCreateAsyncConfigMap(); @Override ToolkitMap<String, Set<String>> getOrCreateAsyncListNamesMap(String fullAsyncName, String cacheName); @Override ToolkitListInternal getAsyncProcessingBucket(String bucketName, String cacheName); @Override ToolkitMap<String, Serializable> getOrCreateClusteredStoreConfigMap(String cacheManagerName, String cacheName); @Override SerializedToolkitCache<TransactionID, Decision> getOrCreateTransactionCommitStateMap(String cacheManagerName); @Override ToolkitLock getSoftLockWriteLock(String cacheManagerName, String cacheName, TransactionID transactionID,
                                          Object key); @Override ToolkitLock getLockForCache(Ehcache cache, String lockName); @Override ToolkitReadWriteLock getSoftLockFreezeLock(String cacheManagerName, String cacheName,
                                                    TransactionID transactionID, Object key); @Override ToolkitReadWriteLock getSoftLockNotifierLock(String cacheManagerName, String cacheName,
                                                      TransactionID transactionID, Object key); @Override boolean destroy(final String cacheManagerName, final String cacheName); @Override void removeNonStopConfigforCache(Ehcache cache); @Override void linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration); @Override ToolkitMap<String, Serializable> getOrCreateCacheManagerMetaInfoMap(String cacheManagerName); @Override void unlinkCache(String cacheName); @Override void clusterRejoined(); }
ToolkitInstanceFactoryImpl implements ToolkitInstanceFactory { @Override public void clusterRejoined() { String cacheManagerName = entityNames.cacheManagerName; synchronized (entityNames) { ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); if (clusteredCacheManager == null) { LOGGER.error("Cache Manager {} has been destroyed by some other node - shutting down to prevent any further use of clustered features", cacheManagerName); shutdown(); } else { try { clusteredCacheManager.releaseUse(); } catch (Exception e) { LOGGER.trace("Exception trying to release cache manager {} after rejoin", entityNames.cacheManagerName); } for (String cacheName : entityNames.getCacheNames()) { ClusteredCache cacheEntity = clusteredCacheManagerEntity.getCache(cacheName); if (cacheEntity != null) { try { clusteredCacheManagerEntity.releaseCacheUse(cacheEntity); } catch (Exception e) { LOGGER.trace("Exception trying to release cache {} after rejoin", cacheName); } } } int retryCount = 0; boolean success = false; while (retryCount < RETRY_MARK_IN_USE_AFTER_REJOIN) { try { clusteredCacheManager.markInUse(); success = (clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class) != null); break; } catch (Exception e) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e1) { } retryCount++; } } if (!success) { LOGGER.error("Unable to mark cache manager {} in use - shutting down to prevent any further use of clustered features", cacheManagerName); shutdown(); } else { for (String cacheName : entityNames.getCacheNames()) { boolean successCache = false; int retryCountCache = 0; while (!successCache && retryCountCache < RETRY_MARK_IN_USE_AFTER_REJOIN) { ClusteredCache cacheEntity = clusteredCacheManagerEntity.getCache(cacheName); if (cacheEntity == null) { LOGGER.error("Cache " + cacheName + " has been destroyed by some other node"); successCache = true; } else { try { clusteredCacheManagerEntity.markCacheInUse(cacheEntity); successCache = true; } catch (Exception e) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e1) { } retryCountCache++; } } } } } } } } ToolkitInstanceFactoryImpl(final TerracottaClientConfiguration terracottaClientConfiguration, final String productId);  ToolkitInstanceFactoryImpl(final TerracottaClientConfiguration terracottaClientConfiguration);   ToolkitInstanceFactoryImpl(final Toolkit toolkit, final ClusteredEntityManager clusteredEntityManager);   ToolkitInstanceFactoryImpl(final Toolkit toolkit, final ClusteredEntityManager clusteredEntityManager,
                             final WANUtil util, final Watchdog wanWatchdog); @Override void waitForOrchestrator(String cacheManagerName); @Override void markCacheWanDisabled(String cacheManagerName, String cacheName); @Override Toolkit getToolkit(); @Override ToolkitCacheInternal<String, Serializable> getOrCreateToolkitCache(final Ehcache cache); @Override WanAwareToolkitCache<String, Serializable> getOrCreateWanAwareToolkitCache(final String cacheManagerName,
                                                                                    final String cacheName,
                                                                                    final CacheConfiguration ehcacheConfig,
                                                                                    final boolean masterCache,
                                                                                    final boolean bidirectional); @Override ToolkitNotifier<CacheConfigChangeNotificationMsg> getOrCreateConfigChangeNotifier(Ehcache cache); @Override ToolkitNotifier<CacheEventNotificationMsg> getOrCreateCacheEventNotifier(Ehcache cache); @Override ToolkitNotifier<CacheDisposalNotification> getOrCreateCacheDisposalNotifier(Ehcache cache); @Override String getFullyQualifiedCacheName(Ehcache cache); @Override ToolkitLock getOrCreateStoreLock(Ehcache cache); @Override ToolkitMap<String, AttributeExtractor> getOrCreateExtractorsMap(final String cacheManagerName, String cacheName); @Override ToolkitMap<String, String> getOrCreateAttributeMap(final String cacheManagerName, String cacheName); @Override void shutdown(); @Override SerializedToolkitCache<ClusteredSoftLockIDKey, SerializedReadCommittedClusteredSoftLock> getOrCreateAllSoftLockMap(String cacheManagerName,
                                                                                                                            String cacheName); @Override ToolkitMap<SerializedReadCommittedClusteredSoftLock, Integer> getOrCreateNewSoftLocksSet(String cacheManagerName,
                                                                                                  String cacheName); @Override ToolkitMap<String, AsyncConfig> getOrCreateAsyncConfigMap(); @Override ToolkitMap<String, Set<String>> getOrCreateAsyncListNamesMap(String fullAsyncName, String cacheName); @Override ToolkitListInternal getAsyncProcessingBucket(String bucketName, String cacheName); @Override ToolkitMap<String, Serializable> getOrCreateClusteredStoreConfigMap(String cacheManagerName, String cacheName); @Override SerializedToolkitCache<TransactionID, Decision> getOrCreateTransactionCommitStateMap(String cacheManagerName); @Override ToolkitLock getSoftLockWriteLock(String cacheManagerName, String cacheName, TransactionID transactionID,
                                          Object key); @Override ToolkitLock getLockForCache(Ehcache cache, String lockName); @Override ToolkitReadWriteLock getSoftLockFreezeLock(String cacheManagerName, String cacheName,
                                                    TransactionID transactionID, Object key); @Override ToolkitReadWriteLock getSoftLockNotifierLock(String cacheManagerName, String cacheName,
                                                      TransactionID transactionID, Object key); @Override boolean destroy(final String cacheManagerName, final String cacheName); @Override void removeNonStopConfigforCache(Ehcache cache); @Override void linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration); @Override ToolkitMap<String, Serializable> getOrCreateCacheManagerMetaInfoMap(String cacheManagerName); @Override void unlinkCache(String cacheName); @Override void clusterRejoined(); static final Logger LOGGER; static final String DELIMITER; static final int RETRY_MARK_IN_USE_AFTER_REJOIN; }