14 Replies Latest reply on Mar 15, 2016 3:03 AM by sikkandar raja

    Can the Scheduler call code in a EAR?

    Jeremy Levy Newbie

      I am using the varia mbean Scheduler to call some code to perform some clean up on a scheduled interval. It seems that the code that the Scheduler can only acesss classes that are in the server/lib directory and not code that exists within a deployment... Is there a way around this? Can I include my mbean scheduler xml inside my ear?

      Thanks

      Jeremy

        • 1. Re: Can the Scheduler call code in a EAR?
          Dani Belz Newbie

          Hi Jeremy,

          I guess the problem is that when the scheduler service
          starts (at JBoss startup?), there is no deployment as EARs
          are deployed later on. This is the problem I also have. I want
          the scheduler to call a class that is in my deployment. A dirty
          workaround is to start JBoss to let the EAR be deployed, then
          open scheduler-service.xml within the deployment directory,
          make a little change (add a new line), save and close. The
          scheduler service is now able to find the specified class and
          can be started.

          My question (in addition to yours) is: can I add a scheduler-service.xml
          or something like that to my EAR to make the scheduler service
          start when my EAR is deployed and stop when it is undeployed?

          Thanks!
          -Danny

          • 2. Re: Can the Scheduler call code in a EAR?
            Jeremy Levy Newbie

            Weird, I tried deploying the scheduler-service.xml after my EAR deployed, but it still didn't see those classes. It only seems to work for me if the class that the scheduler calls is exists in a jar in the lib directory...

            • 3. Re: Can the Scheduler call code in a EAR?
              Dani Belz Newbie

              Now that is really weird. I have the following in the
              scheduler-service.xml:

              <?xml version="1.0" encoding="UTF-8"?>
              <!DOCTYPE server>
              <!-- $Id: scheduler-service.xml,v 1.6 2004/09/02 05:37:26 telrod Exp $ -->
              
              <server>
               <mbean code="org.jboss.varia.scheduler.Scheduler"
               name=":service=Scheduler">
              
               <attribute name="StartAtStartup">true</attribute>
               <attribute name="SchedulableClass">net.danb.TimeoutTrigger</attribute>
               <attribute name="InitialStartDate">NOW</attribute>
               <attribute name="SchedulePeriod">1000</attribute>
               <attribute name="InitialRepetitions">-1</attribute>
               </mbean>
              </server>
              


              This class (net.danb.TimeoutTrigger) is in my EAR file. So when JBoss
              starts, it cannot be found. But the class is deployed with my EAR and
              after a

              $ touch $JBOSS_HOME/server/default/deploy/scheduler-service.xml
              


              it is reloaded and finds that class... Is there any error message?

              • 4. Re: Can the Scheduler call code in a EAR?
                Jeremy Levy Newbie

                I added the scedulable classes to my EJBs and I tried deploying just my EJBs (w/o the EAR). The scheduler was then able to find the class. However when the same EJB jar packaged in a EAR the scheduler is not able to find the classes...

                Are you deploying your application as a EAR?

                • 6. Re: Can the Scheduler call code in a EAR?
                  Jeremy Levy Newbie

                  I assume your schedulable classes are in your ejb jar in your ear right..

                  appreciate your help.

                  • 7. Re: Can the Scheduler call code in a EAR?
                    Jeremy Levy Newbie

                    What does you application.xml look like? Here is mine...

                    <?xml version="1.0" encoding="UTF-8" ?>
                    - <application version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
                     <display-name>MyApp</display-name>
                    - <module>
                    - <web>
                     <web-uri>MyApp-WebModule.war</web-uri>
                     <context-root>/MyApp-WebModule</context-root>
                     </web>
                     </module>
                    - <module>
                     <ejb>MyApp-EJBModule.jar</ejb>
                     </module>
                     </application>


                    • 8. Re: Can the Scheduler call code in a EAR?
                      Dani Belz Newbie

                      Yes, that's true. I use XDoclet, to generate the EJB classes. These are
                      in a seperate directory. In my Ant "compile" task, I compile every Java
                      file in both directories to one directory. I create a jar and put this jar into
                      my ear which in turn is then deployed to my server. Did you check your
                      ear to make sure the class is really there?

                      • 9. Re: Can the Scheduler call code in a EAR?
                        Dani Belz Newbie

                        Here's my application.xml:

                        <?xml version="1.0" encoding="UTF-8"?>
                        
                        <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>
                        
                        <application>
                         <display-name>MyApp</display-name>
                         <description>some useful information</description>
                         <module>
                         <ejb>myapp-core.jar</ejb>
                         </module>
                        </application>


                        I don't have a web UI and therefore no web module...


                        • 10. Re: Can the Scheduler call code in a EAR?
                          Jeremy Levy Newbie

                          Hmm, no real difference in application.xml. The class does exist and the path to it is correct in my scheduler. Here it is btw:

                           <mbean code="org.jboss.varia.scheduler.Scheduler"
                           name=":service=UsersTimeoutScheduler">
                           <attribute name="StartAtStartup">true</attribute>
                           <attribute name="SchedulableClass">com.myapp.external.schedule.TimeoutScheduler</attribute>
                           <attribute name="InitialStartDate">NOW</attribute>
                           <attribute name="SchedulePeriod">60000</attribute>
                           <attribute name="InitialRepetitions">-1</attribute>
                           </mbean>


                          Strange that it works if I deploy my ejbs outside of my ear file... Seems that inside my EAR they are not allowed to be accessed...



                          In regards to the issue you are having I was thinking about using a depends in the scheduler mbean, but I'm not sure what the syntax would be...


                          • 11. Re: Can the Scheduler call code in a EAR?
                            Jeremy Levy Newbie

                            Dan,

                            Last question, are you using a Schedulable class or Schedulable Mbean?

                            Thanks.

                            • 12. Re: Can the Scheduler call code in a EAR?
                              Dani Belz Newbie

                              Hi Jeremy,

                              you use

                              name=":service=UsersTimeoutScheduler"
                              .

                              That's the only difference I see. Maybe this causes the trouble?
                              To your question: I use a Schedulable class.

                              public class TimeoutTrigger implements Schedulable {
                               public void perform(Date timeOfCall, long remainingRepetitions) {
                               // my timeout action
                               }
                              }


                              I have no idea how to implement a Schedulable MBean =)



                              • 13. Re: Can the Scheduler call code in a EAR?
                                Jeremy Levy Newbie

                                Well, I could never get the service to find the files in my EAR, I have a feeling it may be some sort of secuity issue or nested archive thing... Very strange.

                                Anyways I was able to get it to work if I created a SAR archive, put in the necessary classes for the timer and included a jboss-service.xml (with the timer Mbean in it). I include the SAR file in the top level of my EAR.

                                Now to get it to work I added a just had to add this to my jboss-app.xml:

                                <jboss-app>
                                 <module>
                                 <service>timers.sar</service>
                                 </module>
                                 </jboss-app>



                                Now the timer starts when the EAR is deployed... Help this helps.

                                • 14. Re: Can the Scheduler call code in a EAR?
                                  sikkandar raja Newbie

                                  JBoss 6.1


                                  ear-deployer-jboss-beans.xml


                                  Located in your JBoss installation's server\default\deployers directory.

                                  Set the Isolated property to false:

                                  <property name="Isolated">false</property>