Class ServerAnnotationProcessor


  • public class ServerAnnotationProcessor
    extends java.lang.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

      Fields 
      Modifier and Type Field Description
      protected org.slf4j.Logger logger  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static java.lang.Object callPublic​(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object... arguments)  
      protected static void checkMethodsPublic​(java.lang.Object bean, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
      protected static void checkSignaturesMatch​(java.lang.reflect.Method method, java.lang.Class<?>[] expectedTypes, java.util.List<java.lang.String> paramNames)  
      boolean deprocess​(java.lang.Object bean)
      Performs the opposite processing done by process(Object) on callbacks methods annotated with Listener, Subscription and RemoteCall, and on lifecycle methods annotated with PreDestroy.
      boolean deprocessCallbacks​(java.lang.Object bean)
      Performs the opposite processing done by processCallbacks(Object) on callback methods annotated with Listener, Subscription and RemoteCall.
      protected java.util.List<java.lang.reflect.Method> findAnnotatedMethods​(java.lang.Object bean, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
      protected java.lang.Object getField​(java.lang.Object bean, java.lang.reflect.Field field)  
      protected java.lang.Object invokePrivate​(java.lang.Object bean, java.lang.reflect.Method method, java.lang.Object... args)  
      protected static java.lang.Object invokePublic​(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object[] arguments)  
      boolean process​(java.lang.Object bean)
      Processes dependencies annotated with Inject and Session, configuration methods annotated with Configure, callback methods annotated with Listener, Subscription and RemoteCall, and lifecycle methods annotated with PostConstruct.
      boolean processCallbacks​(java.lang.Object bean)
      Processes the callbacks annotated with Listener, Subscription and RemoteCall.
      boolean processConfigurations​(java.lang.Object bean)
      Processes the methods annotated with Configure.
      boolean processDependencies​(java.lang.Object bean)
      Processes the dependencies annotated with Inject and Session.
      protected boolean processInjectable​(java.lang.Object bean, java.lang.Object injectable)  
      protected boolean processInjectables​(java.lang.Object bean, java.util.List<java.lang.Object> injectables)  
      protected java.util.List<java.lang.String> processParameters​(java.lang.reflect.Method method)  
      boolean processPostConstruct​(java.lang.Object bean)
      Processes lifecycle methods annotated with PostConstruct.
      boolean processPreDestroy​(java.lang.Object bean)
      Processes lifecycle methods annotated with PreDestroy.
      protected void setField​(java.lang.Object bean, java.lang.reflect.Field field, java.lang.Object value)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        protected final org.slf4j.Logger logger
    • Constructor Detail

      • ServerAnnotationProcessor

        public ServerAnnotationProcessor​(BayeuxServer bayeuxServer)
      • ServerAnnotationProcessor

        public ServerAnnotationProcessor​(BayeuxServer bayeuxServer,
                                         java.lang.Object... injectables)
    • Method Detail

      • process

        public boolean process​(java.lang.Object bean)
        Processes dependencies annotated with Inject and Session, configuration methods annotated with Configure, callback methods annotated with Listener, Subscription and RemoteCall, and lifecycle methods annotated with PostConstruct.
        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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.Object bean)
        Processes the callbacks annotated with Listener, Subscription and RemoteCall.
        Parameters:
        bean - the annotated service instance
        Returns:
        true if at least one annotated callback has been processed, false otherwise
      • deprocess

        public boolean deprocess​(java.lang.Object bean)
        Performs the opposite processing done by process(Object) on callbacks methods annotated with Listener, Subscription and RemoteCall, 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​(java.lang.Object bean)
        Performs the opposite processing done by processCallbacks(Object) on callback methods annotated with Listener, Subscription and RemoteCall.
        Parameters:
        bean - the annotated service instance
        Returns:
        true if the at least one callback has been deprocessed
      • processPreDestroy

        public boolean processPreDestroy​(java.lang.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
      • findAnnotatedMethods

        protected java.util.List<java.lang.reflect.Method> findAnnotatedMethods​(java.lang.Object bean,
                                                                                java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      • processParameters

        protected java.util.List<java.lang.String> processParameters​(java.lang.reflect.Method method)
      • invokePrivate

        protected java.lang.Object invokePrivate​(java.lang.Object bean,
                                                 java.lang.reflect.Method method,
                                                 java.lang.Object... args)
      • invokePublic

        protected static java.lang.Object invokePublic​(java.lang.Object target,
                                                       java.lang.reflect.Method method,
                                                       java.lang.Object[] arguments)
                                                throws java.lang.Throwable
        Throws:
        java.lang.Throwable
      • callPublic

        protected static java.lang.Object callPublic​(java.lang.Object target,
                                                     java.lang.reflect.Method method,
                                                     java.lang.Object... arguments)
      • getField

        protected java.lang.Object getField​(java.lang.Object bean,
                                            java.lang.reflect.Field field)
      • setField

        protected void setField​(java.lang.Object bean,
                                java.lang.reflect.Field field,
                                java.lang.Object value)
      • checkMethodsPublic

        protected static void checkMethodsPublic​(java.lang.Object bean,
                                                 java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      • checkSignaturesMatch

        protected static void checkSignaturesMatch​(java.lang.reflect.Method method,
                                                   java.lang.Class<?>[] expectedTypes,
                                                   java.util.List<java.lang.String> paramNames)
      • processInjectables

        protected boolean processInjectables​(java.lang.Object bean,
                                             java.util.List<java.lang.Object> injectables)
      • processInjectable

        protected boolean processInjectable​(java.lang.Object bean,
                                            java.lang.Object injectable)