@Test public void testRetrievingExistingClusteredCacheManagerEntity() { String name = "existing"; net.sf.ehcache.config.Configuration configuration = new net.sf.ehcache.config.Configuration(); Toolkit toolkit = mock(Toolkit.class); when(toolkit.getMap(anyString(), eq(String.class), eq(ClusteredCache.class))).thenReturn(mock(ToolkitMap.class)); ClusteredEntityManager clusteredEntityManager = mock(ClusteredEntityManager.class); ToolkitBackedClusteredCacheManager cacheManagerEntity = new ToolkitBackedClusteredCacheManager(name, new ClusteredCacheManagerConfiguration("test")); cacheManagerEntity.setEntityLockHandler(mock(EntityLockHandler.class)); when(clusteredEntityManager.getRootEntity(name, ClusteredCacheManager.class)) .thenReturn(cacheManagerEntity); ToolkitInstanceFactoryImpl toolkitInstanceFactory = new ToolkitInstanceFactoryImpl(mock(Toolkit.class), clusteredEntityManager); toolkitInstanceFactory.linkClusteredCacheManager(name, configuration); verify(clusteredEntityManager).getRootEntity(name, ClusteredCacheManager.class); verifyNoMoreInteractions(clusteredEntityManager); }
@Override public void linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration) { ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); if (clusteredCacheManager == null) { 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; clusteredCacheManagerEntity.markInUse(); }
ToolkitInstanceFactoryImpl implements ToolkitInstanceFactory { @Override public void linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration) { ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); if (clusteredCacheManager == null) { 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; clusteredCacheManagerEntity.markInUse(); } }
ToolkitInstanceFactoryImpl implements ToolkitInstanceFactory { @Override public void linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration) { ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); if (clusteredCacheManager == null) { 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; clusteredCacheManagerEntity.markInUse(); } ToolkitInstanceFactoryImpl(TerracottaClientConfiguration terracottaClientConfiguration);   ToolkitInstanceFactoryImpl(Toolkit toolkit, ClusteredEntityManager clusteredEntityManager); }
ToolkitInstanceFactoryImpl implements ToolkitInstanceFactory { @Override public void linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration) { ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); if (clusteredCacheManager == null) { 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; clusteredCacheManagerEntity.markInUse(); } ToolkitInstanceFactoryImpl(TerracottaClientConfiguration terracottaClientConfiguration);   ToolkitInstanceFactoryImpl(Toolkit toolkit, ClusteredEntityManager clusteredEntityManager); @Override void waitForOrchestrator(String cacheManagerName); @Override void markCacheWanDisabled(String cacheManagerName, String cacheName); @Override Toolkit getToolkit(); @Override ToolkitCacheInternal<String, Serializable> getOrCreateToolkitCache(final Ehcache cache); @Override ToolkitCacheInternal<String, Serializable> getOrCreateWanAwareToolkitCache(final String cacheManagerName,
                                                                                    final String cacheName,
                                                                                    final CacheConfiguration ehcacheConfig); @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(Ehcache cache); @Override ToolkitMap<String, String> getOrCreateAttributeMap(Ehcache cache); @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); @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 void unlinkCache(String cacheName); }
ToolkitInstanceFactoryImpl implements ToolkitInstanceFactory { @Override public void linkClusteredCacheManager(String cacheManagerName, net.sf.ehcache.config.Configuration configuration) { ClusteredCacheManager clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class); if (clusteredCacheManager == null) { 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; clusteredCacheManagerEntity.markInUse(); } ToolkitInstanceFactoryImpl(TerracottaClientConfiguration terracottaClientConfiguration);   ToolkitInstanceFactoryImpl(Toolkit toolkit, ClusteredEntityManager clusteredEntityManager); @Override void waitForOrchestrator(String cacheManagerName); @Override void markCacheWanDisabled(String cacheManagerName, String cacheName); @Override Toolkit getToolkit(); @Override ToolkitCacheInternal<String, Serializable> getOrCreateToolkitCache(final Ehcache cache); @Override ToolkitCacheInternal<String, Serializable> getOrCreateWanAwareToolkitCache(final String cacheManagerName,
                                                                                    final String cacheName,
                                                                                    final CacheConfiguration ehcacheConfig); @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(Ehcache cache); @Override ToolkitMap<String, String> getOrCreateAttributeMap(Ehcache cache); @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); @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 void unlinkCache(String cacheName); static final String DELIMITER; }