class ToolkitInstanceFactoryImpl implements ToolkitInstanceFactory {

  void addCacheEntityInfo(final String cacheName, final CacheConfiguration ehcacheConfig, String toolkitCacheName) {
    if (clusteredCacheManagerEntity == null) {
      throw new IllegalStateException(format("ClusteredCacheManger entity not configured for cache %s", cacheName));
    }
    ClusteredCache cacheEntity = clusteredCacheManagerEntity.getCache(cacheName);
    if (cacheEntity == null) {
      ToolkitReadWriteLock cacheRWLock = clusteredCacheManagerEntity.getCacheLock(cacheName);
      ToolkitLock cacheWriteLock = cacheRWLock.writeLock();
      while (cacheEntity == null) {
        if (cacheWriteLock.tryLock()) {
          try {
            cacheEntity = createClusteredCacheEntity(cacheName, ehcacheConfig, toolkitCacheName);
          } finally {
            cacheWriteLock.unlock();
          }
        } else {
          cacheEntity = clusteredCacheManagerEntity.getCache(cacheName);
        }
      }
    }
    // TODO check some config elements
    clusteredCacheManagerEntity.markCacheInUse(cacheEntity);
    entityNames.addCacheName(cacheName);
  }

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

}