Infinispan/JDG Quickstarts – CarMart



I will try to post a all the quick-starts here, with some comments/thoughts, basicall try to dissect some of the application for knowledge gain on infinispan/jdg-rhdg using the libraby mode in EAP.

Overview CarMart

This is an application to use Infinispan’s features (caches) instead of a DB per se, front-end on JSF, deployed as app on JBoss and infinispan cache.

That’s the application deployed, we can see the list of cars and the cache statistics:


Retrivals means the number of get operations.


First compile the application using Maven, the start eap and deploy.

19:12:24,702 INFO [] (DeploymentScanner-threads – 1) WFLYSRV0010: Deployed “jboss-carmart.war” (runtime-name : “jboss-carmart.war”)

I added some external logs as well, to show getCacheContainer function:

INFO [com.ocpsoft.pretty.PrettyFilter] (default task-2) PrettyFilter initialized.
INFO [] (default task-2) cool log


JSF2.0 plays a role here with a template, this is explained on using template  with `<ui:composition template`so the home.jsf imports the template file.

The exchange of information is done with the Remote using a javex annotation ​ @Named, to declare the bean `stats`, the form template is populated by an EL expression, which means it can also invoke the setter when submitting the form:

<h:outputLabel value=”Retrievals:” /><h:outputText value=”#{stats.retrievals}” />

That actually calls the getter function, on the

public String getRetrievals() {return stats.get(ServerStatistics.RETRIEVALS);}

The app has also css, which is imported using styleClass in file style.css.


The core of the code, of course, is on the CacheContainerProvider interface, on this application we have the local container provider, that extends the cache container provider – the upper level class is an abstract class. On this example, it will be the LocalCacheContainerProvider, that’s the core with all the settings for the cache:

GlobalConfiguration glob = new GlobalConfigurationBuilder()
.nonClusteredDefault() //Helper method that gets you a default constructed GlobalConfiguration, preconfigured for use in LOCAL mode
.globalJmxStatistics().enable() //This method allows enables the jmx statistics of the global configuration.
.build(); //Builds the GlobalConfiguration object

Original configuration:

– jmx statistics

– clustering and local mode so the data is not replicated.

– isolation levels (from the 3 levels of isolation of dbs): REPEATABLE_READ.

The populate is done with a PopulateCache that manually creates each car.

INFO [] (ServerService Thread Pool — 142) Successfully imported data!


Creation of the basic cache:

BasicCache<String, Object> cars = provider.getCacheContainer().getCache(CarManager.CACHE_NAME);

The insertion is done using the cache provider (encoded):

cars.put(CarManager.encode(c.getNumberPlate()), c);

Addition of the new car follows the same pattern as populating the home.jsf – done with the annotation @Model, that creates a EL. So then get the cache with the cache name, and the put the value – encoding in UTF-8.

carCache = provider.getCacheContainer().getCache(CACHE_NAME);
carCache.put(CarManager.encode(car.getNumberPlate()), car);
List<String> carNumbers = getNumberPlateList();
if (carNumbers == null)
carNumbers = new LinkedList<String>();
carCache.put(CAR_NUMBERS_KEY, carNumbers);
return “home”;


As shown above, the statistics comes from a JMX connection and are enabled with `globalJmxStatistics().enable()`. The core operation is to get the cache from the cache manager (with name, since the cache architecture in JDG is based on naming):

stats = ((DefaultCacheManager) provider.getCacheContainer()).getCache(CarManager.CACHE_NAME).getAdvancedCache()

On this example, the cache name is defined globally as <CarManager.CACHE_NAME>. All those stats information are conteined in Stats class.

To display, the only process needed is to convert to string:

public String getMisses() { return String.valueOf(stats.getMisses());}

The Server Statistics meaning is on documentation

Interesting facts:

1. changing RemoteStatisticsProvider @Named(“stats”) does not break the application, but Local RemoteStatisticsProvider does: Reason you’re using local ofc.

2. Added a new car, on Populate Cache, but there is no plate verification, so the plate repeated: Reason: addition is an example.

6T4 2526
2B2 4946
2B2 4946

3. Added some more data on the stats table,  adding Time Since Beginning. Reason: there are more stats that can be added.

Retrievals: 3
Stores: 6
Current Entries: 6
Hits: 3
Misses: 0
Remove Hits: 0
Time Since Beginning 2

4. The Infinispan stores the references to the values so you are modifying directly the object – aka by reference.

5. The insertion encode is done for `​UTF-8`.

6. The added custom log message actually appears 3 times when deploying the application. Reason: not sure why.

7. Yes, the more you reload, the more the number of hits will increase, and the time since beginning as well. The time is in seconds.

8. After updating a few times, the browser crashed and continue to add more and more repeated data when I was refreshing the page. Maybe it was the cache lol!


9. When deploying you will see an warning:

WARN [org.infinispan.manager.DefaultCacheManager] (ServerService Thread Pool — 120) ISPN000435: Cache manager initialized with a default cache configuration but without a name for it. Set it in the GlobalConfiguration.

This can be solved setting up a cache manager name or at least, it should:



This is a good exercises that can make sense the introductory pages of Infinispan. There are many small concepts to learn on Infinispan, the only way to learn is a hands on approach.

The most important part of the tutorial, ofc, is the cache, but it has this hardcoded configuration so is obscure and requires some previous knowledge for understanding it.

Suggestion: new DefaultCacheManager("use-a-confi-file.xml");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s