public class RemoteCacheManager extends Object implements RemoteCacheContainer
RemoteCache
s. Lifecycle:
In order to be able to use anRemoteCache
, the RemoteCacheManager
must be started first: beside other things, this instantiates connections to Hot Rod server(s). Starting the RemoteCacheManager
can be done either at creation by passing start==true to constructor
or by using a constructor that does that for you (see C-tor documentation); or after construction by calling start()
.
This is an "expensive" object, as it manages a set of persistent TCP connections to the Hot Rod servers. It is recommended
to only have one instance of this per JVM, and to cache it between calls to the server (i.e. remoteCache
operations).
stop()
needs to be called explicitly in order to release all the resources (e.g. threads, TCP connections).
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CACHE_NAME |
static String |
HOTROD_CLIENT_PROPERTIES |
static String |
JSON_STRING_ARRAY_ELEMENT_REGEX |
protected ClientListenerNotifier |
listenerNotifier |
protected TransportFactory |
transportFactory |
Constructor and Description |
---|
RemoteCacheManager()
Same as
RemoteCacheManager(boolean) and it also starts the cache. |
RemoteCacheManager(boolean start)
Same as
RemoteCacheManager(java.util.Properties) , but it will try to lookup the config properties in the
classpath, in a file named hotrod-client.properties. |
RemoteCacheManager(Configuration configuration)
Create a new RemoteCacheManager using the supplied
Configuration . |
RemoteCacheManager(Configuration configuration,
boolean start)
Create a new RemoteCacheManager using the supplied
Configuration . |
Modifier and Type | Method and Description |
---|---|
RemoteCacheManagerAdmin |
administration() |
static byte[] |
cacheNameBytes() |
static byte[] |
cacheNameBytes(String cacheName) |
protected <K,V> NearCacheService<K,V> |
createNearCacheService(NearCacheConfiguration cfg) |
<K,V> RemoteCache<K,V> |
getCache()
Retrieves the default cache from the remote server.
|
<K,V> RemoteCache<K,V> |
getCache(boolean forceReturnValue) |
<K,V> RemoteCache<K,V> |
getCache(String cacheName)
Retrieves a named cache from the remote server if the cache has been defined, otherwise if the cache name is
undefined, it will return null.
|
<K,V> RemoteCache<K,V> |
getCache(String cacheName,
boolean forceReturnValue) |
Set<String> |
getCacheNames()
This method returns a collection of caches names which contains the
caches that have been defined via XML or programmatically, and the
caches that have been created at runtime via this cache manager
instance.
|
Configuration |
getConfiguration()
Retrieves the configuration currently in use.
|
Marshaller |
getMarshaller() |
Properties |
getProperties()
Deprecated.
|
boolean |
isStarted() |
void |
start()
Invoked on component start
|
void |
stop()
Stop the remote cache manager, disconnecting all existing connections.
|
boolean |
switchToCluster(String clusterName)
Switch remote cache manager to a different cluster, previously
declared via configuration.
|
boolean |
switchToDefaultCluster()
Switch remote cache manager to a the default cluster, previously
declared via configuration.
|
public static final String DEFAULT_CACHE_NAME
public static final String HOTROD_CLIENT_PROPERTIES
public static final String JSON_STRING_ARRAY_ELEMENT_REGEX
protected TransportFactory transportFactory
protected ClientListenerNotifier listenerNotifier
public RemoteCacheManager(Configuration configuration)
Configuration
.
The RemoteCacheManager will be started automaticallyconfiguration
- the configuration to use for this RemoteCacheManagerpublic RemoteCacheManager(Configuration configuration, boolean start)
Configuration
.
The RemoteCacheManager will be started automatically only if the start parameter is trueconfiguration
- the configuration to use for this RemoteCacheManagerstart
- whether or not to start the manager on return from the constructor.public RemoteCacheManager(boolean start)
RemoteCacheManager(java.util.Properties)
, but it will try to lookup the config properties in the
classpath, in a file named hotrod-client.properties. If no properties can be found in the classpath, the
server tries to connect to "127.0.0.1:11222" in start.start
- whether or not to start the RemoteCacheManagerHotRodClientException
- if such a file cannot be found in the classpathpublic RemoteCacheManager()
RemoteCacheManager(boolean)
and it also starts the cache.public Configuration getConfiguration()
RemoteCacheContainer
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.read(remoteCacheManager.getConfiguration());
// modify builder
remoteCacheManager.stop();
remoteCacheManager = new RemoteCacheManager(builder.build());
getConfiguration
in interface RemoteCacheContainer
@Deprecated public Properties getProperties()
RemoteCacheContainer
getProperties
in interface RemoteCacheContainer
public <K,V> RemoteCache<K,V> getCache(String cacheName)
getCache
in interface BasicCacheContainer
cacheName
- name of cache to retrievepublic Set<String> getCacheNames()
BasicCacheContainer
InternalCacheRegistry
getCacheNames
in interface BasicCacheContainer
public <K,V> RemoteCache<K,V> getCache(String cacheName, boolean forceReturnValue)
getCache
in interface RemoteCacheContainer
public <K,V> RemoteCache<K,V> getCache()
getCache
in interface BasicCacheContainer
public <K,V> RemoteCache<K,V> getCache(boolean forceReturnValue)
getCache
in interface RemoteCacheContainer
public void start()
Lifecycle
public void stop()
public boolean isStarted()
isStarted
in interface RemoteCacheContainer
public boolean switchToCluster(String clusterName)
RemoteCacheContainer
true
, otherwise it returns false
.switchToCluster
in interface RemoteCacheContainer
clusterName
- name of the cluster to which to switch totrue
if the cluster was switched, false
otherwisepublic boolean switchToDefaultCluster()
RemoteCacheContainer
true
, otherwise it returns false
.switchToDefaultCluster
in interface RemoteCacheContainer
true
if the cluster was switched, false
otherwiseprotected <K,V> NearCacheService<K,V> createNearCacheService(NearCacheConfiguration cfg)
public Marshaller getMarshaller()
getMarshaller
in interface RemoteCacheContainer
public static byte[] cacheNameBytes(String cacheName)
public static byte[] cacheNameBytes()
public RemoteCacheManagerAdmin administration()
Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.