org.cometd.java.annotation
Class ServerAnnotationProcessor

java.lang.Object
  extended by org.cometd.java.annotation.ServerAnnotationProcessor

public class ServerAnnotationProcessor
extends Object

Processes annotations in server-side service objects.

Service objects must be annotated with Service at class level to be processed by this processor, for example:

 @Service
 public class MyService
 {
     @Session
     private ServerSession session;

     @Configure("/foo")
     public void configureFoo(ConfigurableServerChannel channel)
     {
         channel.setPersistent(...);
         channel.addListener(...);
         channel.addAuthorizer(...);
     }

     @Listener("/foo")
     public void handleFooMessages(ServerSession remote, ServerMessage.Mutable message)
     {
         // Do something
     }
 }
 

The processor is used in this way:

 BayeuxServer bayeux = ...;
 ServerAnnotationProcessor processor = ServerAnnotationProcessor.get(bayeux);
 MyService s = new MyService();
 processor.process(s);
 

See Also:
ClientAnnotationProcessor

Field Summary
protected  org.eclipse.jetty.util.log.Logger logger
           
 
Constructor Summary
ServerAnnotationProcessor(BayeuxServer bayeuxServer)
           
 
Method Summary
 boolean deprocess(Object bean)
          Performs the opposite processing done by process(Object) on callbacks methods annotated with Listener and Subscription, and on lifecycle methods annotated with PreDestroy.
 boolean deprocessCallbacks(Object bean)
          Performs the opposite processing done by processCallbacks(Object) on callback methods annotated with Listener and Subscription.
protected  Method findGetterMethod(Class<?> klass, Method setter)
           
protected  Object getField(Object bean, Field field)
           
protected  Object invokeMethod(Object bean, Method method, Object... args)
           
 boolean process(Object bean)
          Processes dependencies annotated with Inject and Session, lifecycle methods annotated with PostConstruct, and callback methods annotated with Listener and Subscription.
 boolean processCallbacks(Object bean)
          Processes the callbacks annotated with Listener and Subscription.
 boolean processConfigurations(Object bean)
          Processes the methods annotated with Configure
 boolean processDependencies(Object bean)
          Processes the dependencies annotated with Inject and Session.
 boolean processPostConstruct(Object bean)
          Processes lifecycle methods annotated with PostConstruct.
 boolean processPreDestroy(Object bean)
          Processes lifecycle methods annotated with PreDestroy.
protected  void setField(Object bean, Field field, Object value)
           
protected static boolean signaturesMatch(Class<?>[] candidate, Class<?>[] expected)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.eclipse.jetty.util.log.Logger logger
Constructor Detail

ServerAnnotationProcessor

public ServerAnnotationProcessor(BayeuxServer bayeuxServer)
Method Detail

process

public boolean process(Object bean)
Processes dependencies annotated with Inject and Session, lifecycle methods annotated with PostConstruct, and callback methods annotated with Listener and Subscription.

Parameters:
bean - the annotated service instance
Returns:
true if the bean contains at least one annotation that has been processed, false otherwise

processConfigurations

public boolean processConfigurations(Object bean)
Processes the methods annotated with Configure

Parameters:
bean - the annotated service instance
Returns:
true if at least one annotated configure has been processed, false otherwise

processDependencies

public boolean processDependencies(Object bean)
Processes the dependencies annotated with Inject and Session.

Parameters:
bean - the annotated service instance
Returns:
true if at least one annotated dependency has been processed, false otherwise

processPostConstruct

public boolean processPostConstruct(Object bean)
Processes lifecycle methods annotated with PostConstruct.

Parameters:
bean - the annotated service instance
Returns:
true if at least one lifecycle method has been invoked, false otherwise

processCallbacks

public boolean processCallbacks(Object bean)
Processes the callbacks annotated with Listener and Subscription.

Parameters:
bean - the annotated service instance
Returns:
true if at least one annotated callback has been processed, false otherwise

deprocess

public boolean deprocess(Object bean)
Performs the opposite processing done by process(Object) on callbacks methods annotated with Listener and Subscription, and on lifecycle methods annotated with PreDestroy.

Parameters:
bean - the annotated service instance
Returns:
true if at least one deprocessing has been performed, false otherwise
See Also:
process(Object)

deprocessCallbacks

public boolean deprocessCallbacks(Object bean)
Performs the opposite processing done by processCallbacks(Object) on callback methods annotated with Listener and Subscription.

Parameters:
bean - the annotated service instance
Returns:
true if the at least one callback has been deprocessed

processPreDestroy

public boolean processPreDestroy(Object bean)
Processes lifecycle methods annotated with PreDestroy.

Parameters:
bean - the annotated service instance
Returns:
true if at least one lifecycle method has been invoked, false otherwise

invokeMethod

protected Object invokeMethod(Object bean,
                              Method method,
                              Object... args)

findGetterMethod

protected Method findGetterMethod(Class<?> klass,
                                  Method setter)

getField

protected Object getField(Object bean,
                          Field field)

setField

protected void setField(Object bean,
                        Field field,
                        Object value)

signaturesMatch

protected static boolean signaturesMatch(Class<?>[] candidate,
                                         Class<?>[] expected)


Copyright © 2008-2011 Dojo Foundation. All Rights Reserved.