3 Replies Latest reply on Jun 22, 2010 12:12 AM by dave2010

    Persitant Bean for the life of the application

    dave2010

      Hi


      I am new to Seam and j2EE in general. I am a bit lost on the concept and design of what I need to do. I have a set of dates on a database (these can be updated), When the date is reached, I want my site to automatically generate an email. My problem is how can i implement a scheduler bean that automatically checks perodically and (this bean have to be alway be alive whenever the server is active), does anyone have any insight or idea on how this can be achieved ?


      Regards, David

        • 1. Re: Persitant Bean for the life of the application
          kyatim

          You can use Quartz to do it.
          You have to develop a Seam component that start after Seam Init ( fired by the PostInitialization Event) that will start scheduled actions).


          See Seam doc for Seam / Quartz integration!

          • 2. Re: Persitant Bean for the life of the application
            lvdberg

            Hi,


            The Seam docs and examples contain very nice examples of the use of the Quartz timer service. This works like a charm.


            Create a bean which has the service you want to trigger every n-times.


            Give it a name with the Name Annotation : doSomethingHandler


            This service needs to have a method with the following signature:




            public QuartzTriggerHandle doWhatYouNeedToDo(@Expiration Date when,
                           @IntervalDuration Long interval, @FinalExpiration Date endDate) {
            
            
            /// Do what you need to do
            
            }



            That all there is!


            Leo




            The you need a piece of code which triggers this method:
            
            A simple  example:
            
            private QuartzTriggerHandle doSomething;
            
            
            ...
            doSomething = doSomethingHandlerdoWhatYouNeedToDo(when, interval, until);
            
            // Meaning when is the start date
            // Interval is once a day
            // untul is the end date
            
            



            You need the handle in another bean to start and stop the timer. If you look into the example you will see that the method has a return value of null, That doesn't mean it really returns a null. The interception is handled by Seam, which gets the real handle.


            Don't forget to configure the Quarts timer in components.xml !!





            <async:quartz-dispatcher  />
            







            • 3. Re: Persitant Bean for the life of the application
              dave2010

              Thanks, this has been very helpful


              Dave