Java Reference
In-Depth Information
ar to the java.util.ConcurrentMap Java SE, with some modifications for distrib-
uted environments. In particular, it adds the ability to register, deregister, and list event
listeners. Also, it defines a CacheLoader interface to load/store cached data. Cache in-
stances can be retrieved using an appropriate CacheManager interface, which repres-
ents a collection of caches.
So here's our singleton TheatreBox class rewritten using the Infinispan API:
@Singleton
@Startup
@AccessTimeout(value = 5, unit = TimeUnit.MINUTES)
public class TheatreBox {
private static final Logger logger =
Logger.getLogger(TheatreBox.class);
private Map<Integer, Seat> seats;
@Resource(lookup = "java:jboss/infinispan/tickets")
private EmbeddedCacheManager container;
@PostConstruct
public void setupTheatre() {
try {
this.cache = container.getCache();
logger.info("Got Infinispan cache");
int id = 0;
for (int i = 0; i < 5; i++) {
addSeat(new Seat(++id, "Stalls", 40));
addSeat(new Seat(++id, "Circle", 20));
addSeat(new Seat(++id, "Balcony", 10));
}
logger.info("Seat Map constructed.");
} catch (Exception e) {
logger.info("Error! " + e.getMessage());
}
}
private void addSeat(Seat seat) {
Search WWH ::




Custom Search