javax.enterprise.inject.spi
Interface ObserverMethod<T>

Type Parameters:
T - the event which should be observed

public interface ObserverMethod<T>

ObserverMethod is the SPI to handle an observer method, which is an event consumer for an event of the given type T. An instance of ObserverMethod exists for every observer method of every enabled bean.

A class may have n observer methods.

Each observer method must have a void return value and exactly one parameter which defines which event it javax.enterprise.event.Observes. The observed event may be further specified by using an optional Qualifier.

Sample:
 public class UserHandler 
 {
   public void afterUserLogin(@Observes UserLoginEvent userHasLoggedIn) 
   {
     // prepare some data for the user, ...
     int userId = userHadLoggedIn.getUserId();
     ...
   }
   
   public void afterAdminLogin(@Observes @Admin UserLoginEvent userHasLoggedIn) 
   {
     // prepare stuff for the admin user
     ...
   }
   
   public void afterUserLogout(@Observes UserLogoutEvent userHasLoggedOut) 
   {
     // cleanup afterwards 
     ...
   }
 }
 

See Also:
Observes

Method Summary
 Class<?> getBeanClass()
           
 Set<Annotation> getObservedQualifiers()
           
 Type getObservedType()
           
 Reception getReception()
           
 TransactionPhase getTransactionPhase()
           
 void notify(T event)
          will actually cann the underlying observer method
 

Method Detail

getBeanClass

Class<?> getBeanClass()

getObservedType

Type getObservedType()
Returns:
the type of the observed event

getObservedQualifiers

Set<Annotation> getObservedQualifiers()
Returns:
the defined Qualifiers plus javax.enterprise.inject.Any

getReception

Reception getReception()
Returns:
either Reception#IF_EXISTS if the observed method must only be called if an instance of the bean which defines the observer method aready exists in the specified context or Reception#ALWAYS.

getTransactionPhase

TransactionPhase getTransactionPhase()
Returns:
the appropriate TransactionPhase for a transactional observer method or TransactionPhase#IN_PROGRESS otherwise.

notify

void notify(T event)
will actually cann the underlying observer method

Parameters:
event -


Copyright © 2003-2012 The Apache Software Foundation. All Rights Reserved.