public class RemoteCacheManager extends Object implements RemoteCacheContainer
RemoteCaches. 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 |
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 |
|---|---|
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) |
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
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()
RemoteCacheContainergetProperties in interface RemoteCacheContainerpublic <K,V> RemoteCache<K,V> getCache(String cacheName)
getCache in interface BasicCacheContainercacheName - name of cache to retrievepublic <K,V> RemoteCache<K,V> getCache(String cacheName, boolean forceReturnValue)
getCache in interface RemoteCacheContainerpublic <K,V> RemoteCache<K,V> getCache()
getCache in interface BasicCacheContainerpublic <K,V> RemoteCache<K,V> getCache(boolean forceReturnValue)
getCache in interface RemoteCacheContainerpublic void start()
Lifecyclepublic void stop()
public boolean isStarted()
isStarted in interface RemoteCacheContainerpublic boolean switchToCluster(String clusterName)
RemoteCacheContainertrue, otherwise it returns false.switchToCluster in interface RemoteCacheContainerclusterName - name of the cluster to which to switch totrue if the cluster was switched, false otherwisepublic boolean switchToDefaultCluster()
RemoteCacheContainertrue, otherwise it returns false.switchToDefaultCluster in interface RemoteCacheContainertrue if the cluster was switched, false otherwiseprotected <K,V> NearCacheService<K,V> createNearCacheService(NearCacheConfiguration cfg)
public Marshaller getMarshaller()
getMarshaller in interface RemoteCacheContainerpublic static byte[] cacheNameBytes(String cacheName)
public static byte[] cacheNameBytes()
Copyright © 2017 JBoss, a division of Red Hat. All rights reserved.