Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view and edit Infinispan cached data remotely

I have an Infinispan cache embedded in a WildFly 8.2 server.

I added to standalone.xml inside <subsystem xmlns="urn:jboss:domain:infinispan:2.0">:

<cache-container name="mycache" default-cache="cachedb">
    <transport lock-timeout="600000" />
    <replicated-cache name="cachedb" batching="true" mode="SYNC" />
</cache-container>

...and injected the cache container like this:

@Singleton
@Startup
public class CacheManager {

    @Resource(lookup = "java:jboss/infinispan/container/mycache")
    private CacheContainer container;
    . . . . 

}

I can use the cache in my applications.

However the requirement is to see/edit/delete the cached data remotely by using any of the cache monitoring APIs.

Via jconsole I can see the cache information, but not the cached data.

jconsole screen

How can I access the cache remotely?

like image 395
Sujith PS Avatar asked Apr 09 '15 05:04

Sujith PS


People also ask

How does infinispan cache work?

Infinispan replicates cache entries on a subset of nodes in a cluster and assigns entries to fixed owner nodes. Infinispan requests read operations from owner nodes to ensure it returns the correct value. Infinispan evicts stale data from all nodes whenever operations modify entries in the cache.

How do I clear infinispan cache?

the clear() goes to all nodes. You can use the CACHE_MODE_LOCAL flag to force it to the local node. example: cache. getAdvancedCache().

What is infinispan JGroups?

Infinispan uses the JGroups library to handle all network communications. JGroups enables cluster node detection, a process called discovery, and reliable data transfer between nodes. JGroups also handles the process of nodes entering and exiting the cluster and master node determination for the cluster.


1 Answers

First of all, my condolences on having to choose the road less traveled.

It's possible to access an embedded Infinispan cache remotely. You need to set up a org.infinispan.server.hotrod.HotRodServer in your server process, essentially reverse engineering the pre-packaged Infinispan Server distribution. This approach is not documented, so proceed at your own risk.

You need these dependencies:

<dependency>
    <groupId>org.infinispan</groupId>
    <artifactId>infinispan-server-hotrod</artifactId>
    <version>7.1.0.Final</version>
</dependency>
<dependency>
    <groupId>org.infinispan</groupId>
    <artifactId>infinispan-client-hotrod</artifactId>
    <version>7.1.0.Final</version>
</dependency>
<dependency>
    <groupId>org.infinispan</groupId>
    <artifactId>infinispan-remote-query-server</artifactId>
    <version>7.1.0.Final</version>
</dependency>

Configure an example cache (infinispan.xml):

<infinispan>
    <cache-container default-cache="default">
        <local-cache name="dumpster">
            <compatibility />
        </local-cache>
    </cache-container>
</infinispan>

The server process:

// Start a cache manager as usual
EmbeddedCacheManager cacheManager;
try (InputStream in = ClassLoader.getSystemResourceAsStream("infinispan.xml")) {
    cacheManager = new DefaultCacheManager(in);
}

// Start a server to allow remote access to the cache manager
HotRodServerConfiguration serverConfig = new HotRodServerConfigurationBuilder()
        .host("127.0.0.1").port(9999).build();
HotRodServer server = new HotRodServer();
server.start(serverConfig, cacheManager);

// Start the example cache
Cache<String, String> cache = cacheManager.getCache("dumpster", true);
cache.put("K", "V");
System.out.println(cache.get("K")); // V

The client process:

Configuration config = new ConfigurationBuilder().addServer()
        .host("127.0.0.1").port(9999).build();
RemoteCacheManager cacheManager = new RemoteCacheManager(config);
RemoteCache<String, String> cache = cacheManager.getCache("dumpster");
System.out.println(cache.get("K")); // V
like image 111
approxiblue Avatar answered Oct 23 '22 08:10

approxiblue