class 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 (true) {
        if (cmWriteLock.tryLock()) {
          try {
            clusteredCacheManager = createClusteredCacheManagerEntity(cacheManagerName, configuration);
          } finally {
            cmWriteLock.unlock();
          }
        } else {
          clusteredCacheManager = clusteredEntityManager.getRootEntity(cacheManagerName, ClusteredCacheManager.class);
        }
        if (clusteredCacheManager != null) {
          break;
        }
      }
    }
    clusteredCacheManagerEntity = clusteredCacheManager;
    clusteredCacheManagerEntity.markInUse();
  }

  public  ToolkitInstanceFactoryImpl(TerracottaClientConfiguration terracottaClientConfiguration);
    ToolkitInstanceFactoryImpl(Toolkit toolkit, ClusteredEntityManager clusteredEntityManager);

}