@Override public TimerJobFactoryManager getTimerJobFactoryManager() { return timerService.getTimerJobFactoryManager(); }
protected void findDelegate() { if (delegate == null) { Collection<TimerJobInstance> timers = TimerServiceRegistry.getInstance().get(timerServiceId) .getTimerJobFactoryManager().getTimerJobInstances(); for (TimerJobInstance instance : timers) { if (((GlobalQuartzJobHandle)instance.getJobHandle()).getJobName().equals(jobname)) { delegate = instance; break; } } } }
@Override public void internalSchedule(TimerJobInstance timerJobInstance) { if (scheduler.isShutdown()) { return; } Date date = timerJobInstance.getTrigger().hasNextFireTime(); Callable<Void> item = (Callable<Void>) timerJobInstance; GlobalJDKJobHandle jobHandle = (GlobalJDKJobHandle) timerJobInstance.getJobHandle(); long then = date.getTime(); long now = System.currentTimeMillis(); ScheduledFuture<Void> future = null; if ( then >= now ) { future = scheduler.schedule( new RetriggerCallable(scheduler, item), then - now, TimeUnit.MILLISECONDS ); } else { future = scheduler.schedule( new RetriggerCallable(scheduler, item), 0, TimeUnit.MILLISECONDS ); } jobHandle.setFuture( future ); globalTimerService.getTimerJobFactoryManager().addTimerJobInstance( timerJobInstance ); }
return; globalTimerService.getTimerJobFactoryManager().addTimerJobInstance( timerJobInstance ); JobDetail jobDetail = scheduler.getJobDetail(jobKey(quartzJobHandle.getJobName(), quartzJobHandle.getJobGroup())); if (jobDetail == null) { globalTimerService.getTimerJobFactoryManager().removeTimerJobInstance(timerJobInstance); throw new RuntimeException(e); globalTimerService.getTimerJobFactoryManager().removeTimerJobInstance(timerJobInstance); throw new RuntimeException("Exception while scheduling job", e);
getTimerJobFactoryManager().createTimerJobInstance( job, ctx, trigger,
public ProcessRuntimeImpl(InternalKnowledgeRuntime kruntime) { this.kruntime = kruntime; TimerService timerService = kruntime.getTimerService(); if ( !(timerService.getTimerJobFactoryManager() instanceof CommandServiceTimerJobFactoryManager) ) { timerService.setTimerJobFactoryManager( new ThreadSafeTrackableTimeJobFactoryManager() ); } ((CompositeClassLoader) getRootClassLoader()).addClassLoader( getClass().getClassLoader() ); initProcessInstanceManager(); initSignalManager(); timerManager = new TimerManager(kruntime, kruntime.getTimerService()); processEventSupport = new ProcessEventSupport(); if (isActive()) { initProcessEventListeners(); initStartTimers(); } initProcessActivationListener(); }
getTimerJobFactoryManager().createTimerJobInstance( job, ctx, trigger,
@Override public boolean removeJob(JobHandle jobHandle) { if (jobHandle == null) { return false; } jobHandle.setCancel( true ); JobContext jobContext = ((GlobalJDKJobHandle) jobHandle).getTimerJobInstance().getJobContext(); try { ProcessJobContext processCtx = null; if (jobContext instanceof SelfRemovalJobContext) { processCtx = (ProcessJobContext) ((SelfRemovalJobContext) jobContext).getJobContext(); } else { processCtx = (ProcessJobContext) jobContext; } String jobname = processCtx.getSessionId() + "-" + processCtx.getProcessInstanceId() + "-" + processCtx.getTimer().getId(); if (processCtx instanceof StartProcessJobContext) { jobname = "StartProcess-"+((StartProcessJobContext) processCtx).getProcessId()+ "-" + processCtx.getTimer().getId(); } activeTimer.remove(jobname); globalTimerService.getTimerJobFactoryManager().removeTimerJobInstance( ((GlobalJDKJobHandle) jobHandle).getTimerJobInstance() ); } catch (ClassCastException e) { // do nothing in case ProcessJobContext was not given } boolean removed = this.scheduler.remove( (Runnable) ((GlobalJDKJobHandle) jobHandle).getFuture() ); return removed; }
public ProcessRuntimeImpl(InternalWorkingMemory workingMemory) { TimerService timerService = workingMemory.getTimerService(); if ( !(timerService.getTimerJobFactoryManager() instanceof CommandServiceTimerJobFactoryManager) ) { timerService.setTimerJobFactoryManager( new ThreadSafeTrackableTimeJobFactoryManager() ); } this.kruntime = (InternalKnowledgeRuntime) workingMemory.getKnowledgeRuntime(); initProcessInstanceManager(); initSignalManager(); timerManager = new TimerManager(kruntime, kruntime.getTimerService()); processEventSupport = new ProcessEventSupport(); if (isActive()) { initProcessEventListeners(); initStartTimers(); } initProcessActivationListener(); }
@Override public TimerJobFactoryManager getTimerJobFactoryManager() { return timerService.getTimerJobFactoryManager(); }
@Override public void init( KieSession ksession ) { // The ExecutableRunner for the TimerJobFactoryManager must be set before any timer jobs are scheduled. // Otherwise, if overdue jobs are scheduled (and then run before the .executorDelegate field can be set), // they will retrieve a null executorDelegate (instead of a reference to this) and fail. TimerJobFactoryManager timerJobFactoryManager = ((InternalKnowledgeRuntime) ksession ).getTimerService().getTimerJobFactoryManager(); if (timerJobFactoryManager instanceof CommandServiceTimerJobFactoryManager) { ( (CommandServiceTimerJobFactoryManager) timerJobFactoryManager ).setRunner( runner ); } } }
public Void call() throws Exception { try { JDKCallableJobCommand command = new JDKCallableJobCommand( this ); ExecutableRunner runner = ( (CommandServiceTimerJobFactoryManager) ( (TimerService) scheduler ).getTimerJobFactoryManager() ).getRunner(); runner.execute( command ); return null; } catch( Exception e ) { logger.error("Unable to execute timer job!", e); throw e; } }
public Void call() throws Exception { try { JDKCallableJobCommand command = new JDKCallableJobCommand( this ); TimerJobFactoryManager timerJobFactoryManager = ( (TimerService)scheduler ).getTimerJobFactoryManager(); ExecutableRunner commandService = ( (CommandServiceTimerJobFactoryManager) timerJobFactoryManager ).getRunner(); commandService.execute( command ); return null; } catch( Exception e ) { logger.error("Unable to execute timer job!", e); throw e; } }
protected void findDelegate() { if (delegate == null) { Collection<TimerJobInstance> timers = TimerServiceRegistry.getInstance().get(timerServiceId) .getTimerJobFactoryManager().getTimerJobInstances(); for (TimerJobInstance instance : timers) { if (((GlobalQuartzJobHandle)instance.getJobHandle()).getJobName().equals(jobname)) { delegate = instance; break; } } } }
@Override public void internalSchedule(TimerJobInstance timerJobInstance) { if (scheduler.isShutdown()) { return; } Date date = timerJobInstance.getTrigger().hasNextFireTime(); Callable<Void> item = (Callable<Void>) timerJobInstance; GlobalJDKJobHandle jobHandle = (GlobalJDKJobHandle) timerJobInstance.getJobHandle(); long then = date.getTime(); long now = System.currentTimeMillis(); ScheduledFuture<Void> future = null; if ( then >= now ) { future = scheduler.schedule( new RetriggerCallable(scheduler, item), then - now, TimeUnit.MILLISECONDS ); } else { future = scheduler.schedule( new RetriggerCallable(scheduler, item), 0, TimeUnit.MILLISECONDS ); } jobHandle.setFuture( future ); globalTimerService.getTimerJobFactoryManager().addTimerJobInstance( timerJobInstance ); }
@Override public JobHandle scheduleJob(Job job, JobContext ctx, Trigger trigger) { Long id = idCounter.getAndIncrement(); String jobName = getJobName(ctx, id); EjbGlobalJobHandle jobHandle = new EjbGlobalJobHandle(id, jobName, ((GlobalTimerService) globalTimerService).getTimerServiceId()); TimerJobInstance jobInstance = null; // check if given timer job is marked as new timer meaning it was never scheduled before, // if so skip the check by timer name as it has no way to exist if (!isNewTimer(ctx)) { jobInstance = scheduler.getTimerByName(jobName); if (jobInstance != null) { return jobInstance.getJobHandle(); } } jobInstance = globalTimerService.getTimerJobFactoryManager().createTimerJobInstance( job, ctx, trigger, jobHandle, (InternalSchedulerService) globalTimerService); jobHandle.setTimerJobInstance((TimerJobInstance) jobInstance); interceptor.internalSchedule(jobInstance); return jobHandle; }
public ProcessRuntimeImpl(InternalKnowledgeRuntime kruntime) { this.kruntime = kruntime; TimerService timerService = kruntime.getTimerService(); if ( !(timerService.getTimerJobFactoryManager() instanceof CommandServiceTimerJobFactoryManager) ) { timerService.setTimerJobFactoryManager( new ThreadSafeTrackableTimeJobFactoryManager() ); } ((CompositeClassLoader) getRootClassLoader()).addClassLoader( getClass().getClassLoader() ); initProcessInstanceManager(); initSignalManager(); timerManager = new TimerManager(kruntime, kruntime.getTimerService()); processEventSupport = new ProcessEventSupport(); if (isActive()) { initProcessEventListeners(); initStartTimers(); } initProcessActivationListener(); }
@Override public boolean removeJob(JobHandle jobHandle) { if (jobHandle == null) { return false; } jobHandle.setCancel( true ); JobContext jobContext = ((GlobalJDKJobHandle) jobHandle).getTimerJobInstance().getJobContext(); try { ProcessJobContext processCtx = null; if (jobContext instanceof SelfRemovalJobContext) { processCtx = (ProcessJobContext) ((SelfRemovalJobContext) jobContext).getJobContext(); } else { processCtx = (ProcessJobContext) jobContext; } String jobname = processCtx.getSessionId() + "-" + processCtx.getProcessInstanceId() + "-" + processCtx.getTimer().getId(); if (processCtx instanceof StartProcessJobContext) { jobname = "StartProcess-"+((StartProcessJobContext) processCtx).getProcessId()+ "-" + processCtx.getTimer().getId(); } activeTimer.remove(jobname); globalTimerService.getTimerJobFactoryManager().removeTimerJobInstance( ((GlobalJDKJobHandle) jobHandle).getTimerJobInstance() ); } catch (ClassCastException e) { // do nothing in case ProcessJobContext was not given } boolean removed = this.scheduler.remove( (Runnable) ((GlobalJDKJobHandle) jobHandle).getFuture() ); return removed; }
public ProcessRuntimeImpl(InternalWorkingMemory workingMemory) { TimerService timerService = workingMemory.getTimerService(); if ( !(timerService.getTimerJobFactoryManager() instanceof CommandServiceTimerJobFactoryManager) ) { timerService.setTimerJobFactoryManager( new ThreadSafeTrackableTimeJobFactoryManager() ); } this.kruntime = (InternalKnowledgeRuntime) workingMemory.getKnowledgeRuntime(); initProcessInstanceManager(); initSignalManager(); timerManager = new TimerManager(kruntime, kruntime.getTimerService()); processEventSupport = new ProcessEventSupport(); if (isActive()) { initProcessEventListeners(); initStartTimers(); } initProcessActivationListener(); }
protected void initNewKnowledgeSession(KieBase kbase, KieSessionConfiguration conf) { this.sessionInfo = new SessionInfo(); // create session but bypass command service this.ksession = kbase.newKieSession( conf, this.env ); initKieSessionMBeans(this.ksession); this.marshallingHelper = new SessionMarshallingHelper( this.ksession, conf ); MarshallingConfigurationImpl config = (MarshallingConfigurationImpl) this.marshallingHelper.getMarshaller().getMarshallingConfiguration(); config.setMarshallProcessInstances( false ); config.setMarshallWorkItems( false ); this.sessionInfo.setJPASessionMashallingHelper( this.marshallingHelper ); ((InternalKnowledgeRuntime) this.ksession).setEndOperationListener( new EndOperationListenerImpl(this.txm, this.sessionInfo ) ); this.runner = new TransactionInterceptor(); TimerJobFactoryManager timerJobFactoryManager = ((InternalKnowledgeRuntime) ksession ).getTimerService().getTimerJobFactoryManager(); if (timerJobFactoryManager instanceof CommandServiceTimerJobFactoryManager) { ( (CommandServiceTimerJobFactoryManager) timerJobFactoryManager ).setRunner( this ); } }