public void addLockedWorkflowInstance(WorkflowInstanceImpl lockedWorkflowInstance) { if (lockedWorkflowInstances == null) { lockedWorkflowInstances = new HashMap<>(); } lockedWorkflowInstances.put(lockedWorkflowInstance.getId(), lockedWorkflowInstance); }
public WorkflowInstance toWorkflowInstance() { return toWorkflowInstance(false); }
protected ScopeInstanceImpl getScopeInstance(WorkflowInstanceImpl workflowInstance, String activityInstanceId) { ScopeInstanceImpl scopeInstance = workflowInstance; if (activityInstanceId!=null) { scopeInstance = workflowInstance.findActivityInstance(activityInstanceId); Exceptions.checkNotNull(scopeInstance); } return scopeInstance; }
public void addWork(ActivityInstanceImpl activityInstance) { if (isWorkAsync(activityInstance)) { addAsyncWork(activityInstance); } else { addSyncWork(activityInstance); } }
public void removeLock() { setLock(null); if (updates != null) { getUpdates().isLockChanged = true; } }
@Override public void flushAndUnlock(WorkflowInstanceImpl workflowInstance) { lockedWorkflowInstanceIds.remove(workflowInstance.id); workflowInstance.removeLock(); workflowInstance.notifyUnlockListeners(); }
public WorkflowInstance executeWork() { boolean isFirst = true; while (hasWork()) { ActivityInstanceImpl activityInstance = getNextWork(); ActivityImpl activity = activityInstance.getActivity(); ActivityType activityType = activity.activityType; isFirst = false; } else { flushDbUpdates(); WorkflowInstance workflowInstanceSnapshot = workflowInstance.toWorkflowInstance(); if (hasAsyncWork()) { if (log.isDebugEnabled()) log.debug("Going asynchronous " + this); flushDbUpdates(); Runnable asyncContinuation = new Runnable() { public void run() {
public void setLock(LockImpl lock) { this.lock = lock; if (updates != null) { getUpdates().isLockChanged = true; } }
public void assertResolveTemplate(String expected, TextTemplate tt) { WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl(); workflowInstance.configuration = configuration; workflowInstance.workflowInstance = workflowInstance; workflowInstance.nextVariableInstanceId = 1l; workflowInstance.setVariableValue("v1", "x"); workflowInstance.setVariableValue("v2", "y"); assertEquals(expected, tt.resolve(workflowInstance)); }
if (log.isDebugEnabled()) log.debug("Flushing workflow instance..."); WorkflowInstanceUpdates updates = workflowInstance.getUpdates(); sets.append(END_STATE, workflowInstance.getEndState()); sets.append(PROPERTIES, new BasicDBObject(workflowInstance.getProperties())); else unsets.append(PROPERTIES, 1); workflowInstance.trackUpdates(false);
return null; WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl(); workflowInstance.id = readWorkflowInstanceId(dbWorkflowInstance, _ID); workflowInstance.businessKey = readString(dbWorkflowInstance, BUSINESS_KEY); workflowInstance.workAsync = readWork(dbWorkflowInstance, WORK_ASYNC, workflowInstance); workflowInstance.properties = readObjectMap(dbWorkflowInstance, PROPERTIES); workflowInstance.setProperty(ORGANIZATION_ID, readObject(dbWorkflowInstance, ORGANIZATION_ID));
@Override public WorkflowInstance cancel(WorkflowInstanceId workflowInstanceId) { WorkflowInstanceImpl workflowInstance = lockWorkflowInstanceWithRetry(workflowInstanceId); workflowInstance.cancel(); return workflowInstance.toWorkflowInstance(); }
/** * Notifies event listeners tha the workflow instance has finished execution. */ public void workflowInstanceEnded() { workflow.workflowEngine.notifyWorkflowInstanceEnded(workflowInstance); destroyScopeInstance(); if (callingWorkflowInstanceId != null) { WorkflowInstanceImpl callingWorkflowInstance = getLockedWorkflowInstance(callingWorkflowInstanceId); final ActivityInstanceImpl callingActivityInstance = callingWorkflowInstance.findActivityInstance(callingActivityInstanceId); if (log.isDebugEnabled()) log.debug("Notifying calling activity instance " + callingActivityInstance); ActivityImpl activityDefinition = callingActivityInstance.getActivity(); final SubProcessImpl callActivity = (SubProcessImpl) activityDefinition.activityType; callActivity.calledWorkflowInstanceEnded(callingActivityInstance, this); } }
public synchronized void lockWorkflowInstance(WorkflowInstanceImpl workflowInstance) { WorkflowInstanceId workflowInstanceId = workflowInstance.getId(); if (lockedWorkflowInstanceIds.contains(workflowInstanceId)) { throw new RuntimeException("Process instance "+workflowInstanceId+" is already locked"); } lockedWorkflowInstanceIds.add(workflowInstanceId); LockImpl lock = new LockImpl(); lock.setTime(Time.now()); lock.setOwner(workflowEngineId); workflowInstance.setLock(lock); if (log.isDebugEnabled()) { log.debug("Locked process instance "+workflowInstanceId); } }
public WorkflowInstance send(Message message, WorkflowInstanceImpl workflowInstance) { Map<String, Object> transientData = message.getTransientData(); if (transientData !=null) { for (String key: transientData.keySet()) { workflowInstance.setTransientProperty(key, transientData.get(key)); } } String activityInstanceId = message.getActivityInstanceId(); ActivityInstanceImpl activityInstance = workflowInstance.findActivityInstance(activityInstanceId); if (activityInstance==null) { workflowInstanceStore.unlockWorkflowInstance(workflowInstance); throw new RuntimeException("Activity instance "+activityInstanceId+" not in workflow instance"); } if (log.isDebugEnabled()) log.debug("Signalling "+activityInstance); ActivityImpl activity = activityInstance.getActivity(); activity.activityType.message(activityInstance, message); return workflowInstance.executeWork(); }
protected void initializeTimers() { if (scope.timers!=null) { for (TimerImpl timer: scope.timers) { Job job = timer.createJob(this); job.workflowInstanceId(workflowInstance.getId()); job.activityInstanceId(getActivityInstanceId()); workflowInstance.addJob(job); // workflow.configuration // .get(JobStore.class) // .saveJob(job); } } }
/** * Starts the subworkflow instance. */ protected void startWorkflowInstance(ActivityInstanceImpl activityInstance, TriggerInstance triggerInstance) { Configuration configuration = activityInstance.getConfiguration(); WorkflowEngineImpl workflowEngine = configuration.get(WorkflowEngineImpl.class); WorkflowInstanceImpl calledWorkflowInstance = workflowEngine.startInitialize(triggerInstance); calledWorkflowInstance.addLockedWorkflowInstance(activityInstance.workflowInstance); activityInstance.setCalledWorkflowInstanceId(calledWorkflowInstance.getId()); workflowEngine.startExecute(calledWorkflowInstance); }
/** convenience method to set all activity instance related properties in one go */ public Job activityInstance(ActivityInstanceImpl activityInstance) { activityInstanceId(activityInstance.getId()); workflowInstanceId(activityInstance.getWorkflowInstance().getId()); workflowId(activityInstance.getWorkflowInstance().getWorkflow().getId()); sourceWorkflowId(activityInstance.getWorkflowInstance().getWorkflow().getSourceWorkflowId()); return this; }
@Override public void execute(JobController jobController) { ActivityInstanceImpl activityInstance = jobController.getWorkflowInstance().findActivityInstance(jobController.getJob().getActivityInstanceId()); if (activityInstance != null) { for (TimerImpl timer : activityInstance.activity.getTimers()) { if (timer.timer instanceof BoundaryEventTimer) { BoundaryEventTimer boundaryEventTimer = (BoundaryEventTimer) timer.timer; for (String transitionId : boundaryEventTimer.boundaryEvent.getToTransitionIds()) { activityInstance.takeTransition( jobController.getWorkflowInstance().getWorkflow().findTransitionByIdLocal(transitionId)); } } } jobController.getWorkflowInstance().executeWork(); } else { if (log.isDebugEnabled()) log.debug("activityInstance is null, job is not executed. Looked for activityInstance: " + jobController.getJob().getActivityInstanceId()); } } }
/** first part of starting a new workflow instance: creating the workflow instance and applying the trigger data */ public WorkflowInstanceImpl startInitialize(TriggerInstance triggerInstance) { WorkflowId workflowId = getLatestWorkflowId(triggerInstance); WorkflowImpl workflow = getWorkflowImpl(workflowId); LockImpl lock = new LockImpl(); lock.setTime(Time.now()); lock.setOwner(getId()); WorkflowInstanceId workflowInstanceId = triggerInstance.getWorkflowInstanceId(); if (workflowInstanceId==null) { workflowInstanceId = workflowInstanceStore.generateWorkflowInstanceId(); } WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl( configuration, workflow, workflowInstanceId, triggerInstance, lock, triggerInstance.getTransientData()); if (log.isDebugEnabled()) log.debug("Created "+workflowInstance); if (workflow.trigger!=null) { workflow.trigger.applyTriggerData(workflowInstance, triggerInstance); } else { workflowInstance.setVariableValues(triggerInstance); } notifyWorkflowInstanceStarted(workflowInstance); return workflowInstance; }