KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > util > UnscheduleJob


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 /*
6  * Created by IntelliJ IDEA.
7  * User: plightbo
8  * Date: May 23, 2002
9  * 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 JavaDoc;
29
30
31 /**
32  * Unschedules a job that was scheduled previously. Accepts the following arguments:
33  *
34  * <ul>
35  * <li>triggerName - the name of the trigger previously scheduled</li>
36  * <li>groupName - the name of the group previously scheduled</li>
37  * <li>schedulerName - the name of an existing scheduler to use (optional)</li>
38  * <li>txHack - set this to true if you are getting lockups while running with transactions (optional, defaults to false)</li>
39  * </ul>
40  *
41  * @author <a HREF="mike.g.slack@usahq.unitedspacealliance.com ">Michael G. Slack</a>
42  * @author <a HREF="mailto:plightbo@hotmail.com">Pat Lightbody</a>
43  * @version $Revision: 1.3 $
44  */

45 public class UnscheduleJob implements FunctionProvider {
46     //~ Static fields/initializers /////////////////////////////////////////////
47

48     private static final Log log = LogFactory.getLog(UnscheduleJob.class);
49
50     //~ Methods ////////////////////////////////////////////////////////////////
51

52     public void execute(Map JavaDoc transientVars, Map JavaDoc args, PropertySet ps) {
53         try {
54             WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
55
56             log.info("Starting to unschedule job for WF #" + entry.getId());
57
58             String JavaDoc schedulerName = (String JavaDoc) args.get("schedulerName");
59             Scheduler s = null;
60
61             StdSchedulerFactory factory = new StdSchedulerFactory();
62
63             if ((schedulerName == null) || ("".equals(schedulerName.trim()))) {
64                 s = factory.getScheduler();
65             } else {
66                 s = factory.getScheduler(schedulerName);
67             }
68
69             boolean txHack = TextUtils.parseBoolean((String JavaDoc) args.get("txHack"));
70
71             String JavaDoc triggerName = (String JavaDoc) args.get("triggerName");
72             String JavaDoc groupName = (String JavaDoc) args.get("groupName");
73             triggerName = triggerName + ":" + entry.getId();
74             groupName = groupName + ":" + entry.getId();
75
76             if (txHack && !s.isPaused() && !s.isShutdown()) {
77                 s.pause();
78
79                 try {
80                     s.unscheduleJob(triggerName, groupName);
81                 } catch (SchedulerException e) {
82                     throw e;
83                 } finally {
84                     s.start();
85                 }
86             } else {
87                 s.unscheduleJob(triggerName, groupName);
88             }
89
90             log.info("Job unscheduled");
91         } catch (Exception JavaDoc e) {
92             log.error("Could not unschedule job", e);
93         }
94     }
95 }
96
Popular Tags