Permalink
Browse files

JBPM-3661-HT Deadlines are not cancelled on task completion

  • Loading branch information...
1 parent ababf75 commit 5181ddf84ddf718727f3a55f7715b8416bfe4baf @mswiderski mswiderski committed May 30, 2012
@@ -69,6 +69,8 @@
private ClassLoader classLoader;
+ protected List<Status> validStatuses = new ArrayList<Status>();
+
public DefaultEscalatedDeadlineHandler(Properties properties) {
handler = new EmailWorkItemHandler();
@@ -81,6 +83,7 @@ public DefaultEscalatedDeadlineHandler(Properties properties) {
replyTo = properties.getProperty( "replyTo", null );
handler.setConnection( host, port, user, password );
+ setValidStatuses();
}
public DefaultEscalatedDeadlineHandler(Properties properties, ClassLoader classLoader) {
@@ -96,6 +99,7 @@ public DefaultEscalatedDeadlineHandler(Properties properties, ClassLoader classL
handler.setConnection( host, port, user, password );
this.classLoader = classLoader;
+ setValidStatuses();
}
public DefaultEscalatedDeadlineHandler() {
@@ -111,7 +115,7 @@ public DefaultEscalatedDeadlineHandler() {
replyTo = conf.getProperty( "replyTo", null );
handler.setConnection( host, port, user, password );
-
+ setValidStatuses();
}
public UserInfo getUserInfo() {
@@ -168,10 +172,10 @@ public void executeEscalatedDeadline(Task task,
Deadline deadline,
Content content,
TaskService service) {
- if ( deadline == null || deadline.getEscalations() == null ) {
+ if ( deadline == null || deadline.getEscalations() == null || !isInValidStatus(task) ) {
return;
}
-
+
for ( Escalation escalation : deadline.getEscalations() ) {
// we won't impl constraints for now
@@ -338,4 +342,21 @@ private void buildMapByLanguage(Map<String, List<User>> map,
list.add( user );
}
+ protected void setValidStatuses() {
+ validStatuses.add(Status.Created);
+ validStatuses.add(Status.Ready);
+ validStatuses.add(Status.Reserved);
+ validStatuses.add(Status.InProgress);
+ validStatuses.add(Status.Suspended);
+ }
+
+ protected boolean isInValidStatus(Task task) {
+
+ if (this.validStatuses.contains(task.getTaskData().getStatus())) {
+ return true;
+ }
+ return false;
+
+ }
+
}
@@ -22,9 +22,14 @@
import java.io.Reader;
import java.io.Serializable;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -68,6 +73,9 @@
private SystemEventListener systemEventListener;
private Map<Operation, List<OperationCommand>> operations;
+
+ private Map<Long, List<ScheduledFuture<ScheduledTaskDeadline>>> scheduledTaskDeadlines
+ = new ConcurrentHashMap<Long, List<ScheduledFuture<ScheduledTaskDeadline>>>();
/**
* Constructor in which no EscalatedDeadlineHandler is given.
@@ -170,9 +178,35 @@ public TasksAdmin createTaskAdmin() {
public void schedule(ScheduledTaskDeadline deadline,
long delay) {
- scheduler.schedule(deadline,
+ ScheduledFuture<ScheduledTaskDeadline> scheduled = scheduler.schedule(deadline,
delay,
TimeUnit.MILLISECONDS);
+ List<ScheduledFuture<ScheduledTaskDeadline>> knownFeatures = scheduledTaskDeadlines.get(deadline.getTaskId());
+ if (knownFeatures == null) {
+ knownFeatures = new CopyOnWriteArrayList<ScheduledFuture<ScheduledTaskDeadline>>();
+ }
+ knownFeatures.add(scheduled);
+
+ this.scheduledTaskDeadlines.put(deadline.getTaskId(), knownFeatures);
+ }
+
+ public void unschedule(long taskId) {
+ List<ScheduledFuture<ScheduledTaskDeadline>> knownFeatures = scheduledTaskDeadlines.remove(taskId);
+ if (knownFeatures == null) {
+ return;
+ }
+ Iterator<ScheduledFuture<ScheduledTaskDeadline>> it = knownFeatures.iterator();
+ while (it.hasNext()) {
+ ScheduledFuture<ScheduledTaskDeadline> scheduled = it.next();
+ try {
+ if (!scheduled.isDone() && !scheduled.isCancelled()) {
+ scheduled.cancel(true);
+ }
+
+ } catch (Exception e) {
+ logger.error("Error while cancelling scheduled deadline task for Task with id " + taskId, e);
+ }
+ }
}
public Map<Operation, List<OperationCommand>> getOperations() {
@@ -478,6 +478,10 @@ public void doOperation() {
postTaskSkipOperation(task, userId);
break;
}
+ case Exit: {
+ postTaskExitOperation(task, userId);
+ break;
+ }
}
}
@@ -500,6 +504,8 @@ private void taskCompleteOperation(final Task task, final ContentData data) {
}
private void postTaskCompleteOperation(final Task task) {
+ service.unschedule(task.getId());
+
// trigger event support
service.getEventSupport().fireTaskCompleted(task.getId(), task.getTaskData().getActualOwner().getId());
}
@@ -512,6 +518,8 @@ private void taskFailOperation(final Task task, final ContentData data) {
}
private void postTaskFailOperation(final Task task) {
+ service.unschedule(task.getId());
+
// trigger event support
service.getEventSupport().fireTaskFailed(task.getId(), task.getTaskData().getActualOwner().getId());
}
@@ -521,10 +529,16 @@ private void taskSkipOperation(final Task task, final String userId) {
}
private void postTaskSkipOperation(final Task task, final String userId) {
+ service.unschedule(task.getId());
+
// trigger event support
service.getEventSupport().fireTaskSkipped(task.getId(), userId);
}
+ private void postTaskExitOperation(final Task task, final String userId) {
+ service.unschedule(task.getId());
+ }
+
public Task getTask(final long taskId) {
return getEntity(Task.class, taskId);
}
Oops, something went wrong.

0 comments on commit 5181ddf

Please sign in to comment.