Search in sources :

Example 6 with TimerNodeInstance

use of org.jbpm.workflow.instance.node.TimerNodeInstance in project jbpm by kiegroup.

the class MigrationManager method rescheduleTimersAfterMigration.

protected void rescheduleTimersAfterMigration(RuntimeManager manager, Map<Long, List<TimerInstance>> timerMigrated) {
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(migrationSpec.getProcessInstanceId()));
    try {
        engine.getKieSession().execute(new ExecutableCommand<Void>() {

            private static final long serialVersionUID = 7144657913971146080L;

            @Override
            public Void execute(Context context) {
                KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
                TimerManager timerManager = getTimerManager(kieSession);
                WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) kieSession.getProcessInstance(migrationSpec.getProcessInstanceId());
                for (Entry<Long, List<TimerInstance>> entry : timerMigrated.entrySet()) {
                    org.jbpm.workflow.instance.NodeInstance active = processInstance.getNodeInstance(entry.getKey(), false);
                    if (active instanceof TimerNodeInstance) {
                        TimerInstance timerInstance = entry.getValue().get(0);
                        long delay = timerInstance.getDelay() - (System.currentTimeMillis() - timerInstance.getActivated().getTime());
                        timerInstance.setDelay(delay);
                        timerManager.registerTimer(timerInstance, processInstance);
                        ((TimerNodeInstance) active).internalSetTimerId(timerInstance.getId());
                    } else if (active instanceof StateBasedNodeInstance) {
                        List<TimerInstance> timerInstances = entry.getValue();
                        List<Long> timers = new ArrayList<>();
                        for (TimerInstance timerInstance : timerInstances) {
                            long delay = timerInstance.getDelay() - (System.currentTimeMillis() - timerInstance.getActivated().getTime());
                            timerInstance.setDelay(delay);
                            timerManager.registerTimer(timerInstance, processInstance);
                            timers.add(timerInstance.getId());
                        }
                        ((StateBasedNodeInstance) active).internalSetTimerInstances(timers);
                    }
                }
                return null;
            }
        });
    } finally {
        manager.disposeRuntimeEngine(engine);
    }
}
Also used : RegistryContext(org.drools.core.command.impl.RegistryContext) Context(org.kie.api.runtime.Context) ProcessInstanceIdContext(org.kie.internal.runtime.manager.context.ProcessInstanceIdContext) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) StateBasedNodeInstance(org.jbpm.workflow.instance.node.StateBasedNodeInstance) TimerInstance(org.jbpm.process.instance.timer.TimerInstance) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList) TimerManager(org.jbpm.process.instance.timer.TimerManager) Entry(java.util.Map.Entry) KieSession(org.kie.api.runtime.KieSession) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) StateBasedNodeInstance(org.jbpm.workflow.instance.node.StateBasedNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance)

Aggregations

TimerNodeInstance (org.jbpm.workflow.instance.node.TimerNodeInstance)6 ArrayList (java.util.ArrayList)5 NodeInstance (org.kie.api.runtime.process.NodeInstance)5 List (java.util.List)4 HumanTaskNodeInstance (org.jbpm.workflow.instance.node.HumanTaskNodeInstance)4 StateBasedNodeInstance (org.jbpm.workflow.instance.node.StateBasedNodeInstance)4 HashMap (java.util.HashMap)3 RegistryContext (org.drools.core.command.impl.RegistryContext)3 TimerInstance (org.jbpm.process.instance.timer.TimerInstance)3 TimerManager (org.jbpm.process.instance.timer.TimerManager)3 KieSession (org.kie.api.runtime.KieSession)3 Collection (java.util.Collection)2 Map (java.util.Map)2 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)2 NodeInstanceContent (org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent)2 TextMapEntry (org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.TextMapEntry)2 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)2 AsyncEventNodeInstance (org.jbpm.workflow.instance.node.AsyncEventNodeInstance)2 CompositeContextNodeInstance (org.jbpm.workflow.instance.node.CompositeContextNodeInstance)2 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)2