background preloader

Java EE

Facebook Twitter

Java EE6 Events, a lightweight alternative to JMS. A few weeks ago I attended a bejug meeting about Java EE 6, Building next generation enterprise applications.

Java EE6 Events, a lightweight alternative to JMS

Having read much about it, I did not expect to see much shocking hidden features. But there was one part of the demo I really found impressive. Due to its loose coupling, Enterprise possibilities and simplicity. The feature I’m going to talk about today is the event mechanism that is in java EE 6. The general idea is to fire an event and let an eventlistener pick it up. Easy peasy. So we just need to fire it. Now the event is fired, If no one is registerd to pick it up, it disappears into oblivion, thus we create a listener. The @Observes annotation listens to all events with a LogMessage.

If we would want to combine the database logging and the console logging, we can just create multiple methods that listen to the same event.

JMX

CDI. Dependency Injection for static methods - Stubblog. Developers who are familiar with the topic of clean code know that static methods are a problem, especially if it comes to testability.

Dependency Injection for static methods - Stubblog

Static makes the code global, and if there is some kind of state involved it is even more a problem because this is global state then - both a maintenance and testability nightmare. Unfortunately, sometimes you don't get around of using such code. This could be due to a third party library you have to use, or even because of limitations of PHP itself. (Ever wanted to configure stream wrappers if stream context is not an option? Your only chance are static methods and therefore global state.) Luckily PHP 5.3 comes with a new feature: dynamic access to static methods. For some reason the method call can not be moved to another place where we could get rid of the direct dependency.

The class still works as before, but we can change the name of the class the static method is called on. Our own Bar class is now only loosely coupled to FooFromSomeLibrary. How To Deal With Interfaces In Java EE 6 (or no more Impl) We Recommend These Resources In EJB 3.0 interfaces were required. So whether you liked it or not, you had to provide one. To make it look a bit natural, you could remove the "Remote" or "Local" suffix.

JPA

JSF. Conversational CRUD in Java EE 6. We Recommend These Resources This tutorial will demonstrate a pattern for creating CRUD applications in JSF and Java EE 6.

Conversational CRUD in Java EE 6

While this is not the only way of implementing this mechanism, it does promote re-use and can give you essentially zero code CRUD pages requiring just the view code. The goal is to provide a single structure that provides the particular feature of being both stateless or conversational where we might want a conversational edit page and a stateless view page. This pattern is based on the EntityHome pattern that was used in JBoss Seam and carries over well to Java EE 6 with CDI. This is something I use all the time to make view/edit pages really quickly and unlike most of the automatic scaffolding in other frameworks, doesn’t need re-writing to go into production.

Running in a Servlet Container If you are running this in a servlet container or embedded Jetty, you will need to make the following changes : Create our Application 2. 3. Our home bean That was pretty easy!