1 2 Previous Next 25 Replies Latest reply on Aug 23, 2011 7:44 AM by ashok.ashok.k.vedainformatics.com Go to original post
      • 15. Re: Quartz Scheduling questions
        risenhoover

        Hi Zahid,


        My scheduling class is already in a different class. I added the @AutoCreate to it and it still doesn't work.


        Thanks for the tip, though.

        • 16. Re: Quartz Scheduling questions
          zahidmaqbool

          Ok try this:




          @Name("asyncDownloader")  
          @AutoCreate
          public class AsyncAFSDownloader {
          
               
               @Asynchronous
               @Transactional @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
               public QuartzTriggerHandle schedulePayment(@Expiration Date when,
               @IntervalDuration Long interval,
               @FinalExpiration Date endDate
               )
               {
               // do the repeating or long running task until endDate
                    AFSStatusController afsc = new AFSStatusController();
                    System.out.println("\n\n\n\n-------------------------------------" +
                              "Scheduler Started, Executing Job to Process AFS Response Downloader and State Progressor----------------\n\n\n\n");
                    QuartzTriggerHandle handle = new QuartzTriggerHandle("AFSTrigger");
                    
                    //do your processing here
                    
                    return handle;
               }
          }




          and this is the observer which calls it:




          @Transactional
          @Name("startupTesting")
          public class StartupTesting {
          
               @Logger
               private Log log;     
               @In AsyncAFSDownloader asyncDownloader;
          
          
               /**
                * This is called by seam after initialization
                * has finished.
                */
               @Observer("org.jboss.seam.postInitialization")
               public void observe() 
               {
                    try
                    {
                         log.info("Trying to Start Cron Job");
                         Calendar cal = Calendar.getInstance ();
                         cal.set (2040, Calendar.MAY, 10);
                         QuartzTriggerHandle handle = asyncDownloader.schedulePayment(new Date(), 60*1000L, cal.getTime());
                         
                    }
                    catch(Exception e)
                    {
                         e.printStackTrace();
                         log.info("Operation Failed");
                    }
                    log.info("Job Started");
          
               }
          
          }




          Just now managed to get Cron Job also working .. If you need any code reagrading that let me know

          • 17. Re: Quartz Scheduling questions
            zahidmaqbool

            I forgot to mention it should work without the Transaction annotation also. But I have used it cause I inject the JbpmContext, I removed other code for readibility

            • 18. Re: Quartz Scheduling questions
              risenhoover

              At last!  It works!  I moved the @Asynchronous, @Expiration, etc. tags to the Local Interface of the EJB and it started working.  I'm not sure why this makes a difference, but there it is.


              Thanks for all the help!

              • 19. Re: Quartz Scheduling questions
                j1.jonathan.m.clarke.dsl.pipex.com

                Hi All,


                I'm new to JBoss Seam. I'd like to use Quartz to invoke autonomous behaviour at startup, which is then contacted by numerous session beans throughout the life of the application. However, having followed the instructions of numerous forums, including this one, I'm still unable to get my asynched method scheduled. So,


                1. I have jboss-seam-2.0.2.GA and jboss-4.2.2.GA installed.


                2. I have used 'seam setup' and 'seam create-project' according to the standard instructions.


                3. My components.xml file includes:


                
                xmlns:async="http://jboss.com/products/seam/async"
                
                
                http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.0.xsd 
                
                
                <async:quartz-dispatcher/>
                
                



                4. My classes are:


                
                public class Processor {
                
                     
                
                    Integer fIndex = 0;
                
                     
                
                    @Asynchronous
                
                    public QuartzTriggerHandle doWork(
                
                        @Expiration Date aWhen, 
                
                        @IntervalDuration Long aInterval, 
                
                        @FinalExpiration Date aStoptime) {
                
                              
                
                        System.out.println("Ticking Over Processor");
                
                        System.out.println(fIndex.toString());
                
                        fIndex++;
                
                          
                
                        return null;
                
                    }
                
                }
                
                
                public class Initiator {
                
                         
                
                    Processor fProcessor = new Processor();
                
                     
                
                    @Observer("org.jboss.seam.postInitialization")
                
                    public void observe() { 
                
                                 
                
                        Calendar fCalendar = Calendar.getInstance();
                
                        fCalendar.set(2040, Calendar.MAY, 10);
                
                          
                
                        fProcessor.doWork(new Date(), 1000L, 
                
                            fCalendar.getTime());
                
                    }
                
                }
                
                



                They are intended to be POJOs, and there is no indication in the limited documentation that they should be further annotated for Seam.


                Am I doing anything obviously wrong? Many thanks for your time.

                • 20. Re: Quartz Scheduling questions
                  j1.jonathan.m.clarke.dsl.pipex.com

                  Sorry, I forgot to say that the only debug output is:


                  
                  INFO  [STDOUT] Ticking Over Processor
                  
                  INFO  [STDOUT] 0
                  
                  



                  This happens only once, indicating that the 'observer' functions as expected, but the scheduled method does not.


                  Also, the classes I've indicated above are the only ones I've implemented on top of the skeleton generated by 'seam create-project'


                  Thanks again.

                  • 21. Re: Quartz Scheduling questions
                    cpopetz

                    @Asynchronous (and virtually every other cool seam annotation) depends upon an interceptor which is only run on targets that are seam components.  So you can't do:


                    Processor fProcessor = new Processor();



                    but instead you should do:


                    @In Processor processor;



                    and annotate your processor class with:


                    @Name("processor")




                    • 22. Re: Quartz Scheduling questions
                      j1.jonathan.m.clarke.dsl.pipex.com

                      Brilliant! Thank you. In my naivety, I'd assumed that the @In annotation was associated only with UI-based injection, rather than injections based on a search through all framework contexts. I don't have a web development background, and it's certainly a bit of a mindset change. I had to add @AutoCreate to the Processor class, and @Scope(APPLICATION), in order preserve the state of fIndex, and it works fine. What I'm hoping to do, though, is to have several instances of the Processor class, each operating independently. However, with the @In Processor clause, in turn based on @Name(processor), doesn't that preclude instantiating more than one object of that class type? I'm hoping that the documentation will detail this, in due course, but it's struggling to drag itself away from the usual single instances that go with the trivial database table/session bean examples. 

                      • 23. Re: Quartz Scheduling questions
                        cpopetz

                        You are correct, you'll need to place your component in a shorter scope than application if you want to have more than one, or use a @Role.


                        I really recommend reading the reference docs front to back, twice.  In addition, Dan Allen's Seam in Action and Michael Yuan's Seam-book-with-a-really-long-title-that-I-can't-remember are both excellent.  In particular, if you haven't worked in web frameworks before, Seam is going to bite you if you don't read up.

                        • 24. Re: Quartz Scheduling questions
                          j1.jonathan.m.clarke.dsl.pipex.com

                          Will do. Thanks for your help.

                          • 25. Re: Quartz Scheduling questions
                            ashok.ashok.k.vedainformatics.com

                            Thanks Daniel, your reply saved my time.

                            1 2 Previous Next