7 Replies Latest reply on Apr 21, 2008 5:56 AM by rabbiaqaswar

    Schedulable & jboss-service.xml

    rabbiaqaswar

      Hello

      I am trying to use the Scheduler service provided by JBoss 4.2.2 GA. Here is how the scheduler-service in default/deploy directory looks like:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <server>
      
       <mbean code="org.jboss.varia.scheduler.Scheduler" name=":service=Scheduler">
       <attribute name="StartAtStartup">true</attribute>
       <attribute name="SchedulableClass">org.schedular.MySchedular</attribute>
       <attribute name="SchedulableArguments">TheName,123456789</attribute>
       <attribute name="SchedulableArgumentTypes">java.lang.String,long</attribute>
       <attribute name="InitialStartDate">NOW</attribute>
       <attribute name="SchedulePeriod">1000</attribute>
       <attribute name="InitialRepetitions">5</attribute>
       <depends>
       <mbean code="javax.management.timer.Timer"
       name="jboss:service=Timer"/>
       </depends>
       </mbean>
      
      </server>
      


      and here is the Scheduler class:

      package org.schedular;
      
      import java.util.Date;
      import org.jboss.varia.scheduler.Schedulable;
      
      public class MySchedular implements Schedulable {
      
       private String name;
       private long value;
      
       public MySchedular(String name, long value) {
       this.name = name;
       this.value = value;
       System.out.println("ctor, name: " + name + ", value: " + value);
       }
      
       public void perform(Date now, long remainingRepetitions) {
       System.out.println("perform, now: " + now +
       ", remainingRepetitions: " + remainingRepetitions +
       ", name: " + name + ", value: " + value);
       }
      }


      This MySchedular is part of an ejb-module of the application so I have to place it inside the jar file containing all the ejbs. Now the problem is that when i start JBoss it gives the following error:
      [Scheduler] Failed to find: org.schedular.MySchedular
      java.lang.ClassNotFoundException: No ClassLoaders found for: org.schedular.MySchedular
      --- MBeans waiting for other MBeans ---
      ObjectName: jboss:service=Scheduler
       State: FAILED
       Reason: org.jboss.deployment.DeploymentException: Exception setting attribute javax.management.Attribute@d006a7 on mbean jboss:service=Scheduler; - nested throwable: (java.security.InvalidParameterException: Given class org.schedular.MySchedular is not not found)
      


      When the jar file containing MySchedular is deployed, JBoss deploys it successfully. But the perform method in MySchedular is not executed. Now while the server is running, i make any changes like add an empty line in the scheduler-service.xml and save it, MySchedular perform method is invoked showing:

      INFO [STDOUT] ctor, name: TheName,value: 123456789
      INFO [STDOUT] perform, now: Sun Apr 20 18:15:55 GST 2008, remainingRepetitions: 4, name: TheName,value: 123456789
      INFO [STDOUT] perform, now: Sun Apr 20 18:15:56 GST 2008, remainingRepetitions: 3, name: TheName,value: 123456789
      INFO [STDOUT] perform, now: Sun Apr 20 18:15:57 GST 2008, remainingRepetitions: 2, name: TheName,value: 123456789
      INFO [STDOUT] perform, now: Sun Apr 20 18:15:58 GST 2008, remainingRepetitions: 1, name: TheName,value: 123456789
      


      I cannot understand what am I missing here, please see if you can help.

      Thanks

        • 1. Re: Schedulable & jboss-service.xml
          jaikiran

          Looks like your scheduler service is starting before the jar containing the bean is deployed. Try adding a depends attribute the scheduler-service.xml to ensure that the scheduler starts after the bean is deployed. See this for more details http://wiki.jboss.org/wiki/HowCanAnMBeanDependOnASessionBean

          • 2. Re: Schedulable & jboss-service.xml
            rabbiaqaswar

            Hello

            Thanks for your reply. I tried the following:

             <mbean code="org.jboss.varia.scheduler.Scheduler" name=":service=Scheduler">
             <attribute name="StartAtStartup">true</attribute>
             <attribute name="SchedulableClass">org.schedular.MySchedular</attribute>
             <attribute name="SchedulableArguments">TheName,123456789</attribute>
             <attribute name="SchedulableArgumentTypes">java.lang.String,long</attribute>
             <attribute name="InitialStartDate">NOW</attribute>
             <attribute name="SchedulePeriod">1000</attribute>
             <attribute name="InitialRepetitions">5</attribute>
             <attribute name="FixedRate">true</attribute>
             <depends>
             <mbean code="javax.management.timer.Timer" name="jboss:service=Timer"/>
             </depends>
             <depends>jboss.j2ee:module=SchedularProject-ejb.jar,service=EjbModule</depends>
             </mbean>


            Now the scenario is:
            1. Start JBoss after making the above changes in scheduler-service.xml and start JBoss, it will give the same error.
            2. Deploy the jar file, the deployment will be successfull but the Scheduler is not invoked.
            3. Stop JBoss and start it again, the error will not come and the Scheduler works.

            How can I avoid the error in the first case i.e. when JBoss is started for the first time?

            Many Thanks

            • 3. Re: Schedulable & jboss-service.xml
              rabbiaqaswar

              Forgot to mention, I have also added the following in scheduler-service.xml above the mbean declaration:

              <classpath codebase="." archives="SchedularProject-ejb.jar"/>
              


              • 4. Re: Schedulable & jboss-service.xml
                jaikiran

                 

                1. Start JBoss after making the above changes in scheduler-service.xml and start JBoss, it will give the same error.
                2. Deploy the jar file, the deployment will be successfull but the Scheduler is not invoked.


                Do you mean that you are deploying the jar after the scheduler has started? When you are starting the server, is the jar as well as the scheduler-service.xml present in the deploy folder?

                • 5. Re: Schedulable & jboss-service.xml
                  rabbiaqaswar

                  When I start the server, the scheduler-service.xml is in the deploy folder but the jar is not. That is when JBoss gives an error. After I deploy the jar i.e. put the jar file in the deploy directory and then start JBoss then it works fine.

                  • 6. Re: Schedulable & jboss-service.xml
                    jaikiran

                     

                    "rabbiaqaswar" wrote:
                    When I start the server, the scheduler-service.xml is in the deploy folder but the jar is not. That is when JBoss gives an error. After I deploy the jar i.e. put the jar file in the deploy directory and then start JBoss then it works fine.


                    If you are not having the jar containing the org.schedular.MySchedular in the deploy folder when the scheduler is starting, then you are obviously going to get this exception.

                    Why are you not placing the jar in the deploy folder along with the scheduler-service.xml when the server is starting?


                    • 7. Re: Schedulable & jboss-service.xml
                      rabbiaqaswar

                      I understand your point :)

                      But sometimes when some change is made in the ejb module say a Session bean and the jar is re deployed to JBoss through Netbeans 6.1, it will not deploy the new jar for no obvious reason. Then we have to stop JBoss, remove the previous jar file from deploy folder manually. Start JBoss again and then deploy the modified jar through Netbeans.

                      With this Scheduler implementation, the above procedure will not work as JBoss is depending upon the jar before it starts. That is why I wanted to find some way to avoid this dependency.

                      Now I guess we will just have to make sure that the jar file is always in the deploy folder before starting JBoss.

                      Thanks a lot.