1 5 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 45 public class UnscheduleJob implements FunctionProvider { 46 48 private static final Log log = LogFactory.getLog(UnscheduleJob.class); 49 50 52 public void execute(Map transientVars, Map 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 schedulerName = (String ) 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 ) args.get("txHack")); 70 71 String triggerName = (String ) args.get("triggerName"); 72 String groupName = (String ) 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 e) { 92 log.error("Could not unschedule job", e); 93 } 94 } 95 } 96 | Popular Tags |