Events in CDI 2.0 - No Fluff Just Stuff

Events in CDI 2.0

Posted by: Reza Rahman on October 23, 2014

CDI 2.0 (JSR 365) was the first Java EE 8 approved JSR. The CDI Experts Group has already been formed several weeks ago and the first CDI 2.0 EG face to face meeting took place last week in Brno (see feedback here). The EG has ambitious plans for CDI 2.0 (see here) and is working hard to fulfils them, you can track the evolution of their work here.

CDI Events is one of the focus area of CDI 2.0. CDI Events is a simple mechanism that provides an implantation of the Observer pattern where the Event Producer is cleanly decoupled from the Event Consumer(s). This mechanism is available in CDI since the beginning, i.e. CDI 1.0. But for CDI 2.0, the EG plans to improve the overall CDI Event mechanism by adding:

  • Asynchronous events
  • Conversation begins/end events
  • Priorities (ordering of events)
  • Observer Deactivation
  • The ability to observe a group of qualified events ("Qualifier Inheritance")
  • ...

Obviously at this stage, those are just plans, just ideas and clearly introducing some of those features leads to quite a few questions and in some case might also induces potential issues if this is not well thought. Another constraint faced by CDI is that it is a transversal technology that is used across the platform so extra care should be taken. All those new features needs to be discussed in details and challenged, and sometime prototyped, before they are standardised into the CDI specification. The CDI 2.0 EG has recently put together an (evolving) document that describes the thoughts but also the challenges behind some of the CDI Events potential enhancements. This is definitely something to read.

CDI Event is today a useful mechanism. If you have ideas on how events can be improved in CDI 2.0, you should really '@Observe' what is being discussed in the EG and 'fire' comments (I know, in code, it's the opposite, i.e. 'fire' triggers the @Observe ;-) ).

Reza Rahman

About Reza Rahman

Reza is a recovering independent consultant and now Java EE evangelist at Oracle. He is the author of the popular book EJB 3 in Action. Reza is a frequent speaker at developer gatherings worldwide including JavaOne and NFJS. He is an avid contributor to community sites like JavaLobby and TSS. Reza has been a member of the Java EE, EJB and JMS expert groups. He implemented the EJB container for the Resin open source Java EE application server.

All views voiced are squarely mine alone, not Oracle's.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »