Infinispan Cluster on Tomcat
gmparker2000 Jul 28, 2017 3:34 PMI setup two tomcat instances. I have an initialization servlet on each that sets up a distributed cache like this:
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder(); global.transport().clusterName("testCluster"); cacheManager = new DefaultCacheManager(global.build()); ConfigurationBuilder config = new ConfigurationBuilder(); config.expiration().lifespan(60000, TimeUnit.SECONDS).clustering().cacheMode(CacheMode.DIST_SYNC); cacheManager.defineConfiguration("test", config.build());
The first server, server A, has a page that puts a message in the cache like this:
Cache<String, String> cache = CacheInitializationServlet.cacheManager.getCache("test"); String message = cache.get("message"); if (message == null) { message = ""; } message += "*"; cache.put("message", message); message = cache.get("message"); System.out.println("Server A -> cache has : " + message);
Each time I hit the page it adds an asterisk to the message in the cache. The second server, server B, has a page the just gets the message from the cache like this:
Cache<String, String> cache = CacheInitializationServlet.cacheManager.getCache("test"); String message = cache.get("message"); System.out.println("Server B -> cache has : " + message);
When I hit the page on server A, I see:
Server A -> cache has : *
When I hit server B, I get:
Server B -> cache has : null
The console on server A has the following logs entries at startup:
28-Jul-2017 16:27:21.460 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.start ISPN000078: Starting JGroups channel testCluster
28-Jul-2017 16:27:21.461 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.buildChannel ISPN000088: Unable to use any JGroups configuration mechanisms provided in properties {}. Using default JGroups configuration!
28-Jul-2017 16:27:26.702 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.receiveClusterView ISPN000094: Received new cluster view for channel testCluster: [localhost-32508|0] (1) [localhost-32508]
28-Jul-2017 16:27:26.714 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.startJGroupsChannelIfNeeded ISPN000079: Channel testCluster local address is localhost-32508, physical addresses are [fe80:0:0:0:ac5c:7cd7:90b7:7667%10:51444]
28-Jul-2017 16:27:26.720 INFO [localhost-startStop-1] org.infinispan.factories.GlobalComponentRegistry.start ISPN000128: Infinispan version: Infinispan 'Bastille' 9.1.0.Final
Done initializing cache
The console on server B has the following logs entries at startup:
28-Jul-2017 16:27:23.713 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.start ISPN000078: Starting JGroups channel testCluster
28-Jul-2017 16:27:23.714 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.buildChannel ISPN000088: Unable to use any JGroups configuration mechanisms provided in properties {}. Using default JGroups configuration!
28-Jul-2017 16:27:28.885 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.receiveClusterView ISPN000094: Received new cluster view for channel testCluster: [localhost-16476|0] (1) [localhost-16476]
28-Jul-2017 16:27:28.895 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.startJGroupsChannelIfNeeded ISPN000079: Channel testCluster local address is localhost-16476, physical addresses are [fe80:0:0:0:ac5c:7cd7:90b7:7667%10:51445]
28-Jul-2017 16:27:28.900 INFO [localhost-startStop-1] org.infinispan.factories.GlobalComponentRegistry.start ISPN000128: Infinispan version: Infinispan 'Bastille' 9.1.0.Final
The same type of test run using a standalone Java application works when run from the command line. So something is not working correctly on Tomcat. Hoping someone can show me what is wrong.