use of org.drools.core.time.TimerService in project jbpm by kiegroup.
the class PerCaseRuntimeManager method disposeRuntimeEngine.
@Override
public void disposeRuntimeEngine(RuntimeEngine runtime) {
if (isClosed()) {
throw new IllegalStateException("Runtime manager " + identifier + " is already closed");
}
try {
if (canDispose(runtime)) {
removeLocalRuntime(runtime);
Long ksessionId = ((RuntimeEngineImpl) runtime).getKieSessionId();
releaseAndCleanLock(ksessionId, runtime);
if (runtime instanceof Disposable) {
// special handling for in memory to not allow to dispose if there is any context in the mapper
if (mapper instanceof InMemoryMapper && ((InMemoryMapper) mapper).hasContext(ksessionId)) {
return;
}
((Disposable) runtime).dispose();
}
if (ksessionId != null) {
TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
if (timerService != null) {
if (timerService instanceof GlobalTimerService) {
((GlobalTimerService) timerService).clearTimerJobInstances(ksessionId);
}
}
}
}
} catch (Exception e) {
releaseAndCleanLock(runtime);
removeLocalRuntime(runtime);
throw new RuntimeException(e);
}
}
use of org.drools.core.time.TimerService in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManager method disposeRuntimeEngine.
@Override
public void disposeRuntimeEngine(RuntimeEngine runtime) {
if (isClosed()) {
throw new IllegalStateException("Runtime manager " + identifier + " is already closed");
}
try {
if (canDispose(runtime)) {
removeLocalRuntime(runtime);
Long ksessionId = ((RuntimeEngineImpl) runtime).getKieSessionId();
if (runtime instanceof Disposable) {
// special handling for in memory to not allow to dispose if there is any context in the mapper
if (mapper instanceof InMemoryMapper && ((InMemoryMapper) mapper).hasContext(ksessionId)) {
return;
}
((Disposable) runtime).dispose();
}
if (ksessionId != null) {
TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
if (timerService != null) {
if (timerService instanceof GlobalTimerService) {
((GlobalTimerService) timerService).clearTimerJobInstances(ksessionId);
}
}
}
releaseAndCleanLock(runtime);
}
} catch (Exception e) {
releaseAndCleanLock(runtime);
removeLocalRuntime(runtime);
throw new RuntimeException(e);
}
}
use of org.drools.core.time.TimerService in project jbpm by kiegroup.
the class PerRequestRuntimeManager method disposeRuntimeEngine.
@Override
public void disposeRuntimeEngine(RuntimeEngine runtime) {
if (isClosed()) {
throw new IllegalStateException("Runtime manager " + identifier + " is already closed");
}
try {
if (canDispose(runtime)) {
local.get().remove(identifier);
try {
Long ksessionId = ((RuntimeEngineImpl) runtime).getKieSessionId();
factory.onDispose(ksessionId);
if (canDestroy(runtime)) {
runtime.getKieSession().destroy();
} else {
if (runtime instanceof Disposable) {
((Disposable) runtime).dispose();
}
}
if (ksessionId != null) {
TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
if (timerService != null) {
if (timerService instanceof GlobalTimerService) {
((GlobalTimerService) timerService).clearTimerJobInstances(ksessionId);
}
}
}
} catch (Exception e) {
// do nothing
if (runtime instanceof Disposable) {
((Disposable) runtime).dispose();
}
}
}
} catch (Exception e) {
local.get().remove(identifier);
throw new RuntimeException(e);
}
}
use of org.drools.core.time.TimerService in project jbpm by kiegroup.
the class TaskDeadlinesServiceImpl method unschedule.
public void unschedule(long taskId, Deadline deadline, DeadlineType type) {
Task task = persistenceContext.findTask(taskId);
String deploymentId = task.getTaskData().getDeploymentId();
Deadlines deadlines = ((InternalTask) task).getDeadlines();
TimerService timerService = TimerServiceRegistry.getInstance().get(deploymentId + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
if (timerService != null && timerService instanceof GlobalTimerService) {
TaskDeadlineJob deadlineJob = new TaskDeadlineJob(taskId, deadline.getId(), type, deploymentId, task.getTaskData().getProcessInstanceId());
logger.debug("unscheduling timer job for deadline {} {} and task {} using timer service {}", deadlineJob.getId(), deadline.getId(), taskId, timerService);
JobHandle jobHandle = jobHandles.remove(deadlineJob.getId());
if (jobHandle == null) {
jobHandle = ((GlobalTimerService) timerService).buildJobHandleForContext(new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId));
}
timerService.removeJob(jobHandle);
// mark the deadlines so they won't be rescheduled again
deadline.setEscalated(true);
}
}
use of org.drools.core.time.TimerService in project jbpm by kiegroup.
the class TaskDeadlinesServiceImpl method schedule.
public void schedule(long taskId, long deadlineId, long delay, DeadlineType type) {
Task task = persistenceContext.findTask(taskId);
String deploymentId = task.getTaskData().getDeploymentId();
TimerService timerService = TimerServiceRegistry.getInstance().get(deploymentId + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
if (timerService != null && timerService instanceof GlobalTimerService) {
TaskDeadlineJob deadlineJob = new TaskDeadlineJob(taskId, deadlineId, type, deploymentId, task.getTaskData().getProcessInstanceId());
Trigger trigger = new IntervalTrigger(timerService.getCurrentTime(), null, null, -1, delay, 0, null, null);
JobHandle handle = timerService.scheduleJob(deadlineJob, new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId), trigger);
logger.debug("scheduling timer job for deadline {} and task {} using timer service {}", deadlineJob.getId(), taskId, timerService);
jobHandles.put(deadlineJob.getId(), handle);
} else {
ScheduledFuture<ScheduledTaskDeadline> scheduled = scheduler.schedule(new ScheduledTaskDeadline(taskId, deadlineId, type, deploymentId, task.getTaskData().getProcessInstanceId()), delay, TimeUnit.MILLISECONDS);
List<ScheduledFuture<ScheduledTaskDeadline>> knownFutures = null;
if (type == DeadlineType.START) {
knownFutures = startScheduledTaskDeadlines.get(taskId);
} else if (type == DeadlineType.END) {
knownFutures = endScheduledTaskDeadlines.get(taskId);
}
if (knownFutures == null) {
knownFutures = new CopyOnWriteArrayList<ScheduledFuture<ScheduledTaskDeadline>>();
}
knownFutures.add(scheduled);
if (type == DeadlineType.START) {
startScheduledTaskDeadlines.put(taskId, knownFutures);
} else if (type == DeadlineType.END) {
endScheduledTaskDeadlines.put(taskId, knownFutures);
}
}
}
Aggregations