public class RemoteCacheManager extends Object implements RemoteCacheContainer, Closeable
Factory for RemoteCaches.
In order to be able to use a RemoteCache, the
RemoteCacheManager must be started first: this instantiates connections to
Hot Rod server(s). Starting the RemoteCacheManager can be done either at
creation by passing start==true to the constructor or by using a constructor that does that for you; or after
construction by calling start().
NOTE: 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 |
|---|---|
protected ChannelFactory |
channelFactory |
static String |
DEFAULT_CACHE_NAME |
static String |
HOTROD_CLIENT_PROPERTIES |
static String |
JSON_STRING_ARRAY_ELEMENT_REGEX |
protected ClientListenerNotifier |
listenerNotifier |
| Constructor and Description |
|---|
RemoteCacheManager()
Same as
RemoteCacheManager(boolean) and it also starts the cache. |
RemoteCacheManager(boolean start)
Similar to
RemoteCacheManager(Configuration, boolean), 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) |
void |
close() |
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(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,
TransactionMode transactionMode,
TransactionManager transactionManager) |
<K,V> RemoteCache<K,V> |
getCache(String cacheName,
TransactionMode transactionMode,
TransactionManager transactionManager) |
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.
|
ChannelFactory |
getChannelFactory()
This method is not a part of the public API.
|
Codec |
getCodec()
This method is not a part of the public API.
|
Configuration |
getConfiguration()
Retrieves the configuration currently in use.
|
Marshaller |
getMarshaller() |
MarshallerRegistry |
getMarshallerRegistry() |
boolean |
isStarted() |
void |
start()
Invoked on component start
|
CompletableFuture<Void> |
startAsync() |
void |
stop()
Stop the remote cache manager, disconnecting all existing connections.
|
CompletableFuture<Void> |
stopAsync() |
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 ChannelFactory channelFactory
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)
Similar to RemoteCacheManager(Configuration, boolean), 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, defaults will be used, attempting to connect to 127.0.0.1:11222
Refer to
ConfigurationBuilder for a detailed list of available properties.
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 RemoteCacheContainerpublic <K,V> RemoteCache<K,V> getCache(String cacheName)
getCache in interface BasicCacheContainercacheName - name of cache to retrievepublic Set<String> getCacheNames()
BasicCacheContainerInternalCacheRegistrygetCacheNames in interface BasicCacheContainerpublic <K,V> RemoteCache<K,V> getCache()
getCache in interface BasicCacheContainerpublic <K,V> RemoteCache<K,V> getCache(String cacheName, TransactionMode transactionMode, TransactionManager transactionManager)
getCache in interface RemoteCacheContainercacheName - The cache's name.transactionMode - The TransactionMode to override. If null, it uses the configured value.transactionManager - The TransactionManager to override. If null, it uses the configured value.RemoteCache implementation.public <K,V> RemoteCache<K,V> getCache(String cacheName, boolean forceReturnValue, TransactionMode transactionMode, TransactionManager transactionManager)
getCache in interface RemoteCacheContainercacheName - The cache's name.forceReturnValue - true to force a return value when it is not needed.transactionMode - The TransactionMode to override. If null, it uses the configured value.transactionManager - The TransactionManager to override. If null, it uses the configured
value.RemoteCache implementation.public CompletableFuture<Void> startAsync()
public CompletableFuture<Void> stopAsync()
public void start()
Lifecyclepublic MarshallerRegistry getMarshallerRegistry()
public 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()
public RemoteCacheManagerAdmin administration()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic Codec getCodec()
public ChannelFactory getChannelFactory()
Copyright © 2020 JBoss, a division of Red Hat. All rights reserved.