@Override public void internalSchedule(TimerJobInstance timerJobInstance) { this.delegate.internalSchedule(timerJobInstance); }
public JobHandle buildJobHandleForContext(NamedJobContext ctx) { return this.schedulerService.buildJobHandleForContext(ctx); }
@Override public void reset() { schedulerService.initScheduler(this); timerJobsPerSession.clear(); jobFactoryManager = initJobFactoryManager(); }
protected void initTimerService(RuntimeEnvironment environment, RuntimeManager manager) { if (environment instanceof SchedulerProvider) { GlobalSchedulerService schedulerService = ((SchedulerProvider) environment).getSchedulerService(); if (schedulerService != null) { TimerService globalTs = new GlobalTimerService(manager, schedulerService); String timerServiceId = manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX; // and register it in the registry under 'default' key TimerServiceRegistry.getInstance().registerTimerService(timerServiceId, globalTs); ((SimpleRuntimeEnvironment)environment).addToConfiguration("drools.timerService", "new org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate(\""+timerServiceId+"\")"); if (!schedulerService.isTransactional()) { schedulerService.setInterceptor(new TransactionAwareSchedulerServiceInterceptor(environment, manager, schedulerService)); } } } }
public void destroy() { Collection<List<GlobalJobHandle>> activeTimers = timerJobsPerSession.values(); for (List<GlobalJobHandle> handles : activeTimers) { for (GlobalJobHandle handle : handles) { this.schedulerService.removeJob(handle); } } }
@Override public Collection<TimerJobInstance> getTimerJobInstances(long id) { Collection<TimerJobInstance> timers = new ArrayList<TimerJobInstance>(); List<GlobalJobHandle> jobs = timerJobsPerSession.get(id); { if (jobs != null) { for (GlobalJobHandle job : jobs) { if (job != null && schedulerService.isValid(job)) { timers.add(job.getTimerJobInstance()); } } } } logger.debug("Returning timers {} for session {}", timers, id); return timers; }
public void close(boolean removeJobs) { cacheManager.dispose(); environment.close(); registry.remove(identifier); TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX); if (timerService != null) { try { if (removeJobs && timerService instanceof GlobalTimerService) { ((GlobalTimerService) timerService).destroy(); } timerService.shutdown(); GlobalSchedulerService schedulerService = ((SchedulerProvider) environment).getSchedulerService(); if (schedulerService != null) { schedulerService.shutdown(); } } finally { TimerServiceRegistry.getInstance().remove(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX); } } this.closed = true; }
protected ExecutableRunner getRunner( Long processInstanceId, ProcessJobContext ctx ) { RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); if (runtime == null) { throw new RuntimeException("No runtime engine found, could not be initialized yet"); } try { if (runtime.getKieSession() instanceof CommandBasedStatefulKnowledgeSession) { CommandBasedStatefulKnowledgeSession cmd = (CommandBasedStatefulKnowledgeSession) runtime.getKieSession(); if (ctx != null) { ctx.setKnowledgeRuntime((InternalKnowledgeRuntime) ( (SingleSessionCommandService) cmd.getRunner() ).getKieSession() ); } return new DisposableCommandService(cmd.getRunner(), manager, runtime, schedulerService.retryEnabled()); } else if (runtime.getKieSession() instanceof InternalKnowledgeRuntime && ctx != null) { ctx.setKnowledgeRuntime((InternalKnowledgeRuntime) runtime.getKieSession()); } return new DisposableCommandService(getRunner(), manager, runtime, schedulerService.retryEnabled()); } catch (Throwable e) { // since the DisposableCommandService was not created dispose runtime engine directly manager.disposeRuntimeEngine(runtime); throw new RuntimeException(e); } }
@Override public JobHandle scheduleJob(Job job, JobContext ctx, Trigger trigger) { if (ctx instanceof ProcessJobContext) { ProcessJobContext processCtx = (ProcessJobContext) ctx; List<GlobalJobHandle> jobHandles = timerJobsPerSession.get(processCtx.getSessionId()); if (jobHandles == null) { jobHandles = new CopyOnWriteArrayList<GlobalJobHandle>(); timerJobsPerSession.put(processCtx.getSessionId(), jobHandles); } else { // check if the given job is already scheduled for (GlobalJobHandle handle : jobHandles) { long timerId = handle.getTimerId(); if (timerId == processCtx.getTimer().getId()) { // this timer job is already registered return handle; } } } GlobalJobHandle jobHandle = (GlobalJobHandle) this.schedulerService.scheduleJob(job, ctx, trigger); if (jobHandle != null) { jobHandles.add(jobHandle); } return jobHandle; } GlobalJobHandle jobHandle = (GlobalJobHandle) this.schedulerService.scheduleJob(job, ctx, trigger); return jobHandle; }
protected void initTimerService(RuntimeEnvironment environment, RuntimeManager manager) { if (environment instanceof SchedulerProvider) { GlobalSchedulerService schedulerService = ((SchedulerProvider) environment).getSchedulerService(); if (schedulerService != null) { TimerService globalTs = new GlobalTimerService(manager, schedulerService); String timerServiceId = manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX; // and register it in the registry under 'default' key TimerServiceRegistry.getInstance().registerTimerService(timerServiceId, globalTs); ((SimpleRuntimeEnvironment)environment).addToConfiguration("drools.timerService", "new org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate(\""+timerServiceId+"\")"); if (!schedulerService.isTransactional()) { schedulerService.setInterceptor(new TransactionAwareSchedulerServiceInterceptor(environment, manager, schedulerService)); } } } }
@Override public boolean removeJob(JobHandle jobHandle) { if (jobHandle == null) { return false; } long sessionId = ((GlobalJobHandle) jobHandle).getSessionId(); List<GlobalJobHandle> handles = timerJobsPerSession.get(sessionId); if (handles == null) { logger.debug("No known job handles for session {}", sessionId); return this.schedulerService.removeJob(jobHandle); } if (handles.contains(jobHandle)) { logger.debug("Found match so removing job handle {} from sessions {} handles", jobHandle, sessionId); handles.remove(jobHandle); if (handles.isEmpty()) { timerJobsPerSession.remove(sessionId); } return this.schedulerService.removeJob(jobHandle); } else { logger.debug("No match for job handle {} within handles of session {}", jobHandle, sessionId); return false; } }
@Override public Collection<TimerJobInstance> getTimerJobInstances(long id) { Collection<TimerJobInstance> timers = new ArrayList<TimerJobInstance>(); List<GlobalJobHandle> jobs = timerJobsPerSession.get(id); { if (jobs != null) { for (GlobalJobHandle job : jobs) { if (job != null && schedulerService.isValid(job)) { timers.add(job.getTimerJobInstance()); } } } } logger.debug("Returning timers {} for session {}", timers, id); return timers; }
public void close(boolean removeJobs) { cacheManager.dispose(); environment.close(); registry.remove(identifier); TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX); if (timerService != null) { try { if (removeJobs && timerService instanceof GlobalTimerService) { ((GlobalTimerService) timerService).destroy(); } timerService.shutdown(); GlobalSchedulerService schedulerService = ((SchedulerProvider) environment).getSchedulerService(); if (schedulerService != null) { schedulerService.shutdown(); } } finally { TimerServiceRegistry.getInstance().remove(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX); } } this.closed = true; }
protected ExecutableRunner getRunner( Long processInstanceId, ProcessJobContext ctx ) { RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId)); if (runtime == null) { throw new RuntimeException("No runtime engine found, could not be initialized yet"); } try { if (runtime.getKieSession() instanceof CommandBasedStatefulKnowledgeSession) { CommandBasedStatefulKnowledgeSession cmd = (CommandBasedStatefulKnowledgeSession) runtime.getKieSession(); if (ctx != null) { ctx.setKnowledgeRuntime((InternalKnowledgeRuntime) ( (SingleSessionCommandService) cmd.getRunner() ).getKieSession() ); } return new DisposableCommandService(cmd.getRunner(), manager, runtime, schedulerService.retryEnabled()); } else if (runtime.getKieSession() instanceof InternalKnowledgeRuntime && ctx != null) { ctx.setKnowledgeRuntime((InternalKnowledgeRuntime) runtime.getKieSession()); } return new DisposableCommandService(getRunner(), manager, runtime, schedulerService.retryEnabled()); } catch (Throwable e) { // since the DisposableCommandService was not created dispose runtime engine directly manager.disposeRuntimeEngine(runtime); throw new RuntimeException(e); } }
@Override public JobHandle scheduleJob(Job job, JobContext ctx, Trigger trigger) { if (ctx instanceof ProcessJobContext) { ProcessJobContext processCtx = (ProcessJobContext) ctx; List<GlobalJobHandle> jobHandles = timerJobsPerSession.get(processCtx.getSessionId()); if (jobHandles == null) { jobHandles = new CopyOnWriteArrayList<GlobalJobHandle>(); timerJobsPerSession.put(processCtx.getSessionId(), jobHandles); } else { // check if the given job is already scheduled for (GlobalJobHandle handle : jobHandles) { long timerId = handle.getTimerId(); if (timerId == processCtx.getTimer().getId()) { // this timer job is already registered return handle; } } } GlobalJobHandle jobHandle = (GlobalJobHandle) this.schedulerService.scheduleJob(job, ctx, trigger); if (jobHandle != null) { jobHandles.add(jobHandle); } return jobHandle; } GlobalJobHandle jobHandle = (GlobalJobHandle) this.schedulerService.scheduleJob(job, ctx, trigger); return jobHandle; }
/** * This code takes care of configuring the runtime environment to configure the timer service * (an internal component of the KIE Session used to measure how time progresses, used * for signals and time based rules). It will create a specific timer service, separate from any * other, exclusively for the new runitme manager, and if the configuration makes it a transactional * object, it adds an interceptor to the timer service to store scheduled tasks in the database as well. */ protected void initTimerService(RuntimeEnvironment environment, RuntimeManager manager) { if (environment instanceof SchedulerProvider) { GlobalSchedulerService schedulerService = ((SchedulerProvider) environment).getSchedulerService(); if (schedulerService != null) { TimerService globalTs = new GlobalTimerService(manager, schedulerService); String timerServiceId = manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX; // and register it in the registry under 'default' key TimerServiceRegistry.getInstance().registerTimerService(timerServiceId, globalTs); ((SimpleRuntimeEnvironment)environment).addToConfiguration("drools.timerService", "new org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate(\""+timerServiceId+"\")"); if (!schedulerService.isTransactional()) { schedulerService.setInterceptor(new TransactionAwareSchedulerServiceInterceptor(environment, schedulerService)); } } } } }
@Override public void afterCompletion(int status) { if ( status == TransactionManager.STATUS_COMMITTED && !timerJobInstance.getJobHandle().isCancel()) { this.schedulerService.internalSchedule(timerJobInstance); } }
public GlobalTimerService(RuntimeManager manager, GlobalSchedulerService schedulerService) { this.manager = manager; this.schedulerService = schedulerService; this.schedulerService.initScheduler(this); jobFactoryManager = initJobFactoryManager(); }
public void destroy() { Collection<List<GlobalJobHandle>> activeTimers = timerJobsPerSession.values(); for (List<GlobalJobHandle> handles : activeTimers) { for (GlobalJobHandle handle : handles) { this.schedulerService.removeJob(handle); } } }
public JobHandle buildJobHandleForContext(NamedJobContext ctx) { return this.schedulerService.buildJobHandleForContext(ctx); }