01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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;
25:
26: import javax.ejb.EJBException;
27: import javax.ejb.NoSuchObjectLocalException;
28: import javax.ejb.Timer;
29: import javax.ejb.TimerHandle;
30: import javax.management.ObjectName;
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: 60233 $
44: */
45: public class PersistentTimer implements Serializable, TimerHandle {
46: private static final Logger log = Logger
47: .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 triggerName;
55: private String triggerGroup;
56: private ObjectName objectName;
57:
58: private Serializable info;
59:
60: protected PersistentTimer(Trigger trigger, ObjectName objectName,
61: Serializable info) {
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: // TODO: a hack to get back the container. This needs thinking.
73: TimedObjectInvoker invoker = (TimedObjectInvoker) Ejb3Registry
74: .getContainer(objectName.getCanonicalName());
75: assert invoker != null;
76: return invoker;
77: }
78:
79: public Timer getTimer() throws IllegalStateException,
80: NoSuchObjectLocalException, EJBException {
81: // TODO: check state
82: try {
83: Scheduler scheduler = QuartzTimerServiceFactory
84: .getScheduler();
85: Trigger trigger = scheduler.getTrigger(triggerName,
86: triggerGroup);
87: if (trigger == null)
88: throw new NoSuchObjectLocalException(
89: "can't find trigger '" + triggerName
90: + "' in group '" + triggerGroup + "'");
91: return new TimerImpl(scheduler, trigger, info);
92: } catch (SchedulerException e) {
93: log.error("getTimer failed", e);
94: throw new EJBException(e);
95: }
96: }
97: }
|