public ConditionCallBack(String jobIdentifier) { this.jobIdentifier = jobIdentifier; AbstractDispatchEvent originalEvent; synchronized (incomingJobs) { originalEvent = incomingJobs.get(jobIdentifier); } context = originalEvent.getContext(); processId = originalEvent.getOwningProcess() + ":condition"; }
private String jobIdentifier(AbstractDispatchEvent event) { String jobId = event.getOwningProcess() + Arrays.toString(event.getIndex()); return jobId; }
@Override public void fail(String message, Throwable t, DispatchErrorType errorType) { logger.warn("Failed (" + errorType + ") invoking condition service " + jobIdentifier + ":" + message, t); AbstractDispatchEvent originalEvent; synchronized (incomingJobs) { originalEvent = incomingJobs.get(jobIdentifier); } receiveError(new DispatchErrorEvent(originalEvent .getOwningProcess(), originalEvent.getIndex(), originalEvent.getContext(), "Can't invoke condition service ", t, DispatchErrorType.INVOCATION, null)); }
private DispatchJobEvent prepareNewJobEvent( Map<String, T2Reference> data, AbstractDispatchEvent dispatchEvent) { DispatchJobEvent dispatchJobEvent = (DispatchJobEvent) dispatchEvent; Map<String, T2Reference> newInputs = new HashMap<String, T2Reference>( dispatchJobEvent.getData()); newInputs.putAll(data); DispatchJobEvent newJobEvent = new DispatchJobEvent(dispatchEvent .getOwningProcess(), dispatchEvent.getIndex(), dispatchEvent.getContext(), newInputs, ((DispatchJobEvent) dispatchEvent).getActivities()); /* * TODO: Should this be registered as an incomingJobs? If so the * conditional could even feed to itself, and we should also keep a * list of originalJobs. */ return newJobEvent; }
private void checkCondition(AbstractDispatchEvent event) { Activity<?> condition = getCondition(); if (condition == null) { super.receiveError(new DispatchErrorEvent(event.getOwningProcess(), event.getIndex(), event.getContext(), "Can't invoke condition service: null", null, DispatchErrorType.INVOCATION, condition)); return; } if (!(condition instanceof AbstractAsynchronousActivity)) { DispatchErrorEvent errorEvent = new DispatchErrorEvent( event.getOwningProcess(), event.getIndex(), event.getContext(), "Can't invoke condition service " + condition + " is not an instance of AbstractAsynchronousActivity", null, DispatchErrorType.INVOCATION, condition); super.receiveError(errorEvent); return; } AbstractAsynchronousActivity asyncCondition = (AbstractAsynchronousActivity) condition; String jobIdentifier = jobIdentifier(event); Map<String, T2Reference> inputs = prepareInputs(asyncCondition, jobIdentifier); AsynchronousActivityCallback callback = new ConditionCallBack( jobIdentifier); asyncCondition.executeAsynch(inputs, callback); }