5 Replies Latest reply on Aug 27, 2007 12:54 PM by gbc1

    Asynchronous JavaBean method not getting called

    damianharvey

      I have a method in a JavaBean that sends out an email and I'd quite like it to be asynchronous.

      My method is annotated with @Asynchronous and I have <async:timer-service-dispatcher/> in my components.xml. However the method never gets called even though I do explicitly call it.

      @Asynchronous
      public void send(Company company, String[] roles, String subject, String content) {
      //stuff
      }

      If I comment out the @Asynchronous then the method is called fine and my email is sent.

      I'm using Seam 1.3.0.ALPHA (should really upgrade but waiting for 2.0.GA) and in my components.xml I've set it to use the async-2.0.xsd as none exists for 1.3.

      Are there any issues/tricks that I should be aware of? The Seam Mail example works fine on the same server and my config looks the same (for the async stuff).

      Thanks,

      Damian.


        • 1. Re: Asynchronous JavaBean method not getting called
          gbc1

          check following

          components.xml
          - async:timer... declared
          - async namespace declared

          interface of bean with contains asynch method
          - fully annotated with @Asynchronous
          - Method parameters fully anotated as needed (see docu)

          class of bean with contains asynch method
          - fully annoted, also method params
          - may return a handler to pasue, resume and cancel the job

          calling bean
          - bean with asynch method must be injected by Interfsce via @In
          - call -> works

          Greetz GHad

          • 2. Re: Asynchronous JavaBean method not getting called
            damianharvey

            Thanks for replying.

            - Components.xml has async:timer and namespace
            - I'm not using an EJB bean, I'm using a JavaBean (see the mail example). So I don't have an interface.
            - My method is annotated with @Asynchronous

            Thanks,

            Damian.

            • 3. Re: Asynchronous JavaBean method not getting called
              pmuir

              In Seam 1.3 its core:timer.

              • 4. Re: Asynchronous JavaBean method not getting called
                damianharvey

                Oops. Thanks Pete.

                • 5. Re: Asynchronous JavaBean method not getting called
                  gbc1

                  Hello damianharvey,

                  as far as i know, an asynchronous call will only work if called by interface:

                  I had a Stateless SessionBean with an annotated asynchronous Method being calld via

                  ...
                  new StatelessSessionBean().asynchMethod();
                  ...
                  


                  and i didn't work, so I changed to:
                  ...
                  @In(create=true) StatelessSessionBeanLocal statelessSessionBean;
                  
                  public void someMethod() {
                   statelessSessionBean.asynchMethod();
                  }
                  


                  and it works.

                  So...

                  - Make class a Seam Component with @Name
                  - Try adding an Interface (even if not needed anywhere else) with annotated method
                  - Use @In at calling side to let seam inject the class
                  - You may add @Scope(ScopeType.SESSION) to the class

                  Good luck, just sharing my expiriences...

                  Greetz, GHad