@Test public void testCreatingNewClusteredCacheManagerEntity() { String name = "newCM"; net.sf.ehcache.config.Configuration configuration = new net.sf.ehcache.config.Configuration(); ClusteredEntityManager clusteredEntityManager = mock(ClusteredEntityManager.class); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocationOnMock) throws Throwable { Object[] arguments = invocationOnMock.getArguments(); ((ToolkitBackedClusteredCacheManager)arguments[2]).setEntityLockHandler(mock(EntityLockHandler.class)); return null; } }).when(clusteredEntityManager).addRootEntityIfAbsent(eq(name), eq(ClusteredCacheManager.class), any(ClusteredCacheManager.class)); ToolkitReadWriteLock rwLock = mock(ToolkitReadWriteLock.class); ToolkitLock writeLock = mock(ToolkitLock.class); when(writeLock.tryLock()).thenReturn(true); when(rwLock.writeLock()).thenReturn(writeLock); when(clusteredEntityManager.getEntityLock(any(String.class))).thenReturn(rwLock); ToolkitInstanceFactoryImpl toolkitInstanceFactory = new ToolkitInstanceFactoryImpl(getMockToolkit(), clusteredEntityManager); toolkitInstanceFactory.linkClusteredCacheManager(name, configuration); verify(clusteredEntityManager).getRootEntity(name, ClusteredCacheManager.class); verify(clusteredEntityManager).getEntityLock(EhcacheEntitiesNaming.getCacheManagerLockNameFor(name)); verify(clusteredEntityManager).addRootEntityIfAbsent(eq(name), any(Class.class), any(ClusteredCacheManager.class)); verifyNoMoreInteractions(clusteredEntityManager); }
@Override public void linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration) { if (clusteredCacheManagerEntity == null) { logCacheManagerConfigInTerracottaClientLogs(cacheManagerName, configuration); ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); ToolkitReadWriteLock cmRWLock = clusteredEntityManager.getEntityLock(EhcacheEntitiesNaming .getCacheManagerLockNameFor(cacheManagerName)); ToolkitLock cmWriteLock = cmRWLock.writeLock(); while (clusteredCacheManager == null) { if (cmWriteLock.tryLock()) { try { clusteredCacheManager = createClusteredCacheManagerEntity(cacheManagerName, configuration); } finally { cmWriteLock.unlock(); } } else { clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); } } clusteredCacheManagerEntity = clusteredCacheManager; entityNames.setCacheManagerName(cacheManagerName); } }
ToolkitInstanceFactoryImpl implements ToolkitInstanceFactory { @Override public void linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration) { if (clusteredCacheManagerEntity == null) { logCacheManagerConfigInTerracottaClientLogs(cacheManagerName, configuration); ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); ToolkitReadWriteLock cmRWLock = clusteredEntityManager.getEntityLock(EhcacheEntitiesNaming .getCacheManagerLockNameFor(cacheManagerName)); ToolkitLock cmWriteLock = cmRWLock.writeLock(); while (clusteredCacheManager == null) { if (cmWriteLock.tryLock()) { try { clusteredCacheManager = createClusteredCacheManagerEntity(cacheManagerName, configuration); } finally { cmWriteLock.unlock(); } } else { clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); } } clusteredCacheManagerEntity = clusteredCacheManager; entityNames.setCacheManagerName(cacheManagerName); } } }
ToolkitInstanceFactoryImpl implements ToolkitInstanceFactory { @Override public void linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration) { if (clusteredCacheManagerEntity == null) { logCacheManagerConfigInTerracottaClientLogs(cacheManagerName, configuration); ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); ToolkitReadWriteLock cmRWLock = clusteredEntityManager.getEntityLock(EhcacheEntitiesNaming .getCacheManagerLockNameFor(cacheManagerName)); ToolkitLock cmWriteLock = cmRWLock.writeLock(); while (clusteredCacheManager == null) { if (cmWriteLock.tryLock()) { try { clusteredCacheManager = createClusteredCacheManagerEntity(cacheManagerName, configuration); } finally { cmWriteLock.unlock(); } } else { clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); } } clusteredCacheManagerEntity = clusteredCacheManager; entityNames.setCacheManagerName(cacheManagerName); } } 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 linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration) { if (clusteredCacheManagerEntity == null) { logCacheManagerConfigInTerracottaClientLogs(cacheManagerName, configuration); ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); ToolkitReadWriteLock cmRWLock = clusteredEntityManager.getEntityLock(EhcacheEntitiesNaming .getCacheManagerLockNameFor(cacheManagerName)); ToolkitLock cmWriteLock = cmRWLock.writeLock(); while (clusteredCacheManager == null) { if (cmWriteLock.tryLock()) { try { clusteredCacheManager = createClusteredCacheManagerEntity(cacheManagerName, configuration); } finally { cmWriteLock.unlock(); } } else { clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); } } clusteredCacheManagerEntity = clusteredCacheManager; entityNames.setCacheManagerName(cacheManagerName); } } 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 linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration) { if (clusteredCacheManagerEntity == null) { logCacheManagerConfigInTerracottaClientLogs(cacheManagerName, configuration); ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); ToolkitReadWriteLock cmRWLock = clusteredEntityManager.getEntityLock(EhcacheEntitiesNaming .getCacheManagerLockNameFor(cacheManagerName)); ToolkitLock cmWriteLock = cmRWLock.writeLock(); while (clusteredCacheManager == null) { if (cmWriteLock.tryLock()) { try { clusteredCacheManager = createClusteredCacheManagerEntity(cacheManagerName, configuration); } finally { cmWriteLock.unlock(); } } else { clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); } } clusteredCacheManagerEntity = clusteredCacheManager; entityNames.setCacheManagerName(cacheManagerName); } } 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; }