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, HazelcastHelper
Direct Known Subclasses:
HazelcastDistributedCacheManager, HazelcastHybridCacheManager

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

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.
 com.hazelcast.config.MapConfig configureHazelcastMap(java.lang.String cacheName, java.lang.String mapName, com.atlassian.cache.CacheSettings settings)
          Configures hazelcast map config accordingly to given cache settings
protected abstract  C createCache(java.lang.String cacheName, com.atlassian.cache.CacheLoader cacheLoader, com.atlassian.cache.CacheSettings settings, com.hazelcast.map.MapContainer mapContainer, 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.Collection<com.atlassian.cache.Cache<?,?>> getCaches()
           
 com.hazelcast.core.IMap getHazelcastMapForCache(java.lang.String cacheName)
           
 com.hazelcast.core.IMap getHazelcastMapForCachedReference(java.lang.String cacheName)
           
 java.lang.String getHazelcastMapNameForCache(java.lang.String cacheName)
           
 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.map.MapContainer getMapContainerForMap(java.lang.String mapName)
          Retrieves MapContainer to which is bind ot given map Using map container is needed for runtime cache settings change because update mapconfig from actual hazelcast is not used after instance has been start.
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<R> 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

getMapContainerForMap

protected com.hazelcast.map.MapContainer getMapContainerForMap(java.lang.String mapName)
Retrieves MapContainer to which is bind ot given map Using map container is needed for runtime cache settings change because update mapconfig from actual hazelcast is not used after instance has been start. It's likely to break with upgrade with hz upgrades, however we have good unit/acceptance test coverage for this.


configureHazelcastMap

public com.hazelcast.config.MapConfig configureHazelcastMap(java.lang.String cacheName,
                                                            java.lang.String mapName,
                                                            com.atlassian.cache.CacheSettings settings)
Configures hazelcast map config accordingly to given cache settings

Specified by:
configureHazelcastMap in interface HazelcastHelper
Returns:
MapConfig applied to hazelcast instance and map container

hazelcast

protected com.hazelcast.core.HazelcastInstance hazelcast()

lockAndCreateCachedReference

protected R lockAndCreateCachedReference(java.lang.String cacheName,
                                         com.atlassian.cache.Supplier<R> 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

public java.lang.String getHazelcastMapNameForCache(java.lang.String cacheName)
Specified by:
getHazelcastMapNameForCache in interface HazelcastHelper

getHazelcastMapNameForCachedReference

public java.lang.String getHazelcastMapNameForCachedReference(java.lang.String cacheName)
Specified by:
getHazelcastMapNameForCachedReference in interface HazelcastHelper

getHazelcastMapForCache

public com.hazelcast.core.IMap getHazelcastMapForCache(java.lang.String cacheName)
Specified by:
getHazelcastMapForCache in interface HazelcastHelper

getHazelcastMapForCachedReference

public com.hazelcast.core.IMap getHazelcastMapForCachedReference(java.lang.String cacheName)
Specified by:
getHazelcastMapForCachedReference in interface HazelcastHelper

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

getManagedCache

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

createCache

protected abstract C createCache(java.lang.String cacheName,
                                 com.atlassian.cache.CacheLoader cacheLoader,
                                 com.atlassian.cache.CacheSettings settings,
                                 com.hazelcast.map.MapContainer mapContainer,
                                 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.