try {
jobExecutionContext = createJEC(jobExecutionContext.getExperimentID(),
jobExecutionContext.getTaskData().getTaskID(), jobExecutionContext.getGatewayID());
} catch (Exception e) {
log.error("Error constructing job execution context during outhandler invocation");
throw new GFacException(e);
}
launch(jobExecutionContext);
}
monitorPublisher.publish(new GfacExperimentStateChangeRequest(new MonitorID(jobExecutionContext), GfacExperimentState.OUTHANDLERSINVOKING));
for (GFacHandlerConfig handlerClassName : handlers) {
Class<? extends GFacHandler> handlerClass;
GFacHandler handler;
try {
GFacUtils.createPluginZnode(zk, jobExecutionContext, handlerClassName.getClassName());
handlerClass = Class.forName(handlerClassName.getClassName().trim()).asSubclass(GFacHandler.class);
handler = handlerClass.newInstance();
handler.initProperties(handlerClassName.getProperties());
} catch (ClassNotFoundException e) {
log.error(e.getMessage());
throw new GFacException("Cannot load handler class " + handlerClassName, e);
} catch (InstantiationException e) {
log.error(e.getMessage());
throw new GFacException("Cannot instantiate handler class " + handlerClassName, e);
} catch (IllegalAccessException e) {
log.error(e.getMessage());
throw new GFacException("Cannot instantiate handler class " + handlerClassName, e);
} catch (Exception e) {
throw new GFacException("Cannot instantiate handler class " + handlerClassName, e);
}
try {
handler.invoke(jobExecutionContext);
GFacUtils.updatePluginState(zk, jobExecutionContext, handlerClassName.getClassName(), GfacPluginState.COMPLETED);
} catch (Exception e) {
// TODO: Better error reporting.
throw new GFacException("Error Executing a OutFlow Handler", e);
}
monitorPublisher.publish(new GfacExperimentStateChangeRequest(new MonitorID(jobExecutionContext), GfacExperimentState.OUTHANDLERSINVOKED));
}
// At this point all the execution is finished so we update the task and experiment statuses.