01: /**
02: * EasyBeans
03: * Copyright (C) 2007 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: EasyBeansJob.java 1970 2007-10-16 11:49:25Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.component.quartz;
25:
26: import javax.ejb.Timer;
27:
28: import org.ow2.easybeans.api.EZBContainer;
29: import org.ow2.easybeans.api.EZBServer;
30: import org.ow2.easybeans.api.EmbeddedManager;
31: import org.ow2.easybeans.api.Factory;
32: import org.quartz.Job;
33: import org.quartz.JobExecutionContext;
34: import org.quartz.JobExecutionException;
35:
36: /**
37: * This class will receive a job execution context and then call the bean
38: * method. The parameters are stored in the Job Execution Context
39: * @author Florent Benoit
40: */
41: public class EasyBeansJob implements Job {
42:
43: /**
44: * Invoke the factory with the timer object.
45: * @param context the context containing the stuff in order to call the Bean's factory and the associated timeout method.
46: * @throws JobExecutionException if there is an exception while executing
47: * the job.
48: */
49: public void execute(final JobExecutionContext context)
50: throws JobExecutionException {
51: // Get the Job Detail data from the context
52: EasyBeansJobDetailData data = ((EasyBeansJobDetail) context
53: .getJobDetail()).getJobDetailData();
54:
55: // Find the Embedded instance
56: EZBServer server = EmbeddedManager.getEmbedded(data
57: .getEasyBeansServerID());
58: if (server == null) {
59: throw new JobExecutionException(
60: "Cannot find the embedded server with the id '"
61: + data.getEasyBeansServerID() + "'.");
62: }
63:
64: // Get the container
65: EZBContainer container = server.getContainer(data
66: .getContainerId());
67: if (container == null) {
68: throw new JobExecutionException(
69: "Cannot find the container with the id '"
70: + data.getContainerId() + "'.");
71: }
72:
73: // Get the factory
74: Factory factory = container.getFactory(data.getFactoryName());
75: if (factory == null) {
76: throw new JobExecutionException(
77: "Cannot find the factory with the name '"
78: + data.getFactoryName() + "'.");
79: }
80:
81: // Get the timer
82: Timer timer = data.getTimer();
83: if (timer == null) {
84: throw new JobExecutionException(
85: "No timer found in the given JobExecutionContext.");
86: }
87:
88: // Invoke the timer method
89: factory.notifyTimeout(timer);
90:
91: }
92: }
|