Class RemoteCacheManager
- java.lang.Object
-
- org.infinispan.client.hotrod.RemoteCacheManager
-
- All Implemented Interfaces:
Closeable,AutoCloseable,RemoteCacheManagerMXBean,RemoteCacheContainer,BasicCacheContainer,Lifecycle
public class RemoteCacheManager extends Object implements RemoteCacheContainer, Closeable, RemoteCacheManagerMXBean
Factory for
RemoteCaches.In order to be able to use a
RemoteCache, theRemoteCacheManagermust be started first: this instantiates connections to Hot Rod server(s). Starting theRemoteCacheManagercan 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 callingstart().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 Modifier and Type Field Description protected org.infinispan.client.hotrod.impl.transport.netty.ChannelFactorychannelFactorystatic StringDEFAULT_CACHE_NAMEstatic StringHOTROD_CLIENT_PROPERTIESstatic StringJSON_STRING_ARRAY_ELEMENT_REGEXprotected org.infinispan.client.hotrod.event.impl.ClientListenerNotifierlistenerNotifier
-
Constructor Summary
Constructors Constructor Description RemoteCacheManager()Same 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(Configuration configuration)Create a new RemoteCacheManager using the suppliedConfiguration.RemoteCacheManager(Configuration configuration, boolean start)Create a new RemoteCacheManager using the suppliedConfiguration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RemoteCacheManagerAdminadministration()static byte[]cacheNameBytes()static byte[]cacheNameBytes(String cacheName)voidclose()protected <K,V>
NearCacheService<K,V>createNearCacheService(String cacheName, NearCacheConfiguration cfg)protected <K,V>
NearCacheService<K,V>createNearCacheService(NearCacheConfiguration cfg)Deprecated.Replaced by#createNearCacheService(String, NearCacheConfiguration).intgetActiveConnectionCount()Returns the number of active connections<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.org.infinispan.client.hotrod.impl.transport.netty.ChannelFactorygetChannelFactory()This method is not a part of the public API.org.infinispan.client.hotrod.impl.protocol.CodecgetCodec()This method is not a part of the public API.ConfigurationgetConfiguration()Retrieves the configuration currently in use.intgetConnectionCount()Returns the total number of connectionsintgetIdleConnectionCount()Returns the number of idle connectionsMarshallergetMarshaller()org.infinispan.client.hotrod.impl.MarshallerRegistrygetMarshallerRegistry()longgetRetries()Returns the total number of retries that have been executedString[]getServers()Returns a list of servers to which the client is currently connected in the format of ip_address:port_number.booleanisStarted()voidstart()Invoked on component startCompletableFuture<Void>startAsync()voidstop()Stop the remote cache manager, disconnecting all existing connections.CompletableFuture<Void>stopAsync()booleanswitchToCluster(String clusterName)Switch remote cache manager to a different cluster, previously declared via configuration.booleanswitchToDefaultCluster()Switch remote cache manager to a the default cluster, previously declared via configuration.
-
-
-
Field Detail
-
DEFAULT_CACHE_NAME
public static final String DEFAULT_CACHE_NAME
- See Also:
- Constant Field Values
-
HOTROD_CLIENT_PROPERTIES
public static final String HOTROD_CLIENT_PROPERTIES
- See Also:
- Constant Field Values
-
JSON_STRING_ARRAY_ELEMENT_REGEX
public static final String JSON_STRING_ARRAY_ELEMENT_REGEX
- See Also:
- Constant Field Values
-
channelFactory
protected org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory channelFactory
-
listenerNotifier
protected org.infinispan.client.hotrod.event.impl.ClientListenerNotifier listenerNotifier
-
-
Constructor Detail
-
RemoteCacheManager
public RemoteCacheManager(Configuration configuration)
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
public RemoteCacheManager(Configuration configuration, boolean start)
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
ConfigurationBuilderfor 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 Detail
-
getConfiguration
public Configuration getConfiguration()
Description copied from interface:RemoteCacheContainerRetrieves 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:
getConfigurationin interfaceRemoteCacheContainer- Returns:
- The configuration of this RemoteCacheManager
- Since:
- 5.3
-
getCache
public <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.- Specified by:
getCachein interfaceBasicCacheContainer- Parameters:
cacheName- name of cache to retrieve- Returns:
- a cache instance identified by cacheName or null if the cache name has not been defined
-
getCacheNames
public Set<String> getCacheNames()
Description copied from interface:BasicCacheContainerThis 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. If no named caches are registered or no caches have been created, this method returns an empty set. The list of caches does not include internal-only cachesInternalCacheRegistry- Specified by:
getCacheNamesin interfaceBasicCacheContainer- Returns:
- an immutable set of caches registered or created with this cache manager.
-
getCache
public <K,V> RemoteCache<K,V> getCache()
Retrieves the default cache from the remote server.- Specified by:
getCachein interfaceBasicCacheContainer- Returns:
- a remote cache instance that can be used to send requests to the default cache in the server
-
getCache
public <K,V> RemoteCache<K,V> getCache(String cacheName, TransactionMode transactionMode, TransactionManager transactionManager)
- Specified by:
getCachein interfaceRemoteCacheContainer- Parameters:
cacheName- The cache's name.transactionMode- TheTransactionModeto override. Ifnull, it uses the configured value.transactionManager- TheTransactionManagerto override. Ifnull, it uses the configured value.- Returns:
- the
RemoteCacheimplementation.
-
getCache
public <K,V> RemoteCache<K,V> getCache(String cacheName, boolean forceReturnValue, TransactionMode transactionMode, TransactionManager transactionManager)
- Specified by:
getCachein interfaceRemoteCacheContainer- Parameters:
cacheName- The cache's name.forceReturnValue-trueto force a return value when it is not needed.transactionMode- TheTransactionModeto override. Ifnull, it uses the configured value.transactionManager- TheTransactionManagerto override. Ifnull, it uses the configured value.- Returns:
- the
RemoteCacheimplementation.
-
startAsync
public CompletableFuture<Void> startAsync()
-
stopAsync
public CompletableFuture<Void> stopAsync()
-
start
public void start()
Description copied from interface:LifecycleInvoked on component start
-
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:
isStartedin interfaceRemoteCacheContainer
-
switchToCluster
public boolean switchToCluster(String clusterName)
Description copied from interface:RemoteCacheContainerSwitch 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:
switchToClusterin interfaceRemoteCacheContainer- Specified by:
switchToClusterin interfaceRemoteCacheManagerMXBean- Parameters:
clusterName- name of the cluster to which to switch to- Returns:
trueif the cluster was switched,falseotherwise
-
switchToDefaultCluster
public boolean switchToDefaultCluster()
Description copied from interface:RemoteCacheContainerSwitch 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:
switchToDefaultClusterin interfaceRemoteCacheContainer- Specified by:
switchToDefaultClusterin interfaceRemoteCacheManagerMXBean- Returns:
trueif the cluster was switched,falseotherwise
-
createNearCacheService
protected <K,V> NearCacheService<K,V> createNearCacheService(String cacheName, NearCacheConfiguration cfg)
-
createNearCacheService
@Deprecated protected <K,V> NearCacheService<K,V> createNearCacheService(NearCacheConfiguration cfg)
Deprecated.Replaced by#createNearCacheService(String, NearCacheConfiguration).
-
getMarshaller
public Marshaller getMarshaller()
- Specified by:
getMarshallerin interfaceRemoteCacheContainer
-
cacheNameBytes
public static byte[] cacheNameBytes(String cacheName)
-
cacheNameBytes
public static byte[] cacheNameBytes()
-
administration
public RemoteCacheManagerAdmin administration()
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
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.
-
getServers
public String[] getServers()
Description copied from interface:RemoteCacheManagerMXBeanReturns a list of servers to which the client is currently connected in the format of ip_address:port_number.- Specified by:
getServersin interfaceRemoteCacheManagerMXBean
-
getActiveConnectionCount
public int getActiveConnectionCount()
Description copied from interface:RemoteCacheManagerMXBeanReturns the number of active connections- Specified by:
getActiveConnectionCountin interfaceRemoteCacheManagerMXBean
-
getConnectionCount
public int getConnectionCount()
Description copied from interface:RemoteCacheManagerMXBeanReturns the total number of connections- Specified by:
getConnectionCountin interfaceRemoteCacheManagerMXBean
-
getIdleConnectionCount
public int getIdleConnectionCount()
Description copied from interface:RemoteCacheManagerMXBeanReturns the number of idle connections- Specified by:
getIdleConnectionCountin interfaceRemoteCacheManagerMXBean
-
getRetries
public long getRetries()
Description copied from interface:RemoteCacheManagerMXBeanReturns the total number of retries that have been executed- Specified by:
getRetriesin interfaceRemoteCacheManagerMXBean
-
-