6 Replies Latest reply on Oct 16, 2009 1:15 PM by bedek_bedkowski

    QuartzTriggerHandle is null

      Hi,


      I've problem with quartz asynchronous method.

      The task is starting and it runs every second as configured the problem is that only in method startClockBeat of clockTest component timer object is not null but in pauseClockBeat and resumeClockBeat it is null.


      This is interface of component which is using quartz timer:


      @Local
      public interface ClockTest {
           public void startClockBeat();
           public void resumeClockBeat();
           public void pauseClockBeat();
           public void remove();
      }



      This is implementation of above interface:


      @Stateful
      @Name("clockTest")
      public class ClockTestImpl implements ClockTest {
           
           @Logger
           Log log;
           
           @In
           ClockBeat clockBeat;
           
           private QuartzTriggerHandle timer;
           
           @Override
           public void startClockBeat() {
                log.debug("In start clock.");
                Long clockTickInterval = 1000L;
                timer = clockBeat.clockTick(clockTickInterval);
                if(timer == null) {
                     log.error("In start: 'timer' is null.");               
                } else {
                     log.debug("In start: 'timer' is not null.");               
                }          
           }
           
           @Override
           public void pauseClockBeat() {
                if(timer == null) {
                     log.error("In pause: Timer is null.");
                     return;
                }
                try {
                     timer.pause();     
                } catch (SchedulerException e) {
                     log.error("In pause: Scheduler exception: ", e.getMessage());
                }          
           }
           
           @Override
           public void resumeClockBeat() {
                if(timer == null) {
                     log.error("In resume: Timer is null.");
                     return;
                }
                try {
                     timer.resume();     
                } catch (SchedulerException e) {
                     log.error("In resume: Scheduler exception: ", e.getMessage());
                }          
           }
           
           @Override
           @Remove
           public void remove() {          
           }
      }



      This is my quartz component interface:


      @Local
      public interface ClockBeat {
           
           @Asynchronous
           public QuartzTriggerHandle clockTick(@IntervalDuration Long interval);
      }



      This is my quartz component implementation:


      @AutoCreate
      @Name("clockBeat")
      @Stateless
      public class ClockBeatImpl implements ClockBeat {
      
           @Logger
           Log log;
      
           public QuartzTriggerHandle clockTick(@IntervalDuration Long interval) {
                log.debug("Clock ejb beat time: {0}", new Date());
                return null;
           }
      }



      I've xhtml with 3 buttons - start / pause / resume, when I click on:




      1. start - (bound with startClockBeat() method) - In start: 'timer' is not null.

      2. pause - (bound with pauseClockBeat() method) - In pause: 'timer' is null.

      3. resume - (bound with resumeClockBeat() method) - In resume: 'timer' is null.





      Why is it so that only one method have not null "timer" and the rest of them null?

      How can I control "timer" form other method then the method in which it's started?