9 Replies Latest reply on Jul 4, 2008 9:24 AM by Damien

    SchedulableMBean arguments

    Stratos Pavlakis Newbie


      There is a detail of the ScheduleManager implementation that troubles me.
      I ll give u a short description of what I want to do.

      I want to run a ScheduleManager + Provider as a Singleton in a cluster. A client will be able to register schedules on the provider from any node on the cluster using HA-JNDI as I will expose an RMIAdaptor interface of the Provider MBean. The ScheduleProvider (i have made a custom one) provides the ScheduleManager with schedules. The manager in turn, notifies a target object (Mbean) , whenever the schedule demands , and calls an appropriate method on the target object. As you can see I wont use xml to describe the scheduling parameters for my custom Provider (start date etc) but every client request on the Provider will register a schedule with its own parameters.

      The only example I ve found so far is this http://www.onjava.com/pub/a/onjava/2003/08/20/jboss_clustering.html?page=2

      As you can see it uses the SingleScheduleProvider which comes with Jboss.
      It defines the attribute :

      which refers to the method + arguments of the target object.

      The target object is SchedulableMBeanExample which also comes with Jboss.

      Ok, here is my problem. As you can imagine I dont wanna use SchedulableMBeanExample as my target in my own application. So what do I have to do? I have to write my own MBean. So far so good. I thought so as well but when I checked the scheduler package source code i came up with this :

      If u spend some time and check the code (inner class MBeanListener) u ll see that it takes under consideration only some predefined arguments for the target object's method (ID,NOTIFICATION,DATE ...) and sets all others to Null!

      When I saw that, I went back to the given example and noticed that the example's target (SchedulableMBeanExample) takes an extra argument. A simple String. Well, ScheduleManager ignores that as well.

      I dont know how to move on now... I want my SchedulableMbean's target method to take some custom arguments but all I see is a list of predefined ones.

        • 1. Re: SchedulableMBean arguments
          Stratos Pavlakis Newbie

          I found the following definition for target method argument of the SimpleScheduleProvider. Should be the same for the other providers as well.


          Target Method
          Defines the method on the Target that is invoked by the Manager when a timed notification is handled. It starts with the method name, optionally followed by a list a parameters in brackets. Predefined parameteres are:

          * ID: Schedule Instance Id
          * NOTIFICATION: JMX Notification (Event) that is send by the JMX Timer Service
          * DATE: Current Date (and time)
          * REPETITIONS: Remaining Repetitions or -1 if no limit is set
          * SCHEDULER_NAME: Service Name of the Schedule Manager
          * NEXT_DATE: Expected Date of the next timed notification

          any other parameter is treated as class name that is used to look up the method and the Schedule Manager will provide a null value.


          Isnt that an extremely static and inflexible implementation? For example if I want a schedule to add a certain number to another already known number, then I just cant pass the first number as an argument. I have to make 1 Mbean or Schedulable Class for every different number I may want to add.

          For now my only solution is to extend the ScheduleManager and override some of its methods so that I permit custom parameters propagation from the provider to the target object.

          • 2. Re: SchedulableMBean arguments
            Damien Newbie

            Hi thehunt, could you please post some codes as I'm interested too in your use case.

            I've got same problem as I want to execute task with specific parameters.

            Does your solution replicate task on all nodes when the "master" node going down ??

            • 3. Re: SchedulableMBean arguments
              Stratos Pavlakis Newbie

              Hi dmary. Actually I found a solution to this and implemented the project. I ll need to dig a bit as its 2 years old now, to find the specific chunks of code you are interested in. I hope i send em to you some time tomorrow.

              As far as the fail over behaviour, provider and manager are instantiated but not started on all but the master node (on which their are started ofc). All tasks are placed in a shared cache (Jboss cache), and those which have already been fired are also placed inside a queue. Every node has a Message-driven EJBs pool, reading from this queue, and thus actually executing the scheduled task. When the master node is going down, another random node acts as the the master, starting its already instantiated provider and manager, re-registering all tasks which can easily be found in the shared cache. I don't provide a solution, as it was an experimental project, to the problem arising from the tasks already executing on a node, when the node fails.

              For a better overview of the project check this


              • 4. Re: SchedulableMBean arguments
                Damien Newbie

                thks a lot for ur response, two years after ;)

                I'm trying actualy , a little bit the same way , but for moment with db provider.

                I was also thinking about JbossCache as I use it in other parts.
                I was wondering what is the goods and bads between JbossCache and a database .

                One good point for database, is that all tasks are persistents, but when one node is broken, the order node take only the tasks which contains a date after the actual date, lets see my sql request I used in MySql:

                SELECT target, method_name, method_signature, start_date, period,
                repetitions, date_format FROM Schedule where start_date>NOW()

                Nice trick ?!

                How do you make that with JbossCache ? do u take all task in cache and look at the date parameter if it is superior ??
                and how do you "clean" the cache with executed tasks ?


                • 5. Re: SchedulableMBean arguments
                  Stratos Pavlakis Newbie

                  np. ur welcome.

                  JbossCache doesn't exclude the use of a database. The question is... the exact use of each. For example, database can be used only for persistence in case of a general power failure or system restart, but not for failover. Don't forget that if you use a non High Availability clustered database, then you still have a 1-point failure node. If your db server crashes, then so does all your system.

                  Let me search a little bit this weekend to refresh my memory and I ll send you whatever info i believe you ll find useful. In the meantime, check the url I posted previously and tell me what exactly is the purpose of your job scheduling app? To be accurate, to handle vast number of schedules, to be lossless? To execute many small jobs or fewer cpu-memory hungry jobs? You need clustering for High Availability or Load Balancing or both? I am asking these because I didn't find a do-it all in one solution :) For example if you use synchronized cache, and as every node added to the cluster brings a hell of a lot network traffic for cache synchronization, the bottleneck appears to be the network and not the Timer itself.

                  • 6. Re: SchedulableMBean arguments
                    Damien Newbie

                    well I aims at execute many small jobs which needs few cpu.

                    I see your post and finaly, I'm not far from you.

                    The difference is that I've got a JMX target in addition, like it is written here : http://www.madplanet.com/jboss-docu-wiki/Wiki.jsp?page=40.Utilities.Scheduler

                    But this JMX target, simply put parameters in a queue with messageselector properties (I've got one MDB for one type of task), and the logic (EJB3) is called in this queue.

                    I like the concept of queue, as it is asynchronous, can be load balanced, and there is no dependency between JMX and queue.

                    • 7. Re: SchedulableMBean arguments
                      Damien Newbie

                      just one question, what do u do of the task which has been pushed into cache, after his execution ?
                      do u deleted it ? how ? just after push it into queue ?

                      • 8. Re: SchedulableMBean arguments
                        Damien Newbie

                        and another question :)

                        how do you add one task only ? put into cache and call a new method to add task into provider which call manager to put into timer ?