Exemple #1
0
 @Override
 public void close() {
   flush();
   cacheEntryList.clear();
   if (!cache.isDestroyed() && !manager.isClosed()) {
     cache.close();
   }
   if (!manager.isClosed()) {
     manager.close();
   }
   hazelcastInstance.shutdown();
   persistentDataStore.close();
   LOG.info("JCache Gora datastore destroyed successfully.");
 }
  @Override
  public CacheManager getCacheManager(URI uri, ClassLoader classLoader, Properties properties) {
    URI globalUri = uri == null ? getDefaultURI() : uri;
    ClassLoader globalClassLoader = classLoader == null ? getDefaultClassLoader() : classLoader;
    Properties globalProperties = properties == null ? new Properties() : properties;

    synchronized (cacheManagers) {
      Map<URI, CacheManager> map = cacheManagers.get(globalClassLoader);
      if (map == null) {
        if (trace) log.tracef("No cache managers registered under '%s'", globalUri);

        map = new HashMap<URI, CacheManager>();
        cacheManagers.put(globalClassLoader, map);
      }

      CacheManager cacheManager = map.get(globalUri);
      if (cacheManager == null || cacheManager.isClosed()) {
        // Not found or stopped, create cache manager and add to collection
        cacheManager = createCacheManager(globalClassLoader, globalUri, globalProperties);
        if (trace) log.tracef("Created '%s' cache manager", globalUri);

        map.put(globalUri, cacheManager);
      }

      return cacheManager;
    }
  }