JDG in Library Mode Usage Example: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=Internal= * Infinispan Concepts - Client API") |
(→Maven) |
||
(7 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
* [[Infinispan_Concepts#Client_API|Infinispan Concepts - Client API]] | * [[Infinispan_Concepts#Client_API|Infinispan Concepts - Client API]] | ||
=Overview= | |||
The example is deployed in a wrapper servlet, to facilitate interaction with the EAP JEE container. | |||
=GitHub= | |||
{{External|https://github.com/NovaOrdis/playground/tree/master/jboss/infinispan/library-mode-access-from-eap}} | |||
=Maven= | |||
<pre> | |||
<dependency> | |||
<groupId>org.infinispan</groupId> | |||
<artifactId>infinispan-core</artifactId> | |||
<version>8.3.0.Final-redhat-1</version> | |||
<scope>provided</scope> | |||
</dependency> | |||
</pre> | |||
If support for JDG in library mode is [[Installation_of_JDG_in_Library_Mode_within_EAP#Module_Installation|deployed within the target EAP]] (preferred), declare the dependency <scope>provided</scope> and configure the [[jboss-deployment-structure.xml]] as shown: | |||
<pre> | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<jboss-deployment-structure> | |||
<deployment> | |||
<dependencies> | |||
<module name="org.infinispan" slot="jdg-7.0" services="export"/> | |||
</dependencies> | |||
</deployment> | |||
</jboss-deployment-structure> | |||
</pre> | |||
[[Jboss-deployment-structure.xml#deployment_dependencies_module_services|services="export"]] is required because we want JDG module to export its [[Java_Services#Overview|java services]] to the application. | |||
Otherwise, all required dependencies it with your deployment, by '''not''' declaring them "provided". | |||
=HotRod Client Configuration= | |||
<pre> | |||
import org.infinispan.client.hotrod.configuration.Configuration; | |||
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; | |||
... | |||
ConfigurationBuilder cb = new ConfigurationBuilder(); | |||
cb.tcpNoDelay(true) | |||
.connectionPool() | |||
.numTestsPerEvictionRun(3) | |||
.testOnBorrow(false) | |||
.testOnReturn(false) | |||
.testWhileIdle(true) | |||
.addServer() | |||
.host(JDG_SERVER_IP_ADDRESS) | |||
.port(JDG_SERVER_IP_PORT); | |||
Configuration c = cb.build(); | |||
</pre> | |||
=Create a RemoteCacheManager and a Cache= | |||
<pre> | |||
import org.infinispan.client.hotrod.RemoteCacheManager; | |||
import org.infinispan.commons.api.BasicCache; | |||
... | |||
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(c); | |||
BasicCache cache = remoteCacheManager.getCache(); | |||
... | |||
</pre> | |||
=Features= | |||
==Basic API== | |||
<pre> | |||
cache.put("some-key", "some value"); | |||
String s = cache.get("some-key"); | |||
</pre> | |||
==Transactions== | |||
Not available in remote client/server mode. |
Latest revision as of 18:17, 4 May 2017
Internal
Overview
The example is deployed in a wrapper servlet, to facilitate interaction with the EAP JEE container.
GitHub
Maven
<dependency> <groupId>org.infinispan</groupId> <artifactId>infinispan-core</artifactId> <version>8.3.0.Final-redhat-1</version> <scope>provided</scope> </dependency>
If support for JDG in library mode is deployed within the target EAP (preferred), declare the dependency <scope>provided</scope> and configure the jboss-deployment-structure.xml as shown:
<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment> <dependencies> <module name="org.infinispan" slot="jdg-7.0" services="export"/> </dependencies> </deployment> </jboss-deployment-structure>
services="export" is required because we want JDG module to export its java services to the application.
Otherwise, all required dependencies it with your deployment, by not declaring them "provided".
HotRod Client Configuration
import org.infinispan.client.hotrod.configuration.Configuration; import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; ... ConfigurationBuilder cb = new ConfigurationBuilder(); cb.tcpNoDelay(true) .connectionPool() .numTestsPerEvictionRun(3) .testOnBorrow(false) .testOnReturn(false) .testWhileIdle(true) .addServer() .host(JDG_SERVER_IP_ADDRESS) .port(JDG_SERVER_IP_PORT); Configuration c = cb.build();
Create a RemoteCacheManager and a Cache
import org.infinispan.client.hotrod.RemoteCacheManager; import org.infinispan.commons.api.BasicCache; ... RemoteCacheManager remoteCacheManager = new RemoteCacheManager(c); BasicCache cache = remoteCacheManager.getCache(); ...
Features
Basic API
cache.put("some-key", "some value"); String s = cache.get("some-key");
Transactions
Not available in remote client/server mode.