9 Replies Latest reply on Aug 27, 2002 12:42 PM by Renaud Bruyeron

    Dynamic scheduler....

    fred Newbie

      I wrote an API to allow people to create a new scheduled task. The differences with what Andreas Schaefer wrote are:

      1/ The task parameter are loaded from a database (as opposed to jboss.jcml), and started when the server start.
      2/ When a task is created it is saved into the DB, therefore it will be restarted when the server start again
      3/ If you stop a task it will be deleted from the DB

      This scheduler is more dynamic than the previous one, and enable developer to write an interface so the end-user can stop or start a task.

      YOu can find the code into the Test Forum section of this site. (dunno why but i couldn't post anything in this section, probably because the answer URL made by the server was too long...)

      the Database looks like:

      CREATE TABLE [creditderivative].[scheduledTasks] (
      [name] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
      [start] [datetime] NULL ,
      [howOften] [bigint] NULL ,
      [state] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
      [notificationId] [int] NULL ,
      [taskClass] [varchar] (200) COLLATE Latin1_General_CI_AS NULL
      ) ON [PRIMARY]
      GO

      the code needs to be compiled with:
      jboss-j2ee.jar
      jboss.jar
      jdbc.jar
      jmxri.jar
      log4j.jar

      need to add:

      to jboss.jcml

      if anybody is interrested I will make something more user friendly and working closer to the JBoss infrastructure.

      Cheers.

        • 1. TimedObject in EJB 2.1 Draft
          Thomas Laresch Newbie

          Frederic,

          You might be interested in reading "What's New in EJB 2.1" to see what's planned for a new timer service, which allows enterprise beans to register for timed events.
          http://www.theserverside.com/resources/article.jsp?l=MonsonHaefel-Column1

          Perhaps you might want to structure your efforts to follow the proposed interface?

          Good luck with your efforts!

          - Tom

          • 2. Re: Dynamic scheduler....
            Thomas Laresch Newbie

            Frederic,
            There appears to be a mismatch between the instructions above and the posted code.
            Line above reads:
            we need to add:
            <mbean code="com.lombardrisk.f3.scheduler.TaskStarter" name="DefaultDomain:service=TaskStarter" />

            But the code you posted is in a different package:
            net.dairdeville.scheduler.TaskStarter

            Regards,
            - Tom L.

            • 3. Re: Dynamic scheduler....
              fred Newbie

              Tom,

              I did this job for my company and quicly change the name of the package. This is a mistake, the correct name is net.dairdeville.TaskStarter. What it does is simply call an MBean responsable to read the database and start each task mentionned in it.

              If you want to run this program you will also have to provide a datasource accessible via JNDI or change the database access. (All is into the Scheduler class).

              If I got some time I will change that to be more user friendly.

              Thank you for your feedback anyway.

              • 4. Re: Dynamic scheduler....
                Thomas Laresch Newbie

                Frederic,
                I appreciate your sharing your efforts. I notice you posted the bean but not the accompanying EJB classes, so I assumed you are using XDoclet.

                I decided to bite the bullet and learn how to use the XDoclet tool, but then I found I couldn't even get their samples to compile after spending a lot of time playing around with it.

                If you could, would you please post the generated EJB files so I can try to use your code?

                Thanks!
                - Tom

                • 5. Re: Dynamic scheduler....
                  fred Newbie

                  I will have some time to make something that will fit better into JBoss. For the time being you still have to create the database and change the way it access the datasource whithin the code...

                  I attach the file with the test included

                  • 6. Re: Dynamic scheduler....
                    Andreas Schaefer Apprentice

                    Hi Geeks

                    You were just a little bit faster than I. I just recently started to create a new Scheduler which uses a ScheduleProvider which is another MBean. This MBean can add any number of schedules to the Scheduler. The provider can also specify the target.

                    The EJB timer is maybe fine to time EJBs but it will for sure not work fine for MBeans and you need an EJB container to use it but JBoss is more than just an EJB container and many people use it w/o it.

                    Have fun - Andy

                    • 7. Re: Dynamic scheduler....
                      june Newbie

                      Your dynamic scheduler is great. But some error occur after I change to access the database with EJB.
                      Parts of message is:
                      Exception in Scheduler
                      java.lang.ClassNotFoundException: com.tech1system.spim.entity.scheduletask.Sched
                      uleTaskHomeInterface (no security manager: RMI class loader disabled)
                      at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:521)
                      at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:6
                      37)
                      at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:309
                      )

                      Can it be solved?

                      • 8. Re: Dynamic scheduler....
                        fred Newbie

                        Forget about this scheduler, Andreas Shaeffer prodided a new one that is dynamic as well.
                        I asked the jboss forum guys to remove this code but they didn't. (dunno why ?)

                        Look at org.jboss.varia.scheduler it is a good implementation that fit better with jboss. (much more complicate though...)

                        • 9. Re: Dynamic scheduler....
                          Renaud Bruyeron Newbie


                          Andy,

                          any reason for the comments around line 699 of the ScheduleManager ?

                          mNotificationID = ( (Integer) getServer().invoke(
                          mTimer,
                          "addNotification",
                          new Object[] {
                          "Schedule",
                          "Scheduler Notification",
                          null, // User Object
                          lStartDate,
                          new Long( mPeriod ),
                          /* why is this commented out ?
                          infinite loop does not work as is */
                          // mRemainingRepetitions < 0 ?
                          // new Long( 0 ) :
                          new Long( mRemainingRepetitions )
                          },
                          new String[] {
                          String.class.getName(),
                          String.class.getName(),
                          Object.class.getName(),
                          Date.class.getName(),
                          Long.TYPE.getName(),
                          Long.TYPE.getName()
                          }
                          ) ).intValue();

                          As is, the MBean throws a RuntimeMBeanException if I use the SingleScheduleProvider with -1 because the Timer.addNotification() does not like negative occurences...

                          - Renaud