Java Reference
In-Depth Information
public class TraceObserver {
public void serviceTrace(
@Observes @MessageEvent(Type.SERVICE) String message) {
System.out.println("Service message: " + message);
public void parameterTrace(
@Observes @MessageEvent(Type.PARAMETER) String message) {
System.out.println("with parameters: " + message);
Firing and observing your own object types is even simpler. The object type is unique, and it's not
necessary to create your own annotation qualii ers; you can use the object instead.
Observable events are transactional and are delivered in the transactional phase that you dei ne
for that event. That may be before or after the transaction has completed or after a successful or
unsuccessful transaction.
Now you'll see this in action. In Listing 11‐7, you dei ne three observer methods that specify a
transaction phase during which the observers listen for events of type String .
LISTING 11‐7: The Transaction event observer
import javax.enterprise.event.Observes;
import javax.enterprise.event.TransactionPhase;
public class TransactionEventObserver {
public void onInProgress(@Observes String message) {
System.out.println("In progress message: " + message);
public void onSuccess(
@Observes(during = TransactionPhase.AFTER_SUCCESS) String message) {
System.out.println("After success message: " + message);
public void onFailure(
@Observes(during = TransactionPhase.AFTER_FAILURE) String message) {
System.out.println("After failure message: " + message);
public void onCompletion(
@Observes(during = TransactionPhase.AFTER_COMPLETION) String message) {
System.out.println("After completion message: " + message);
Search WWH ::

Custom Search