com.atlassian.confluence.cache.hazelcast
Class AbstractHazelcastCacheManager<C extends ManagedLockingCache,R extends com.atlassian.cache.CachedReference>

java.lang.Object
  extended by com.atlassian.confluence.cache.CacheManagerSupport
      extended by com.atlassian.confluence.cache.hazelcast.AbstractHazelcastCacheManager<C,R>
All Implemented Interfaces:
com.atlassian.cache.CacheFactory, com.atlassian.cache.CacheManager, ManagedCacheSource<C>
Direct Known Subclasses:
HazelcastDistributedCacheManager, HazelcastHybridCacheManager

public abstract class AbstractHazelcastCacheManager<C extends ManagedLockingCache,R extends com.atlassian.cache.CachedReference>
extends CacheManagerSupport
implements ManagedCacheSource<C>

An abstract base class for CacheManager implementations that use Hazelcast. Concrete implementations need only implement methods to construct actual Cache and CachedReference objects.

Since:
5.6

Constructor Summary
AbstractHazelcastCacheManager(java.lang.Iterable<java.lang.String> nonFlushableCaches, CacheSettingsManager settingsManager, com.atlassian.util.concurrent.Supplier<com.hazelcast.core.HazelcastInstance> instanceSupplier)
           
 
Method Summary
protected  void assertCacheSettingsAreCompatible(java.lang.String cacheName, com.atlassian.cache.CacheSettings cacheSettings)
          Check that the given cache settings are compatible with this cache manager.
protected abstract  C createCache(java.lang.String cacheName, com.atlassian.cache.CacheLoader cacheLoader, com.atlassian.cache.CacheSettings settings, com.hazelcast.config.MapConfig mapConfig, com.hazelcast.core.IMap hazelcastMap)
           
protected abstract  R createCachedReference(java.lang.String cacheName, com.atlassian.cache.Supplier supplier, com.atlassian.cache.CacheSettings required, com.hazelcast.core.IMap hazelcastMap)
           
 void flushCaches()
           
protected  java.util.Map<java.lang.String,C> getAllCaches()
           
protected  java.util.Map<java.lang.String,C> getAllCaches(java.lang.String mapNamePrefix)
           
 C getCache(java.lang.String cacheName, com.atlassian.cache.CacheLoader loader, com.atlassian.cache.CacheSettings required)
           
protected  java.util.concurrent.locks.Lock getCacheCreationLock(java.lang.String cacheName)
          Return the Lock to be acquired when creating a cache.
 R getCachedReference(java.lang.String cacheName, com.atlassian.cache.Supplier supplier, com.atlassian.cache.CacheSettings required)
           
 java.util.Set<java.lang.String> getCacheNames()
           
 java.util.Collection<com.atlassian.cache.Cache<?,?>> getCaches()
           
 com.hazelcast.core.IMap getHazelcastMapForCache(ManagedLockingCache cache)
           
protected  java.lang.String getHazelcastMapNameForCache(java.lang.String cacheName)
           
protected  java.lang.String getHazelcastMapNameForCachedReference(java.lang.String cacheName)
           
 C getManagedCache(java.lang.String cacheName)
           
 java.util.Collection<com.atlassian.cache.ManagedCache> getManagedCaches()
           
protected  com.hazelcast.core.HazelcastInstance hazelcast()
           
protected  boolean isFlushable(java.lang.String cacheName)
           
protected  C lockAndCreateCache(java.lang.String cacheName, com.atlassian.cache.CacheLoader loader, com.atlassian.cache.CacheSettings required)
           
protected  R lockAndCreateCachedReference(java.lang.String cacheName, com.atlassian.cache.Supplier supplier, com.atlassian.cache.CacheSettings required)
           
 
Methods inherited from class com.atlassian.confluence.cache.CacheManagerSupport
buildMergedCacheSettings, getCache, getCache, getCache, getCache, getCachedReference, getCachedReference, getCachedReference, isLocalCache, isReplicatedCache, toName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractHazelcastCacheManager

public AbstractHazelcastCacheManager(java.lang.Iterable<java.lang.String> nonFlushableCaches,
                                     CacheSettingsManager settingsManager,
                                     com.atlassian.util.concurrent.Supplier<com.hazelcast.core.HazelcastInstance> instanceSupplier)
Method Detail

getCache

public C getCache(java.lang.String cacheName,
                  com.atlassian.cache.CacheLoader loader,
                  com.atlassian.cache.CacheSettings required)
Specified by:
getCache in interface com.atlassian.cache.CacheFactory
Specified by:
getCache in class CacheManagerSupport

getCachedReference

public R getCachedReference(java.lang.String cacheName,
                            com.atlassian.cache.Supplier supplier,
                            com.atlassian.cache.CacheSettings required)
Specified by:
getCachedReference in interface com.atlassian.cache.CacheFactory
Specified by:
getCachedReference in class CacheManagerSupport

getAllCaches

protected java.util.Map<java.lang.String,C> getAllCaches()

getAllCaches

protected java.util.Map<java.lang.String,C> getAllCaches(java.lang.String mapNamePrefix)

isFlushable

protected boolean isFlushable(java.lang.String cacheName)

flushCaches

public void flushCaches()
Specified by:
flushCaches in interface com.atlassian.cache.CacheManager

getCacheCreationLock

protected java.util.concurrent.locks.Lock getCacheCreationLock(java.lang.String cacheName)
Return the Lock to be acquired when creating a cache.

Parameters:
cacheName - the name of the cache to be created
Returns:
the lock that needs to be acquired/released around creating a cache

hazelcast

protected com.hazelcast.core.HazelcastInstance hazelcast()

lockAndCreateCachedReference

protected R lockAndCreateCachedReference(java.lang.String cacheName,
                                         com.atlassian.cache.Supplier supplier,
                                         com.atlassian.cache.CacheSettings required)

lockAndCreateCache

protected C lockAndCreateCache(java.lang.String cacheName,
                               com.atlassian.cache.CacheLoader loader,
                               com.atlassian.cache.CacheSettings required)

assertCacheSettingsAreCompatible

protected void assertCacheSettingsAreCompatible(java.lang.String cacheName,
                                                com.atlassian.cache.CacheSettings cacheSettings)
Check that the given cache settings are compatible with this cache manager. Subclasses should override this as they see fit, to provide additional constraints. They must still call this method via super.

Throws:
java.lang.IllegalArgumentException - if the cache settings are not compatible

getHazelcastMapNameForCache

protected java.lang.String getHazelcastMapNameForCache(java.lang.String cacheName)

getHazelcastMapNameForCachedReference

protected java.lang.String getHazelcastMapNameForCachedReference(java.lang.String cacheName)

getHazelcastMapForCache

public com.hazelcast.core.IMap getHazelcastMapForCache(ManagedLockingCache cache)

getCaches

public java.util.Collection<com.atlassian.cache.Cache<?,?>> getCaches()
Specified by:
getCaches in interface com.atlassian.cache.CacheManager

getManagedCaches

public java.util.Collection<com.atlassian.cache.ManagedCache> getManagedCaches()
Specified by:
getManagedCaches in interface com.atlassian.cache.CacheManager

getCacheNames

public java.util.Set<java.lang.String> getCacheNames()
Specified by:
getCacheNames in interface ManagedCacheSource<C extends ManagedLockingCache>

getManagedCache

public C getManagedCache(@NotNull
                         java.lang.String cacheName)
Specified by:
getManagedCache in interface com.atlassian.cache.CacheManager
Specified by:
getManagedCache in interface ManagedCacheSource<C extends ManagedLockingCache>

createCache

protected abstract C createCache(java.lang.String cacheName,
                                 com.atlassian.cache.CacheLoader cacheLoader,
                                 com.atlassian.cache.CacheSettings settings,
                                 com.hazelcast.config.MapConfig mapConfig,
                                 com.hazelcast.core.IMap hazelcastMap)

createCachedReference

protected abstract R createCachedReference(java.lang.String cacheName,
                                           com.atlassian.cache.Supplier supplier,
                                           com.atlassian.cache.CacheSettings required,
                                           com.hazelcast.core.IMap hazelcastMap)


Copyright © 2003-2014 Atlassian. All Rights Reserved.