KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > timerservice > quartz > PersistentTimer


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.timerservice.quartz;
23
24 import java.io.Serializable JavaDoc;
25
26 import javax.ejb.EJBException JavaDoc;
27 import javax.ejb.NoSuchObjectLocalException JavaDoc;
28 import javax.ejb.Timer JavaDoc;
29 import javax.ejb.TimerHandle JavaDoc;
30 import javax.management.ObjectName JavaDoc;
31
32 import org.jboss.ejb3.Ejb3Registry;
33 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
34 import org.jboss.logging.Logger;
35 import org.quartz.Scheduler;
36 import org.quartz.SchedulerException;
37 import org.quartz.Trigger;
38
39 /**
40  * This class contains all the info for find a persistent timer.
41  *
42  * @author <a HREF="mailto:carlo@nerdnet.nl">Carlo de Wolf</a>
43  * @version $Revision: 56169 $
44  */

45 public class PersistentTimer implements Serializable JavaDoc, TimerHandle JavaDoc
46 {
47    private static final Logger log = Logger.getLogger(PersistentTimer.class);
48    
49    private static final long serialVersionUID = 1L;
50
51    //private String schedulerName;
52
//private String jobName;
53
//private String jobGroup;
54
private String JavaDoc triggerName;
55    private String JavaDoc triggerGroup;
56    private ObjectName JavaDoc objectName;
57    
58    private Serializable JavaDoc info;
59    
60    protected PersistentTimer(Trigger trigger, ObjectName JavaDoc objectName, Serializable JavaDoc info)
61    {
62       assert trigger != null;
63       assert objectName != null;
64       
65       this.triggerName = trigger.getName();
66       this.triggerGroup = trigger.getGroup();
67       this.objectName = objectName;
68       this.info = info;
69    }
70    
71    protected TimedObjectInvoker getTimedObjectInvoker()
72    {
73       // TODO: a hack to get back the container. This needs thinking.
74
TimedObjectInvoker invoker = (TimedObjectInvoker) Ejb3Registry.getContainer(objectName.getCanonicalName());
75       assert invoker != null;
76       return invoker;
77    }
78    
79    public Timer JavaDoc getTimer() throws IllegalStateException JavaDoc, NoSuchObjectLocalException JavaDoc, EJBException JavaDoc
80    {
81       // TODO: check state
82
try
83       {
84          Scheduler scheduler = QuartzTimerServiceFactory.getScheduler();
85          Trigger trigger = scheduler.getTrigger(triggerName, triggerGroup);
86          if(trigger == null)
87             throw new NoSuchObjectLocalException JavaDoc("can't find trigger '" + triggerName + "' in group '" + triggerGroup + "'");
88          return new TimerImpl(scheduler, trigger, info);
89       }
90       catch(SchedulerException e)
91       {
92          log.error("getTimer failed", e);
93          throw new EJBException JavaDoc(e);
94       }
95    }
96 }
97
Popular Tags