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

    Can the Scheduler call code in a EAR?

      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?
          dan-b

          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?

            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?
              dan-b

              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?

                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?

                • 5. Re: Can the Scheduler call code in a EAR?
                  dan-b

                  Yes, I do

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

                    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?

                      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?
                        dan-b

                        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?
                          dan-b

                          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?

                            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?

                              Dan,

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

                              Thanks.

                              • 12. Re: Can the Scheduler call code in a EAR?
                                dan-b

                                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?

                                  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?
                                    sikkandarraja

                                    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>