2.2. Creating CacheManagers
2.2.1. Create a New RemoteCacheManager
Use the following configuration to configure a new
RemoteCacheManager
:
import org.infinispan.client.hotrod.configuration.Configuration; import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; Configuration conf = new ConfigurationBuilder().addServer().host("localhost").port(11222).build(); RemoteCacheManager manager = new RemoteCacheManager(conf); RemoteCache defaultCache = manager.getCache();
Configuration Explanation
An explanation of each line of the provided configuration is as follows:
- Use the
ConfigurationBuilder()
method to configure a new builder. The.addServer()
property adds a remote server, specified via the.host(<hostname|ip>)
and.port(<port>)
properties.Configuration conf = new ConfigurationBuilder().addServer().host(<hostname|ip>).port(<port>).build();
- Create a new
RemoteCacheManager
using the supplied configuration.RemoteCacheManager manager = new RemoteCacheManager(conf);
- Retrieve the default cache from the remote server.
RemoteCache defaultCache = manager.getCache();