/** * Enqueues the specified workflow instance into the engine for execution. * * @param wf the workflow instance to run * @param con connection used for the inserting the workflow to the database * @throws CopperException if the engine can not run the workflow, e.g. in case of a unkown * processor pool id */ public void run(Workflow<?> wf, Connection con) throws CopperException { if (logger.isTraceEnabled()) logger.trace("run(" + wf + ")"); if (!(wf instanceof PersistentWorkflow<?>)) { throw new IllegalArgumentException(wf.getClass() + " is no instance of PersistentWorkflow"); } try { startupBlocker.pass(); if (wf.getId() == null) { wf.setId(createUUID()); } if (wf.getProcessorPoolId() == null) { wf.setProcessorPoolId(PersistentProcessorPool.DEFAULT_POOL_ID); } if (processorPoolManager.getProcessorPool(wf.getProcessorPoolId()) == null) { logger.error( "Unkown processor pool '" + wf.getProcessorPoolId() + "' - using default pool instead"); wf.setProcessorPoolId(PersistentProcessorPool.DEFAULT_POOL_ID); } dbStorage.insert(wf, con); notifyProcessorPool(wf.getProcessorPoolId()); } catch (RuntimeException e) { throw e; } catch (CopperException e) { throw e; } catch (Exception e) { throw new CopperException("run failed", e); } }
void unregister(Workflow<?> wf) { Workflow<?> existingWF = workflowMap.remove(wf.getId()); assert existingWF != null; if (existingWF != null && existingWF.getProcessingState() == ProcessingState.FINISHED) { statisticsCollector.submit( getEngineId() + "." + wf.getClass().getSimpleName() + ".ExecutionTime", 1, System.currentTimeMillis() - wf.getCreationTS().getTime(), TimeUnit.MILLISECONDS); } getAndRemoveWaitHooks(wf); // Clean up... }
private List<WaitHook> getAndRemoveWaitHooks(Workflow<?> wf) { synchronized (waitHookMap) { List<WaitHook> l = waitHookMap.remove(wf.getId()); return l == null ? Collections.<WaitHook>emptyList() : l; } }
void register(Workflow<?> wf) { if (logger.isTraceEnabled()) logger.trace("register(" + wf.getId() + ")"); Workflow<?> existingWF = workflowMap.put(wf.getId(), wf); assert existingWF == null; }