diff --git a/components/mediation/tasks/org.wso2.micro.integrator.mediation.ntask/src/main/java/org/wso2/micro/integrator/mediation/ntask/NTaskTaskManager.java b/components/mediation/tasks/org.wso2.micro.integrator.mediation.ntask/src/main/java/org/wso2/micro/integrator/mediation/ntask/NTaskTaskManager.java index a32ad004fe..ec879d84ef 100644 --- a/components/mediation/tasks/org.wso2.micro.integrator.mediation.ntask/src/main/java/org/wso2/micro/integrator/mediation/ntask/NTaskTaskManager.java +++ b/components/mediation/tasks/org.wso2.micro.integrator.mediation.ntask/src/main/java/org/wso2/micro/integrator/mediation/ntask/NTaskTaskManager.java @@ -146,9 +146,6 @@ public boolean reschedule(String taskName, TaskDescription taskDescription) { @Override public boolean delete(String taskName) { - if (!isInitialized()) { - return false; - } if (taskName == null) { return false; } @@ -172,6 +169,10 @@ public boolean delete(String taskName) { try { boolean deleted; synchronized (lock) { + if (!isInitialized()) { + checkAndDeleteTaskFromQueue(name, group, taskName); + return false; + } if (taskManager == null) { logger.warn("#delete Could not delete task [" + taskName + "]. Task manager is not available."); return false; @@ -714,5 +715,18 @@ public void run() { }).start(); } -} + private void checkAndDeleteTaskFromQueue(String name, String group, String taskName) { + synchronized (taskQueueLock) { + Iterator iterator = taskQueue.iterator(); + while (iterator.hasNext()) { + TaskDescription taskDescription = iterator.next(); + if (taskDescription.getName().equals(name) && taskDescription.getTaskGroup().equals(group)) { + iterator.remove(); + NTaskAdapter.removeProperty(taskName); + logger.info("Deleted queued task [" + name + "::" + group + "]."); + } + } + } + } +}