public class HazelcastCacheManager extends Object implements org.apache.shiro.cache.CacheManager, org.apache.shiro.util.Initializable, org.apache.shiro.util.Destroyable
CacheManager implementation backed by Hazelcast,
"an open source clustering and highly scalable data distribution platform for Java"
This implementation interacts with a HazelcastInstance to
acquire named ConcurrentMap
instances. Those clustered/distributed Map instances are then wrapped and made available to CacheManager
callers as MapCache instances via getCache(String).
HazelcastInstance can be configured in one of three ways:
HazelcastInstanceConfig instance and using that to create a new HazelcastInstanceHazelcastCacheManager and do nothing further, its backing
HazelcastInstance instance will be created automatically by calling
Hazelcast.newHazelcastInstance(null).
The null argument instructs Hazelcast to use whatever default configuration mechanism it has at its disposal,
usually a hazelcast.xml file at the root of the classpath, or if that is not present, the
hazelcast-default.xml file contained in the Hazelcast .jar file itself.
HazelcastInstanceHazelcastInstance outside of Shiro's knowledge/control, you can simply configure it
to be used by calling setHazelcastInstance.
Config instancesetConfig(config). This config
instance will be used to acquire a new Hazelcast instance by calling
Hazelcast.newHazelcastInstance(config)| Modifier and Type | Field and Description |
|---|---|
static org.slf4j.Logger |
log |
| Constructor and Description |
|---|
HazelcastCacheManager() |
| Modifier and Type | Method and Description |
|---|---|
protected com.hazelcast.core.HazelcastInstance |
createHazelcastInstance()
Implicitly creates and returns a new
HazelcastInstance that will be used to back this implementation. |
void |
destroy()
Destroys any
implicitly created backing HazelcastInstance. |
protected com.hazelcast.core.HazelcastInstance |
ensureHazelcastInstance()
Ensures that this implementation has a backing
HazelcastInstance, and if not, implicitly creates one
via createHazelcastInstance(). |
<K,V> org.apache.shiro.cache.Cache<K,V> |
getCache(String name)
Returns a
MapCache instance representing the named Hazelcast-managed
IMap. |
com.hazelcast.config.Config |
getConfig()
Returns the Hazelcast
Config object to use to create a backing HazelcastInstance if one is not
supplied, or null if the
default Hazelcast configuration
mechanisms will be used. |
com.hazelcast.core.HazelcastInstance |
getHazelcastInstance()
Returns the
HazelcastInstance from which named ConcurrentMap
instances will be acquired to create MapCache instances. |
void |
init()
Initializes this instance by
ensuring there is a backing
HazelcastInstance. |
protected boolean |
isImplicitlyCreated()
NOT PART OF SHIRO'S ACCESSIBLE API.
|
void |
setConfig(com.hazelcast.config.Config config)
Sets the Hazelcast
Config object to use to create a backing HazelcastInstance if one is not
supplied. |
void |
setHazelcastInstance(com.hazelcast.core.HazelcastInstance hazelcastInstance)
Sets the
HazelcastInstance from which named ConcurrentMap
instances will be acquired to create MapCache instances. |
public <K,V> org.apache.shiro.cache.Cache<K,V> getCache(String name) throws org.apache.shiro.cache.CacheException
MapCache instance representing the named Hazelcast-managed
IMap. The Hazelcast Map is obtained by calling
hazelcastInstance.getMap(name).getCache in interface org.apache.shiro.cache.CacheManagerK - the type of map keyV - the type of map valuename - the name of the cache to acquire.MapCache instance representing the named Hazelcast-managed IMap.org.apache.shiro.cache.CacheExceptionHazelcastInstance.getMap(String),
ensureHazelcastInstance()protected com.hazelcast.core.HazelcastInstance ensureHazelcastInstance()
HazelcastInstance, and if not, implicitly creates one
via createHazelcastInstance().HazelcastInstance.createHazelcastInstance(),
HazelcastInstancepublic void init()
throws org.apache.shiro.ShiroException
ensuring there is a backing
HazelcastInstance.init in interface org.apache.shiro.util.Initializableorg.apache.shiro.ShiroExceptionensureHazelcastInstance(),
HazelcastInstanceprotected com.hazelcast.core.HazelcastInstance createHazelcastInstance()
HazelcastInstance that will be used to back this implementation.
This implementation calls:
return Hazelcast.newHazelcastInstance(this.config);using any
configured Config object. If no config
object has been specified, this.config will be null, thereby using Hazelcast's
default configuration mechanism.
Can be overridden by subclasses for custom creation behavior.HazelcastInstance that will be used to back this implementationHazelcast.newHazelcastInstance(com.hazelcast.config.Config),
Configprotected final boolean isImplicitlyCreated()
true if this HazelcastCacheManager instance implicitly created the backing
HazelcastInstance, or false if one was externally provided via
setHazelcastInstance.true if this HazelcastCacheManager instance implicitly created the backing
HazelcastInstance, or false if one was externally provided via
setHazelcastInstance.public void destroy()
throws Exception
implicitly created backing HazelcastInstance. If the
backing Hazelcast was not implicitly created (i.e. because it was configured externally and supplied via
setHazelcastInstance), this method does
nothing.destroy in interface org.apache.shiro.util.DestroyableException - if there is a problem shutting downpublic com.hazelcast.core.HazelcastInstance getHazelcastInstance()
HazelcastInstance from which named ConcurrentMap
instances will be acquired to create MapCache instances.HazelcastInstance from which named ConcurrentMap
instances will be acquired to create MapCache instances.public void setHazelcastInstance(com.hazelcast.core.HazelcastInstance hazelcastInstance)
HazelcastInstance from which named ConcurrentMap
instances will be acquired to create MapCache instances.hazelcastInstance - the HazelcastInstance from which named
ConcurrentMap instances will be acquired to create
MapCache instances.public com.hazelcast.config.Config getConfig()
Config object to use to create a backing HazelcastInstance if one is not
supplied, or null if the
default Hazelcast configuration
mechanisms will be used.Config object to use to create a backing HazelcastInstance if one is not
supplied, or null if the
default Hazelcast configuration
mechanisms will be used.Hazelcast.newHazelcastInstance(com.hazelcast.config.Config)public void setConfig(com.hazelcast.config.Config config)
Config object to use to create a backing HazelcastInstance if one is not
supplied. null can be set if the
default Hazelcast configuration
mechanisms will be used.config - the Hazelcast Config object to use to create a backing HazelcastInstance if one is not
supplied, or null if the
default Hazelcast configuration
mechanisms will be used.Copyright © 2004–2017 The Apache Software Foundation. All rights reserved.