public class RemoteCacheManager extends Object implements RemoteCacheContainer, Closeable, RemoteCacheManagerMXBean
Factory for RemoteCache
s.
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 |
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 . |
RemoteCacheManager(String uri)
Create a new RemoteCacheManager using the supplied URI.
|
RemoteCacheManager(URI uri)
Create a new RemoteCacheManager using the supplied URI.
|
Modifier and Type | Method and Description |
---|---|
RemoteCacheManagerAdmin |
administration()
Access to administration operations (cache creation, removal, etc)
|
static byte[] |
cacheNameBytes() |
static byte[] |
cacheNameBytes(String cacheName) |
void |
close()
See
stop() |
ChannelFactory |
createChannelFactory() |
protected <K,V> NearCacheService<K,V> |
createNearCacheService(NearCacheConfiguration cfg)
Deprecated.
since 10.0. To be removed in 12.0. Replaced by
#createNearCacheService(String,
NearCacheConfiguration) . |
protected <K,V> NearCacheService<K,V> |
createNearCacheService(String cacheName,
NearCacheConfiguration cfg) |
int |
getActiveConnectionCount()
Returns the number of active connections
|
ExecutorService |
getAsyncExecutorService() |
<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 all cache names.
|
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.
|
int |
getConnectionCount()
Returns the total number of connections
|
int |
getIdleConnectionCount()
Returns the number of idle connections
|
Marshaller |
getMarshaller() |
MarshallerRegistry |
getMarshallerRegistry() |
long |
getRetries()
Returns the total number of retries that have been executed
|
String[] |
getServers()
Returns a list of servers to which the client is currently connected in the format of ip_address:port_number.
|
XAResource |
getXaResource()
Returns the
XAResource which can be used to do transactional recovery. |
boolean |
isStarted() |
boolean |
isTransactional(String cacheName) |
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 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(String uri)
uri
- the URI to use for this RemoteCacheManagerpublic RemoteCacheManager(URI uri)
uri
- the URI 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 RemoteCacheContainer
public <K,V> RemoteCache<K,V> getCache(String cacheName)
getCache
in interface RemoteCacheContainer
getCache
in interface BasicCacheContainer
cacheName
- name of cache to retrieveBasicCacheContainer.getCache(String)
public Set<String> getCacheNames()
BasicCacheContainer
getCacheNames
in interface BasicCacheContainer
public <K,V> RemoteCache<K,V> getCache()
getCache
in interface RemoteCacheContainer
getCache
in interface BasicCacheContainer
BasicCacheContainer.getCache()
public <K,V> RemoteCache<K,V> getCache(String cacheName, TransactionMode transactionMode, TransactionManager transactionManager)
getCache
in interface RemoteCacheContainer
cacheName
- 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 RemoteCacheContainer
cacheName
- 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()
Lifecycle
public ChannelFactory createChannelFactory()
public boolean isTransactional(String cacheName)
isTransactional
in interface RemoteCacheContainer
true
if the cache with name cacheName
can participate in transactions.public MarshallerRegistry getMarshallerRegistry()
public void stop()
public boolean isStarted()
isStarted
in interface RemoteCacheContainer
public boolean switchToCluster(String clusterName)
RemoteCacheContainer
true
, otherwise it returns false
.switchToCluster
in interface RemoteCacheManagerMXBean
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 RemoteCacheManagerMXBean
switchToDefaultCluster
in interface RemoteCacheContainer
true
if the cluster was switched, false
otherwiseprotected <K,V> NearCacheService<K,V> createNearCacheService(String cacheName, NearCacheConfiguration cfg)
@Deprecated protected <K,V> NearCacheService<K,V> createNearCacheService(NearCacheConfiguration cfg)
#createNearCacheService(String,
NearCacheConfiguration)
.public Marshaller getMarshaller()
getMarshaller
in interface RemoteCacheContainer
public static byte[] cacheNameBytes(String cacheName)
public static byte[] cacheNameBytes()
public RemoteCacheManagerAdmin administration()
RemoteCacheManagerAdmin
which can perform administrative operations on the server.public void close()
stop()
close
in interface Closeable
close
in interface AutoCloseable
public Codec getCodec()
public ChannelFactory getChannelFactory()
public XAResource getXaResource()
XAResource
which can be used to do transactional recovery.XAResource
public String[] getServers()
RemoteCacheManagerMXBean
getServers
in interface RemoteCacheManagerMXBean
public int getActiveConnectionCount()
RemoteCacheManagerMXBean
getActiveConnectionCount
in interface RemoteCacheManagerMXBean
public int getConnectionCount()
RemoteCacheManagerMXBean
getConnectionCount
in interface RemoteCacheManagerMXBean
public int getIdleConnectionCount()
RemoteCacheManagerMXBean
getIdleConnectionCount
in interface RemoteCacheManagerMXBean
public long getRetries()
RemoteCacheManagerMXBean
getRetries
in interface RemoteCacheManagerMXBean
public ExecutorService getAsyncExecutorService()
Copyright © 2021 JBoss by Red Hat. All rights reserved.