public JobExecution(Job job, Configuration configuration, WorkflowInstanceImpl workflowInstance) { this.job = job; this.workflowInstance = workflowInstance; this.time = Time.now(); this.configuration = configuration; }
public ScopeInstanceImpl(ScopeInstanceImpl parent, ScopeImpl scope) { super(parent); this.scope = scope; this.start = Time.now(); }
public boolean isDue() { return dueDate ==null || dueDate.compareTo(Time.now())<=0; }
public void cancel() { if (this.end==null) { this.setEnd(Time.now()); this.endState = ScopeInstance.ENDSTATE_CANCELED; if (activityInstances!=null) { for (ActivityInstanceImpl activityInstance: activityInstances) { activityInstance.cancel(); } } } } }
public LocalDateTime resolve(ActivityInstanceImpl activityInstance) { LocalDateTime baseTime = null; if (activityInstance!=null && base!=null) { baseTime = activityInstance.getValue(base); } if (baseTime==null) { baseTime = Time.now(); } LocalDateTime time = relativeTime.resolve(baseTime); return time; } }
/** * Instructs the engine to propagate execution forwards after ending the current activity instance. */ public void endAndPropagateToParent() { if (this.end == null) { if (hasOpenActivityInstances()) { throw new RuntimeException("Can't end this process instance. There are open activity instances: " + this); } setEnd(Time.now()); if (log.isDebugEnabled()) { log.debug("Ends " + this); } workflowInstanceEnded(); } }
protected BasicDBObjectBuilder buildLockNextJobQuery() { Date now = Time.now().toDate(); return BasicDBObjectBuilder.start() .append("$or", new DBObject[]{ new BasicDBObject(DUE_DATE, new BasicDBObject("$exists", false)), new BasicDBObject(DUE_DATE, new BasicDBObject("$lte", now)) }) .push(DONE).append("$exists", false).pop(); }
protected BasicDBObjectBuilder buildLockNextJobQuery() { Date now = Time.now().toDate(); return BasicDBObjectBuilder.start() .append("$or", new DBObject[]{ new BasicDBObject(DUE_DATE, new BasicDBObject("$exists", false)), new BasicDBObject(DUE_DATE, new BasicDBObject("$lte", now)) }) .push(DONE).append("$exists", false).pop(); }
public void rescheduleFromNow(int delayInMillis) { rescheduleFor(Time.now().plusMillis((int)delayInMillis)); }
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 void end() { if (end==null) { if (hasOpenActivityInstances()) { throw new RuntimeException("Can't end this activity instance. There are open activity instances: " +this); } setEnd(Time.now()); workflow.workflowEngine.notifyActivityInstanceEnded(this); destroyScopeInstance(); setWorkState(null); } }
@Override public WorkflowInstanceImpl lockWorkflowInstanceWithJobsDue() { DBObject query = createLockQuery(); query.put(JobFields.DONE, new BasicDBObject("$exists", false)); query.put(JOBS + "." + JobFields.DUE_DATE, new BasicDBObject("$lte", Time.now().toDate())); DBObject update = createLockUpdate(); DBObject retrieveFields = new BasicDBObject() .append(ARCHIVED_ACTIVITY_INSTANCES, false); BasicDBObject dbWorkflowInstance = workflowInstancesCollection.findAndModify("lock-workflow-instance", query, update, retrieveFields, new BasicDBObject(START, 1), false, true, false); if (dbWorkflowInstance==null) { return null; } WorkflowInstanceImpl workflowInstance = readWorkflowInstanceImpl(dbWorkflowInstance); workflowInstance.trackUpdates(false); return workflowInstance; }
@Override public WorkflowInstanceImpl lockWorkflowInstanceWithJobsDue() { DBObject query = createLockQuery(); query.put(JobFields.DONE, new BasicDBObject("$exists", false)); query.put(JOBS + "." + JobFields.DUE_DATE, new BasicDBObject("$lte", Time.now().toDate())); DBObject update = createLockUpdate(); DBObject retrieveFields = new BasicDBObject() .append(ARCHIVED_ACTIVITY_INSTANCES, false); BasicDBObject dbWorkflowInstance = workflowInstancesCollection.findAndModify("lock-workflow-instance", query, update, retrieveFields, new BasicDBObject(START, 1), false, true, false); if (dbWorkflowInstance==null) { return null; } WorkflowInstanceImpl workflowInstance = readWorkflowInstanceImpl(dbWorkflowInstance); workflowInstance.trackUpdates(false); return workflowInstance; }
public WorkflowInstanceImpl(Configuration configuration, WorkflowImpl workflow, WorkflowInstanceId workflowInstanceId, TriggerInstance triggerInstance, LockImpl lock, Map<String, Object> transientProperties) { this.id = workflowInstanceId; this.configuration = configuration; this.workflow = workflow; this.scope = workflow; this.workflowInstance = this; this.start = Time.now(); this.nextActivityInstanceId = 1l; this.nextVariableInstanceId = 1l; this.nextTimerInstanceId = 1l; this.businessKey = triggerInstance.getBusinessKey(); this.callingWorkflowInstanceId = triggerInstance.getCallingWorkflowInstanceId(); this.callingActivityInstanceId = triggerInstance.getCallingActivityInstanceId(); this.startActivityIds = triggerInstance.getStartActivityIds(); this.lock = lock; this.transientProperties = transientProperties; this.initializeVariableInstances(); }
public DBObject createLockUpdate() { return BasicDBObjectBuilder.start() .push("$set") .push(LOCK) .add(Lock.TIME, Time.now().toDate()) .add(Lock.OWNER, workflowEngine.getId()) .pop() .pop() .get(); }
public DBObject createLockUpdate() { return BasicDBObjectBuilder.start() .push("$set") .push(LOCK) .add(Lock.TIME, Time.now().toDate()) .add(Lock.OWNER, workflowEngine.getId()) .pop() .pop() .get(); }
/** 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; }
@Override public Deployment deployWorkflow(ExecutableWorkflow workflow) { if (log.isDebugEnabled()) { log.debug("Deploying workflow"); } WorkflowParser parser = new WorkflowParser(configuration); parser.parse(workflow); if (!parser.hasErrors()) { WorkflowImpl workflowImpl = parser.getWorkflow(); WorkflowId workflowId; if (workflow.getId()==null) { workflowId = workflowStore.generateWorkflowId(); workflow.setId(workflowId); } workflow.setCreateTime(Time.now()); workflowImpl.id = workflow.getId(); workflowStore.insertWorkflow(workflow); if (workflowImpl.trigger!=null) { workflowImpl.trigger.published(workflowImpl); } workflowCache.put(workflowImpl); } return new Deployment(workflow.getId(), parser.getIssues()); }
public Job lockNextJob(DBObject query) { DBObject dbLock = BasicDBObjectBuilder.start() .append(TIME, Time.now().toDate()) .append(OWNER, lockOwner) .get(); DBObject update = BasicDBObjectBuilder.start() .push("$set").append(LOCK, dbLock).pop() .get(); BasicDBObject dbJob = jobsCollection.findAndModify("lock-next-job", query, update); if (dbJob!=null) { return readJob(dbJob); } return null; }