An Infinispan Distributed Cache Example in Groovy

In 2018 I needed to develop an Infinispan distributed cache example and I choose to use the Groovy scripting language to achieve this. Here I include the script which runs (or should run) in the Groovy Console without needing to manually install any additional dependencies.

It can be beneficial at times to be able to instantiate an object in the Groovy Console and then build a simple example in order to work with a framework and explore an idea. One problem which often appears when working with non-trivial frameworks and which can be a pain to have to work through is the need to install all dependencies and, ideally, without manual effort.

Infinispan Distributed Cache Example Requirements

The following requirements are necessary to execute this example. It’s possible this will run using other configurations but this is what I used:

Groovy version: 3.0.7
Oracle Java version: 15.0.2
OS version: Ubuntu 20.04.2 LTS

As mentioned already, the following script should execute successfully without the need to manually install any extra dependencies and with an empty ~/.groovy/grapes directory.

The Infinispan distributed cache example Groovy script appears in the following snipped and can also be found on GitHub.

				
					@GrabResolver(name='JBoss Release Repository', root='https://repository.jboss.org/nexus/content/repositories/releases/')
@GrabResolver(name='JBoss.org Maven repository', root='https://repository.jboss.org/nexus/content/groups/public')

@GrabExclude(group = 'org.jboss.spec.javax.ws.rs', module='jboss-jaxrs-api_2.1_spec')
@GrabExclude(group = 'org.jboss.spec.javax.xml.bind', module='jboss-jaxb-api_2.3_spec')
@GrabExclude(group = 'org.jboss.spec.javax.servlet', module='jboss-servlet-api_3.1_spec')
@GrabExclude(group = 'javax.validation', module='validation-api')
@GrabExclude(group = 'org.jboss.spec.javax.annotation', module='jboss-annotations-api_1.2_spec')
@GrabExclude(group = 'net.jcip', module='jcip-annotations')
@GrabExclude(group = 'javax.activation', module='activation')
@GrabExclude(group = 'junit', module='junit')

@Grab(group='org.jboss.logging', module='jboss-logging', version='3.3.0.Final')
@Grab(group='org.slf4j', module='slf4j-api', version='1.7.7.jbossorg-1')

@Grab(group='org.infinispan', module='infinispan-core', version='12.0.2.Final')
@Grab(group='org.infinispan', module='infinispan-commons', version='12.0.2.Final')
import org.infinispan.manager.DefaultCacheManager

new DefaultCacheManager()
				
			

The output for the Infinispan Distributed Cache example in the Groovy Console

Finally, we can see the Infinispan Distributed Cache example output in the Groovy Console below.

An Infinispan Distributed Cache Example written in Groovy
An Infinispan Distributed Cache example written in the Groovy scripting language and using the infinispan-core and infinispan-commons 12.0.2.Final dependencies.

An outdated / problematic example

The aforementioned Infinispan Distributed Cache example originally relied on the infinispan-embedded version 9.1.7.Final dependency however when I tried the same script with Java version 15 and Groovy version 3.0.7 on Ubuntu Linux, a warning appeared in the console output that read as follows:

				
					 * Mar 28, 2021 10:09:37 PM org.infinispan.factories.GlobalComponentRegistry start
 * INFO: ISPN000128: Infinispan version: Infinispan 'Bastille' 9.1.7.Final
 * Result: org.infinispan.manager.DefaultCacheManager@25da8465@Address:nullMar 28, 2021 10:09:37 PM org.infinispan.factories.GlobalComponentRegistry lambda$warnAboutUberJarDuplicates$1
 * WARN: ISPN000411: Classpath does not look correct. Make sure you are not mixing uber and jars
				
			

The infinispan-embedded version 9.1.7.Final dependency was released in March 2018 and is a bit dated at this point so I replaced it with infinispan-core and infinispan-commons versions 12.0.2.Final and this script now appears to run successfully and without any warnings.