2 Replies Latest reply on Jun 10, 2007 11:10 AM by suatkaya

    Issuing Commands to a Running Process

    suatkaya

      Hi,

      For some reason, my stateless session bean starts a long running "process" (not in OS terms) like this code:

      private @Resource SessionContext sctx;
      .....
      sctx.getTimerService().createTimer(1, obj);
      


      The long running process is in timer code. And it creates a Queue object and gives it a JNDI name like this:

      @Timeout
       public void timeoutHandler(javax.ejb.Timer timer)
       {
       InitialContext inictx = new InitialContext();
       this.commandQueue = new ConcurrentLinkedQueue<SomeMsg>();
       inictx.bind("CmdQueue", this.commandQueue);
       }
      


      And this created queue is used to accept commands from other session beans, like this:

      SomeMsg msg = this.commandQueue.poll();
      


      And then acts accordingly. Other session beans can send a message to this process like the following:

      InitialContext ctx = new InitialContext();
      Queue<SomeMsg> queue = (Queue<SomeMsg>) ctx.lookup("CmdQueue");
      queue.add(msg);
      


      And the process unbinds the name before finishing.

      Are there any pitfalls in this approach?

        • 1. Re: Issuing Commands to a Running Process
          alrubinger

          What is your desired behaviour if a session bean attempts to send a message to this Queue after it becomes unbound at the end of the timer process?

          If "gets an exception and handles it gracefully" is what you want, this looks valid. You're creating a handler that will be available for a timed window that you specify, it looks.

          S,
          ALR

          • 2. Re: Issuing Commands to a Running Process
            suatkaya

             

            "ALRubinger" wrote:

            If "gets an exception and handles it gracefully" is what you want, this looks valid. You're creating a handler that will be available for a timed window that you specify, it looks.


            Exactly.