Class RemoteCacheManager
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.infinispan.client.hotrod.jmx.RemoteCacheManagerMXBean
,RemoteCacheContainer
,BasicCacheContainer
,Lifecycle
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).
- Since:
- 4.1
- Author:
- Mircea.Markus@jboss.com
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSame asRemoteCacheManager(boolean)
and it also starts the cache.RemoteCacheManager
(boolean start) Similar toRemoteCacheManager(Configuration, boolean)
, but it will try to lookup the config properties in the classpath, in a file named hotrod-client.properties.RemoteCacheManager
(String uri) Create a new RemoteCacheManager using the supplied URI.RemoteCacheManager
(URI uri) Create a new RemoteCacheManager using the supplied URI.RemoteCacheManager
(Configuration configuration) Create a new RemoteCacheManager using the suppliedConfiguration
.RemoteCacheManager
(Configuration configuration, boolean start) Create a new RemoteCacheManager using the suppliedConfiguration
. -
Method Summary
Modifier and TypeMethodDescriptionAccess to administration operations (cache creation, removal, etc)static byte[]
static byte[]
cacheNameBytes
(String cacheName) void
close()
Seestop()
org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory
protected <K,
V> org.infinispan.client.hotrod.near.NearCacheService<K, V> createNearCacheService
(String cacheName, NearCacheConfiguration cfg) int
<K,
V> RemoteCache<K, V> getCache()
Retrieves the default cache from the remote server.<K,
V> RemoteCache<K, V> 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) This method returns a collection of all cache names.org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory
This method is not a part of the public API.org.infinispan.client.hotrod.impl.protocol.Codec
getCodec()
This method is not a part of the public API.Retrieves the configuration currently in use.int
int
org.infinispan.client.hotrod.impl.MarshallerRegistry
long
String[]
Returns theXAResource
which can be used to do transactional recovery.boolean
boolean
isTransactional
(String cacheName) void
start()
Invoked on component startvoid
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
Switch remote cache manager to a the default cluster, previously declared via configuration.
-
Field Details
-
HOTROD_CLIENT_PROPERTIES
- See Also:
-
JSON_STRING_ARRAY_ELEMENT_REGEX
- See Also:
-
channelFactory
protected org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory channelFactory -
listenerNotifier
protected org.infinispan.client.hotrod.event.impl.ClientListenerNotifier listenerNotifier
-
-
Constructor Details
-
RemoteCacheManager
Create a new RemoteCacheManager using the suppliedConfiguration
. The RemoteCacheManager will be started automatically- Parameters:
configuration
- the configuration to use for this RemoteCacheManager- Since:
- 5.3
-
RemoteCacheManager
Create a new RemoteCacheManager using the supplied URI. The RemoteCacheManager will be started automatically- Parameters:
uri
- the URI to use for this RemoteCacheManager- Since:
- 11.0
-
RemoteCacheManager
Create a new RemoteCacheManager using the supplied URI. The RemoteCacheManager will be started automatically- Parameters:
uri
- the URI to use for this RemoteCacheManager- Since:
- 11.0
-
RemoteCacheManager
Create a new RemoteCacheManager using the suppliedConfiguration
. The RemoteCacheManager will be started automatically only if the start parameter is true- Parameters:
configuration
- the configuration to use for this RemoteCacheManagerstart
- whether or not to start the manager on return from the constructor.- Since:
- 5.3
-
RemoteCacheManager
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:11222Refer to
ConfigurationBuilder
for a detailed list of available properties.- Parameters:
start
- whether or not to start the RemoteCacheManager- Throws:
HotRodClientException
- if such a file cannot be found in the classpath
-
RemoteCacheManager
public RemoteCacheManager()Same asRemoteCacheManager(boolean)
and it also starts the cache.
-
-
Method Details
-
getConfiguration
Description copied from interface:RemoteCacheContainer
Retrieves the configuration currently in use. The configuration object is immutable. If you wish to change configuration, you should use the following pattern:ConfigurationBuilder builder = new ConfigurationBuilder(); builder.read(remoteCacheManager.getConfiguration()); // modify builder remoteCacheManager.stop(); remoteCacheManager = new RemoteCacheManager(builder.build());
- Specified by:
getConfiguration
in interfaceRemoteCacheContainer
- Returns:
- The configuration of this RemoteCacheManager
- Since:
- 5.3
-
getCache
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.- Specified by:
getCache
in interfaceBasicCacheContainer
- Specified by:
getCache
in interfaceRemoteCacheContainer
- Parameters:
cacheName
- name of cache to retrieve- Returns:
- a cache instance identified by cacheName or null if the cache name has not been defined
- See Also:
-
getCacheNames
Description copied from interface:BasicCacheContainer
This method returns a collection of all cache names. The configurations may have been defined via XML, in the programmatic configuration, or at runtime. Internal-only caches are not included.- Specified by:
getCacheNames
in interfaceBasicCacheContainer
- Returns:
- an immutable set of cache names registered in this cache manager.
-
getCache
Retrieves the default cache from the remote server.- Specified by:
getCache
in interfaceBasicCacheContainer
- Specified by:
getCache
in interfaceRemoteCacheContainer
- Returns:
- a remote cache instance that can be used to send requests to the default cache in the server
- See Also:
-
getCache
public <K,V> RemoteCache<K,V> getCache(String cacheName, TransactionMode transactionMode, TransactionManager transactionManager) - Specified by:
getCache
in interfaceRemoteCacheContainer
- Parameters:
cacheName
- The cache's name.transactionMode
- TheTransactionMode
to override. Ifnull
, it uses the configured value.transactionManager
- TheTransactionManager
to override. Ifnull
, it uses the configured value.- Returns:
- the
RemoteCache
implementation.
-
getCache
public <K,V> RemoteCache<K,V> getCache(String cacheName, boolean forceReturnValue, TransactionMode transactionMode, TransactionManager transactionManager) - Specified by:
getCache
in interfaceRemoteCacheContainer
- Parameters:
cacheName
- The cache's name.forceReturnValue
-true
to force a return value when it is not needed.transactionMode
- TheTransactionMode
to override. Ifnull
, it uses the configured value.transactionManager
- TheTransactionManager
to override. Ifnull
, it uses the configured value.- Returns:
- the
RemoteCache
implementation.
-
startAsync
-
stopAsync
-
start
public void start()Description copied from interface:Lifecycle
Invoked on component start -
createChannelFactory
public org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory createChannelFactory() -
isTransactional
- Specified by:
isTransactional
in interfaceRemoteCacheContainer
- Returns:
true
if the cache with namecacheName
can participate in transactions.
-
getMarshallerRegistry
public org.infinispan.client.hotrod.impl.MarshallerRegistry getMarshallerRegistry() -
stop
public void stop()Stop the remote cache manager, disconnecting all existing connections. As part of the disconnection, all registered client cache listeners will be removed since client no longer can receive callbacks. -
isStarted
public boolean isStarted()- Specified by:
isStarted
in interfaceRemoteCacheContainer
-
switchToCluster
Description copied from interface:RemoteCacheContainer
Switch remote cache manager to a different cluster, previously declared via configuration. If the switch was completed successfully, this method returnstrue
, otherwise it returnsfalse
.- Specified by:
switchToCluster
in interfaceRemoteCacheContainer
- Parameters:
clusterName
- name of the cluster to which to switch to- Returns:
true
if the cluster was switched,false
otherwise
-
switchToDefaultCluster
public boolean switchToDefaultCluster()Description copied from interface:RemoteCacheContainer
Switch remote cache manager to a the default cluster, previously declared via configuration. If the switch was completed successfully, this method returnstrue
, otherwise it returnsfalse
.- Specified by:
switchToDefaultCluster
in interfaceRemoteCacheContainer
- Returns:
true
if the cluster was switched,false
otherwise
-
createNearCacheService
protected <K,V> org.infinispan.client.hotrod.near.NearCacheService<K,V> createNearCacheService(String cacheName, NearCacheConfiguration cfg) -
getMarshaller
- Specified by:
getMarshaller
in interfaceRemoteCacheContainer
-
cacheNameBytes
-
cacheNameBytes
public static byte[] cacheNameBytes() -
administration
Access to administration operations (cache creation, removal, etc)- Returns:
- an instance of
RemoteCacheManagerAdmin
which can perform administrative operations on the server.
-
close
public void close()Seestop()
-
getCodec
public org.infinispan.client.hotrod.impl.protocol.Codec getCodec()This method is not a part of the public API. It is exposed for internal purposes only. -
getChannelFactory
public org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory getChannelFactory()This method is not a part of the public API. It is exposed for internal purposes only. -
getXaResource
Returns theXAResource
which can be used to do transactional recovery.- Returns:
- An instance of
XAResource
-
getServers
-
getActiveConnectionCount
public int getActiveConnectionCount() -
getConnectionCount
public int getConnectionCount() -
getIdleConnectionCount
public int getIdleConnectionCount() -
getRetries
public long getRetries() -
getAsyncExecutorService
-