4 Replies Latest reply on Jan 12, 2007 3:57 AM by dimitris

    An example of EJB application using JBoss Scheduler/Timer

    forumer

      I'd appreciate if you could point me to an example of an implementation where an EJB in an application receives a periodic callback from a JMX Scheduler/Timer. How does this application registers itself with such scheduler?

      I configured a JMX scheduler and gave it the class name of an EJB of an application. But the problem is that Scheduler gets started before the application and I get an exception about not finding the class. I am not quite sure how to make the scheduler dependent on the application. There are a few posts to this effect, but they are not quite clear to me.

      I'd prefer a solution where each application registers itself with the scheduler as different applications can "come" and "go".

      I'd appreciate all suggestions.

      Thanks

        • 1. Re: An example of EJB application using JBoss Scheduler/Time
          thehunt

          The Scheduler works like that:

          It has a timer on which it subsribes filtered listeners. When the timer triggers, the appropriate listener catches the event and calls the predefined target class or mbean with some certain parameters. What you really want if i understood right, is to have your applications listen to the same timer events as the scheduler does. And you want to use the scheduler for that.

          There are 2 solutions as i can see it.

          The first one is based on being able to catch the timer events as the Scheduler itself does. This you can do by throwing away the Scheduler :) and use the Timer directly. You can set the Timer Mbean to start when jboss starts, and then your every application could implement the NotificationListener interface and subscribe to the timer through the JMX Server.

          for example:
          private ObjectName mTimer;
          mTimer = new ObjectName("jboss:service=Timer");

          mListener = new YourListenerClass();
          getServer().addNotificationListener(
          mTimer,
          mListener,
          new NotificationFilter(...),
          null
          );

          Check this out to see how the SchedulerManager works.
          http://docs.jboss.org/jbossas/javadoc/4.0.2/org/jboss/varia/scheduler/package-summary.html


          The second , easiest and best solution in my opinion is to make your scheduler's target class or mbean to place messages on a durable Topic, and then have your EJB applications subscribe on this Topic. So its MDB solution :)

          In order to do that, you ll have to read about the scheduler's target which can be defined in your jboss-service.xml, and how to develop a custom target (plain class or mbean). Check the JMS documentation for the Topic and how to develop topic subscribers.

          • 2. Re: An example of EJB application using JBoss Scheduler/Time
            forumer

            Thank you very much for taking the time to reply. I am going to try to get my arms around and implement your first suggestion.

            I suppose I'll register the EJB NotificationListener in the Servlet of that application. Is there a better place to do it?

            Thanks again!

            • 3. Re: An example of EJB application using JBoss Scheduler/Time
              iudoka

              Does this scheduler infrastructure have support for cron triggers?

              • 4. Re: An example of EJB application using JBoss Scheduler/Time
                dimitris

                Another possibility is to use the J2EE Timer Service (check the j2ee 1.4 spec).