2 Replies Latest reply on Apr 30, 2008 5:59 AM by zahidmaqbool

    Seam TimerServiceDispatcher - 3 days of wasted time

    zeppelinux.dmitry.diligesoft.com

      I needed some scheduling support in my web application so i decided to use the Seam for it.


      First i refactored the web app (was deloyed as war) to run in the EJB container (to be deployed as ear on Glassfish).
      After (it took some time) to figure out that Seam always returns 'null' instead of timer and moreover the standard @Resource for EJB Timer doesn't work in the stateless bean that is a Seam component.

      After that i tried the Quartz Seam integration - the same result, - handler always 'null'.
      I blamed the EJB container and refactored the application back to war hopping to use Quartz hadlers (as in the seam examples) without any EJB stuff - no luck.
        
      Then i installed JBoss 5 beta 4 and the outcome was even more disappointing - Seam booking example claimed to run out of the box even can't be deployed, it fails on :
      java.lang.RuntimeException: mapped-name is required for timerService of deployment TimerServiceDispatcher


      The problem is not new:


      http://www.seamframework.org/Community/SeamExamplesOnJBoss5beta4


      Finally implemented needed functionality by using plain Java executors.


      I'm a bit pissed off, looks like Seam is not there yet, i.e. it is very dangerous to design applications taking only the Seam manual into account, - each future must be prototyped and well tested.


        • 1. Re: Seam TimerServiceDispatcher - 3 days of wasted time
          zahidmaqbool

          What problem are you getting in using quartz handler. Seam has built in support for it. I have used quartz with seam quite successfully. If you require any help on this let me know

          • 2. Re: Seam TimerServiceDispatcher - 3 days of wasted time
            zahidmaqbool

            Notihng extra to use it as far as I remeber, just the qurtz library should be there, here is a piece of code:



            @Name("asyncDownloader")  
            @AutoCreate
            public class AsyncAFSDownloader {
            
                 
                 @Asynchronous
                 @Transactional
                 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");
                      
                      ExtractAFSFileContents eafs = new ExtractAFSFileContents();
                      ArrayList<AFSStatus> afsList = eafs.getExtractedContents("C:\\CCAPS_LOGS\\test.txt");
                      if(afsList!=null)
                      {
                           for(int i=0; i<afsList.size(); i++)
                           {
                                AFSStatus afsStatus = afsList.get(i);
                                int code=0;
                                if(afsStatus.getStatus().equalsIgnoreCase("Success"))
                                {
                                     code=1;
                                }
                                afsc.updateAFSStatus(afsStatus);
                                signalState("AFS-Response", "/to Send-To-AFS", String.valueOf(afsStatus.getApplicationNo()), code);
                           }
                      }
                      
                      return handle;
                 }




            And here is the code which starts this:




            @Name("asyncAction")
            public class AsyncAFSAction {
                 
                 @In AsyncAFSDownloader asyncDownloader;
                 @In
                private FacesMessages facesMessages;
            
                 public void startAsyncTest()
                 {
                      try
                      {
                           
                      // Schedule the task in the business logic processing code
                      // Starts now, repeats every hour, and ends on May 10th, 2010
                      Calendar cal = Calendar.getInstance ();
                      cal.set (2040, Calendar.MAY, 10);
                      if(Contexts.getApplicationContext().get("afsScheduler")==null)
                      {
                           QuartzTriggerHandle handle = asyncDownloader.schedulePayment(new Date(), 2*60*60*1000L, cal.getTime());
                           Contexts.getApplicationContext().set("afsScheduler", handle);
                           facesMessages.add("Scheduler Successfully Started", "Scheduler Successfully Started");
                      }
                      else
                      {
                           facesMessages.add("Scheduler Already Started", "Scheduler Already Started");
                      }
                      }
                      catch(Exception e)
                      {
                           facesMessages.add("There was a problem in starting the scheduler or it is already started, check the log files", 
                                     "There was a problem in starting the scheduler or it is already started, check the log files");
                      }
                 }
            }