2 Replies Latest reply on Nov 28, 2008 6:35 PM by Matt Drees

    Asynchronous problem when call via Component.getInstance()

    Grigoriy Tkachuk Newbie

      I trying to make mail sending with delay, but when I call method send(3000) via Component.getInstance() it look like system ignore annotation @Duration. What's wrong? And how to do that? If I call method from jsf form everything works fine. But I need call that method from postMessage().


      @Name("messageSender")
      @AutoCreate
      public class MessageHandlerBean {
      
          @In
          private EntityManager entityManager;
      
          private Callback callback;
      
          @Logger
          private Log log;
      
          private Stack<Client> stack;
      
      
          public void postMessage() {
              stack = new Stack<Client>();
              stack.addAll(entityManager.createQuery("select c from Client c").getResultList());
              callback = new Callback() {
                  public void next() {
                      if (!stack.isEmpty()) {
                          stack.pop();
                          ((MessageHandlerBean) Component.getInstance("messageSender")).send(3000);
                      }
                  }
              };
              stack.pop();
              ((MessageHandlerBean) Component.getInstance("messageSender")).send(3000);
      
          }
      
          @Asynchronous
          public void send(@Duration long delay) {
              log.info("test");
      
              //mail sending impl here
       
              callback.next();
          }
      
      }