Java Reference
In-Depth Information
org.jboss.msc.service.Service (An example of this approach is
contained in the JBoss quickstart demo at https://github.com/jboss-jdf/
jboss-as-quickstart/tree/master/cluster-ha-singleton )
• Move your cache to a persistent storage, which means using JPA to store
and read data from the cache (See Chapter 5 , Combining Persistence
with CDI , which includes a JPA-based example of our application)
• Use a distributed data cache such as Infinispan to store our data, provid-
ing a failover and data consistency to your cache
Showing all possible solution implementations would, however, make this section ex-
cessively long; therefore, we will illustrate how to pursue the last option, which can
provide a good architectural pattern with the least amount of effort.
Turning your cache into a distributed cache
Infinispan is a distributed data grid platform that exposes a JSR-107-compatible
cache interface in which you can store data and enhance it by providing additional
APIs and features (such as transactional cache, data eviction and expiration, asyn-
chronous operations on the cache, and more). Its primary interface is
javax.cache.Cache , which is similar to the Java SE
java.util.ConcurrentMap , with some modifications for distributed environ-
ments. In particular, it adds the ability to register, deregister, and list event listeners,
and it defines a CacheLoader interface for loading/storing cached data. Cache in-
stances can be retrieved using an appropriate CacheManager , which represents a
collection of caches.
So here's our singleton TheatreBox class rewritten using the Infinispan API:
@Singleton
@Startup
public class TheatreBox {
@Resource(lookup="java:jboss/infinispan/
container/cluster")
private org.infinispan.manager.CacheContainer
container;
private org.infinispan.Cache<Integer, Seat>
cache;
private static final Logger logger =
Search WWH ::




Custom Search