5 Replies Latest reply on Sep 22, 2008 11:16 PM by Ehsan Rabby

    Seam Quartz On Glassfish

    Ehsan Rabby Newbie
      Hello All,
      I am using seam for a while now. i have ran into problems in the past but was able to figure out myself with the help of past discussions. I ran into this quartz problem that i am kind of stumped with right now. I have tested this on Jboss and it works great no problem at all. but on glassfish it does not work. below is the code snippet
      Here is my enviornment:
      Seam 2.0.2SP1
      GlassFish V2 ur2

      configured quartz on components.xml
      <components xmlns="http://jboss.com/products/seam/components"
                  xmlns:core="http://jboss.com/products/seam/core"
                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:drools="http://jboss.com/products/seam/drools"
                  xmlns:bpm="http://jboss.com/products/seam/bpm"
                  xmlns:security="http://jboss.com/products/seam/security"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xmlns:async="http://jboss.com/products/seam/async"
                  xsi:schemaLocation=
                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                       http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.0.xsd">

         <core:init debug="@debug@" jndi-pattern="java:comp/env/@jndiPattern@"/>
          
         <component scope="APPLICATION" auto-create="true" name="renderManager" class="com.icesoft.faces.async.render.RenderManager" />

         <core:manager concurrent-request-timeout="500"
                       conversation-timeout="120000"
                       conversation-id-parameter="cid"
                       parent-conversation-id-parameter="pid"/>
         <!-- this is glassfish specific -->
         <persistence:entity-manager-factory name="xyz" persistence-unit-name="xyz"/>
         <persistence:managed-persistence-context name="entityManager"
                                           auto-create="true"
                                           entity-manager-factory="#{xyz}"/>
         <async:quartz-dispatcher/>
         <mail:mail-session host="xyz" username="xyz" password="xyz" port="25" tls="false"/> 
      </components>
      Interface
      @Local
      public interface TaskMailProcessor {
         

          @Asynchronous
          public QuartzTriggerHandle scheduleAlertMailer(@Expiration Date when,
                  @IntervalDuration Long interval,
                  @FinalExpiration Date endDate) ;
          public void destroy();

      }
      @Stateful
      @Name("taskMailProcessor")
      @AutoCreate
      public class TaskProcessorImpl implements TaskMailProcessor{
           
               @In
               EntityManager entityManager;
              
             
               @Logger Log log;

               public QuartzTriggerHandle scheduleAlertMailer( Date when,
                        Long interval,
                        Date endDate)
               {
                     List<Tasklist> tasks=entityManager.createQuery("....").getResultList();
                     log.info("tasklist size:"+tasks.size());
                         
                     if(tasks.size()!=0){
                         Contexts.getEventContext().set("emailtasks", tasks);
                         Renderer.instance().render("/TaskEmailText.xhtml");
                         log.info("Wait you will receive emails");
                     }
                     else{
                         log.info("No task found in next hour");
                     }
                   return null;
               }
              
               @Remove
               public void destroy(){
                    
               }
      }
      @Local
      public interface TaskAlertEmail {       
                
                
                public void observe();
                public void destroy();
                public TaskMailProcessor getTaskMailProcessor();
                public void setTaskMailProcessor(TaskMailProcessor taskMailProcessor);
      }
      @Stateful
      @Name("TaskAlertEmailImpl")
      @Scope(ScopeType.APPLICATION)
      @Startup
      public class TaskAlertEmailImpl  implements Serializable,TaskAlertEmail {
              private static final long serialVersionUID = 1881413500711441951L;
             
             
              @Logger
              private Log log;
                @In   
                private TaskMailProcessor taskMailProcessor;
             
             
                
                /**
                 * This is called by seam after initialization
                 * has finished.
                 */

              @Create     
              public void observe() {
                  
                    log.info("About to load system properties");
                     Calendar cal = Calendar.getInstance ();
                    cal.set (2008, Calendar.SEPTEMBER, 20);
                  
                     if(taskMailProcessor!=null){
                     log.info("goin to send emails");
                     QuartzTriggerHandle handle = taskMailProcessor.scheduleAlertMailer(new Date(),1*60*1000L,cal.getTime());
                     }
                     else
                     {
                          log.info("Again Null........");
                          
                     }     
                }


              @Remove
               public void destroy(){
                    
               }

           public TaskMailProcessor getTaskMailProcessor() {
                return taskMailProcessor;
           }

           public void setTaskMailProcessor(TaskMailProcessor taskMailProcessor) {
                this.taskMailProcessor = taskMailProcessor;
           }
      }

      Few notes Renderer.instance().render("template") causes problem with icefaces. I found a work around for that. So on glassfish the scheduleAlertMailer method is called once the server starts up. But never runs again. But on jboss that method runs every one minute.
      My understanding is <async:quartz-dispatcher/> is not registering the quartz sheduler properly on Glassfish. Also i have another context on glassfish server that has quartz configured with a jndi lookup with plain EJB3. I disabled quartz on the context to make sure there was no conflict. no luck. Need some help here. specifically how to register quartz on glassfish with <async:quartz-dispatcher/> or other options to configure quartz
      Thanks in advance