Quantcast
Channel: Serge Ndong – techscouting through the java news
Viewing all articles
Browse latest Browse all 31

How to: Remote mit einem Infinispan Hot Rod Client verbinden

$
0
0

Hot Rod ist ein binäres sprachneutrales Protokoll, um auf eine Infinispan Cache Instanz in einem Remoteserver zuzugreifen. Der Hot Rod Java Client wurde im Laufe der Entwicklung von Infinispan in seinem API verändert und lässt sich in der aktuellen Version 6 auf zwei verschiedene Arten konfigurieren:

Programmatisch kann man anhand eines org.infinispan.client.hotrod.configuration.ConfigurationBuilder
eine org.infinispan.client.hotrod.configuration.Configuration wie folgt erzeugen.

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.tcpNoDelay(true).connectionPool().numTestsPerEvictionRun(3)
.testOnBorrow(false)
.testOnReturn(false)
.testWhileIdle(true)
.addServer()
.host("192.xxx.xx.xxx");

Diese Konfiguration kann dann verwendet werden, um einen RemoteCacheManager zu instanziieren:

Configuration cfg = cb.build();
RemoteCacheManager rcm = new RemoteCacheManager(cfg);
RemoteCache cache = rcm.getCache();

Alternativ kann mit einer externen Propertydatei, die dem entsprechenden Konstruktor des RemoteCacheManagers übergeben wird, die Konfiguration aus dem Quellcode ausgelagert werden:


ConfigurationBuilder cb = new ConfigurationBuilder();
Properties properties = getProperties();
cb.withProperties(properties);
Configuration cfg = cb.build();
RemoteCacheManager rcm = new RemoteCacheManager(cfg);
RemoteCache cache = rcm.getCache();

Eine entsprechende Propertydatei infinispan.properties könnte wie folgt aussehen:

infinispan.client.hotrod.transport_factory = org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory
infinispan.client.hotrod.server_list = 192.xxx.xx.xxx:11222
infinispan.client.hotrod.marshaller = org.infinispan.commons.marshall.jboss.GenericJBossMarshaller
infinispan.client.hotrod.async_executor_factory = org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory
infinispan.client.hotrod.default_executor_factory.pool_size = 3
infinispan.client.hotrod.default_executor_factory.queue_size = 1000
infinispan.client.hotrod.hash_function_impl.1 = org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1
infinispan.client.hotrod.tcp_no_delay = true
infinispan.client.hotrod.ping_on_startup = true
infinispan.client.hotrod.request_balancing_strategy = org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy
infinispan.client.hotrod.key_size_estimate = 64
infinispan.client.hotrod.value_size_estimate = 512
infinispan.client.hotrod.force_return_values = false

## Konfiguration des Connection Pools
maxActive=-1
maxTotal = -1
maxIdle = -1
whenExhaustedAction = 1
timeBetweenEvictionRunsMillis=60000
minEvictableIdleTimeMillis=180000
testWhileIdle = true
minIdle = 1

Einsortiert unter:Java EE, Java Persistence, Java Runtimes - VM, Appserver & Cloud Tagged: Big Data, caching, Hot Rod, Infinispan

Viewing all articles
Browse latest Browse all 31

Trending Articles