01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: /*
06: * Created by IntelliJ IDEA.
07: * User: plightbo
08: * Date: May 23, 2002
09: * Time: 2:33:59 AM
10: */
11: package com.opensymphony.workflow.util;
12:
13: import com.opensymphony.module.propertyset.PropertySet;
14:
15: import com.opensymphony.util.TextUtils;
16:
17: import com.opensymphony.workflow.FunctionProvider;
18: import com.opensymphony.workflow.spi.WorkflowEntry;
19:
20: import org.apache.commons.logging.Log;
21: import org.apache.commons.logging.LogFactory;
22:
23: import org.quartz.Scheduler;
24: import org.quartz.SchedulerException;
25:
26: import org.quartz.impl.StdSchedulerFactory;
27:
28: import java.util.Map;
29:
30: /**
31: * Unschedules a job that was scheduled previously. Accepts the following arguments:
32: *
33: * <ul>
34: * <li>triggerName - the name of the trigger previously scheduled</li>
35: * <li>groupName - the name of the group previously scheduled</li>
36: * <li>schedulerName - the name of an existing scheduler to use (optional)</li>
37: * <li>txHack - set this to true if you are getting lockups while running with transactions (optional, defaults to false)</li>
38: * </ul>
39: *
40: * @author <a href="mike.g.slack@usahq.unitedspacealliance.com ">Michael G. Slack</a>
41: * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
42: * @version $Revision: 1.3 $
43: */
44: public class UnscheduleJob implements FunctionProvider {
45: //~ Static fields/initializers /////////////////////////////////////////////
46:
47: private static final Log log = LogFactory
48: .getLog(UnscheduleJob.class);
49:
50: //~ Methods ////////////////////////////////////////////////////////////////
51:
52: public void execute(Map transientVars, Map args, PropertySet ps) {
53: try {
54: WorkflowEntry entry = (WorkflowEntry) transientVars
55: .get("entry");
56:
57: log.info("Starting to unschedule job for WF #"
58: + entry.getId());
59:
60: String schedulerName = (String) args.get("schedulerName");
61: Scheduler s = null;
62:
63: StdSchedulerFactory factory = new StdSchedulerFactory();
64:
65: if ((schedulerName == null)
66: || ("".equals(schedulerName.trim()))) {
67: s = factory.getScheduler();
68: } else {
69: s = factory.getScheduler(schedulerName);
70: }
71:
72: boolean txHack = TextUtils.parseBoolean((String) args
73: .get("txHack"));
74:
75: String triggerName = (String) args.get("triggerName");
76: String groupName = (String) args.get("groupName");
77: triggerName = triggerName + ":" + entry.getId();
78: groupName = groupName + ":" + entry.getId();
79:
80: if (txHack && !s.isPaused() && !s.isShutdown()) {
81: s.pause();
82:
83: try {
84: s.unscheduleJob(triggerName, groupName);
85: } catch (SchedulerException e) {
86: throw e;
87: } finally {
88: s.start();
89: }
90: } else {
91: s.unscheduleJob(triggerName, groupName);
92: }
93:
94: log.info("Job unscheduled");
95: } catch (Exception e) {
96: log.error("Could not unschedule job", e);
97: }
98: }
99: }
|