Thursday, 25 September 2014
A long time ago, in a coffee bar far, far away, Infinispan met CDI. The two had the most amazing espressos, but they noticed that service was not as efficient as they wished. To help them out, the CDI support has been extended to include CDI Events.
In case you haven’t heard about CDI events, here is a really quick example:
When Waiter receives an order - he fires a CDI event. On the other hand Barista acts as a listener for ordered coffees (@CoffeeOrdered and @Observes). As a result Barista and Waiter are loosely coupled and moreover they don’t know anything about each other.
Now let’s complicate this situation a little bit… Let’s assume that when Waiter is passing an order to Barista, he might be actually busy processing another order. So let’s introduce a little buffer between them - Waiter puts an order into the Cache and later on - Barista takes it and prepares our delicious coffee…
As you can see - introducing CDI improved the service a lot. Now Waiter does not hurry Barista with the orders. This is why they serve the best espresso in the world there…
They have also a lot more time to think about other improvements (and to be honest… I think they will introduce CacheEntryModifiedEvent, CacheEntryRemovedEvent and CacheStartedEvent really shortly)… Or perhaps they’ll find some other ideas in Infinispan’s manual?
Tags: event cdi
Tuesday, 23 April 2013
As part of the recent Infinispan 5.3.0.Alpha1, the first Infinispan JCache implementation was released which implements version 0.6 of the JCache specification as defined by JSR-107. It passes 100% the mandatory TCK including optional transactions TCK.
A document on how to use Infinispan JCache implementation has just been released, which explains the basics of using JCache, how it differs with existing APIs provided by the JDK, and how to cluster JCache based cache instances. More information will be added to the document, including quickstarts, as we make further progress in the Infinispan 5.3 series.
Please note that the CDI and annotations part of JCache 0.6 specification is still in flux, and we’re not yet able to provide an implementation for it, but we expect the issues stopping the implementation to be resolved in the near future.
Finally, as it’s expected from first releases, some bugs might be present, so if you encounter any misbehaviour, check the list of issues associated with the JCache component to see if the issue has already been resolved, or if not, please report it so that it can be fixed ASAP :).
Tags: jsr 107 cdi jcache alpha
Wednesday, 28 March 2012
Infinispan 5.1.3.FINAL is out now after having received very positive feedback on 5.1.3.CR1 and fixing some other issues on top of that, such as the file cache store leaving files open, improving standalone Infinispan Memcached implementation performance, and including Infinispan CDI extension jars in our distribution.
"Release early, release often", that’s out motto, so we’ll carry on taking feedback onboard and releasing new Infinispan versions where we improve on what we’ve done in the past apart from coming out with new goodies.
Thanks to everyone, both users who have been getting in touch to provide their feedback and developers who have been quickly reacting to users fixing issues and implementing requested features.
Tags: release memcached cdi final performance
Wednesday, 21 September 2011
Since version 5.0 (Pagoa) Infinispan has a new module. This module is a portable CDI extension which integrates Infinispan with the CDI programming model. Here are some highlights of what is provided:
full integration with Java EE 6
typesafe cache (and cache manager) injection
JCACHE annotations support
Please note that this module is a technology preview and its API can still change. Next let’s discuss some of its details.
Typesafe injection and configuration of cache
The first feature you can use out of the box is the typesafe injection of the Cache and the CacheManager. Without any configuration you can inject the default cache, as well as the cache manager used by the extension. This injection can be performed in any bean managed by Java EE like EJB, Servlet and CDI beans. The only thing to do is to use the @Inject annotation:
Please note that the cache injection is typed. In this case, only String typed Java objects could be added as key and value.
It’s also possible to configure the injected cache using CDI. The first step is to create a CDI qualifier, and then create the cache configuration producer, annotated with @ConfigureCache. The qualifier is used to qualify the injection point and the cache configuration producer:
In the same way, a cache can be defined with the default configuration of the cache manager in use, using a producer field:
One advantage of this approach is that all cache configurations of the entire application can be gathered together into a single Configuration class.
The Infinispan CDI extension provides a cache manager with a default configuration (and it is used by default). You can also override the default configuration (used by the default cache manager), as well as the default cache manager. You can find more information here.
JCache annotations support
This specification defines a standard caching API to work with a standalone cache, as well as a distributed cache. An interesting part of the specification are the annotations which are designed to solve common caching use cases. Some of the annotations defined by this specification are:
@CacheResult caches the result of a method call
@CachePut caches a method parameter
@CacheRemoveEntry removes an entry from a cache
@CacheRemoveAll removes all entries from a cache
The following example illustrates the use of these annotations:
The Infinispan CDI extension adds support for these annotations. The only thing to do is to enable the CDI interceptors in your application beans.xml - you can find more information here.
Infinispan CDI and JBoss AS 7
With JBoss AS 7, you can setup an Infinispan cache manager in the server configuration file. This allows you to externalize your Infinispan configuration and also to lookup the cache manager from JNDI, normally with the @Resource annotation. This post has more details on the subject.
As we mentioned earlier, you can override the default cache manager used by the Infinispan CDI extension. To use a JBoss AS 7 configured cache, you need to use the cache manager defined in JBoss AS 7. You only need to annotate the default cache manager producer with @Resource. Simple!
Now, you can inject the cache defined in JBoss AS 7 as we described earlier.
Here is a highlight of the features you will see soon.
support for all JSR 107 annotations - @CachePut, @CacheDefaults
support for remote cache
ability to listen Infinispan events with CDI observers
and more - let us know what you want ;-)
As usual you can open issues and features request on the Infinispan JIRA (component CDI Integration).
Feel free to open a topic in the Infinispan forum if you need help.
The Infinispan CDI documentation is here.
About the author Kevin Pollet is a software engineer at SERLI a Consulting & Software Engineering company based in France. He’s an Open Source advocate and contributes on many projects such as Infinispan and Hibernate Validator, both at SERLI and at home. He is also involved in the Poitou-Charentes JUG and has spoken in many JUG events. He enjoys attending Java events like JUDCon, JBoss World and Devoxx.
Tags: jsr 107 cdi