6 Replies Latest reply on Jul 23, 2002 8:59 AM by fred

    API to hot deploy scheduled service...?

    fred Newbie

      Hi,

      Our application needs an API that will allow to add a scheduled service at runtime.

      for example: add a service that send a report every day, but whithout restarting the server.

      So the API will have a method like
      addService(Class className, Method methodName, int howOften)
      or something like that... and a stopService() method as well and so forth.

      then this API will be linked to a gui, and the end user will then be able to start a scheduled service.

      I started implementing something like that with JMX, but before going any further I would like to know if anybody have worked on something similar, or if someone think this will be useless because there's other way to achieve this.

      any ideas ?

        • 1. Re: API to hot deploy scheduled service...?
          marc fleury Master

          Yeah,

          package your service as a SAR and drop it in the deploy directory that will deploy it dynamically (without the restart) then you can safely remove it by removing the file. Or you can call the MainDeployer (available through JMX) to dynamically deploy an URL you feed it.

          Basically the deploy directory scanner is a wrapper around that JMX internal API deployment,

          Dig around in the base distribution and you will figure it out,

          good luck

          • 2. Re: API to hot deploy scheduled service...?
            fred Newbie

            Ok, I'll look in this direction.

            But one of the main requirement is to enable this deployment to be used by the end user, and I'm not expecting them to drop a jar in the deploy directory.

            The idea was to have this API used by the web developer to build a GUI around it, so the end user could change the time or create a service via few clicks...

            I'll have a close look at deploying a service via a URL.

            Thanks.

            • 3. Re: API to hot deploy scheduled service...?
              David Jencks Master

              If the new services need new classes then you need to investigate the MainDeployer.deploy or the deployment scanner. If all the classes are already present and you just need to set up running something periodically I think the Scheduler mbean may do what you want. Look in varia/output/lib/ for scheduler-plugin

              • 4. Re: API to hot deploy scheduled service...?
                fred Newbie

                I thought of a new MBean for each new task, and add a Notification to the Timer MBean to the newly created MBean.
                Then at notification the new MBean will call the service and perform the required task.
                Like that the agent would remain fairly simple.

                If the classes are not present than I'll use the MainDeployer, but as a first instance I'll suppose all the classes are present.

                we also need at startup to load all the task from the database, and save the task as well. So I'll start implementing something like that.

                If someone got any comment or is interrested by this service...

                • 5. Re: API to hot deploy scheduled service...?
                  fred Newbie

                  I wrote an API to allow people to create new scheduled tasks. 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.

                  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.

                  • 6. Re: API to hot deploy scheduled service...?
                    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.