use of org.pentaho.di.trans.ael.websocket.handler.MessageEventHandler in project pentaho-kettle by pentaho.
the class MessageEventService method addHandlerFor.
private void addHandlerFor(final Message eventType, final MessageEventHandler handler) throws HandlerRegistrationException {
// check if the given event type is already registered in the Message Service
if (containsHandlerFor(eventType)) {
// if the handler already exists for the same eventType, an Exception is thrown
final List<MessageEventHandler> handlers = getHandlersFor(eventType);
// Check if another handler of the same class is already registered
for (MessageEventHandler tmpHandler : handlers) {
if (tmpHandler.getIdentifier().equals(handler.getIdentifier())) {
throw new HandlerRegistrationException("The handler with identifier " + tmpHandler.getIdentifier() + " is already registered for the event " + eventType);
}
}
handlers.add(handler);
} else {
// if the given type doesn't already exist in the eventFilters list, we create it
final List<MessageEventHandler> newHandlerList = new ArrayList<>(10);
newHandlerList.add(handler);
registeredHandlers.put(eventType, newHandlerList);
}
}
use of org.pentaho.di.trans.ael.websocket.handler.MessageEventHandler in project pentaho-kettle by pentaho.
the class MessageEventService method getHandlersFor.
public List<MessageEventHandler> getHandlersFor(final Message eventType) {
List<MessageEventHandler> toRet = null;
if (eventType == null || registeredHandlers.isEmpty()) {
return toRet;
}
MessageComparator msgComparator = new MessageComparator();
for (Message e : registeredHandlers.keySet()) {
if (msgComparator.compare(e, eventType) == 0) {
toRet = registeredHandlers.get(e);
}
}
return toRet;
}
use of org.pentaho.di.trans.ael.websocket.handler.MessageEventHandler in project pentaho-kettle by pentaho.
the class TransWebSocketEngineAdapter method wireStatusToTransListeners.
private void wireStatusToTransListeners() throws KettleException {
messageEventService.addHandler(Util.getTransformationStatusEvent(), new MessageEventHandler() {
@Override
public void execute(Message message) throws MessageEventHandlerExecutionException {
PDIEvent<RemoteSource, Status> transStatusEvent = (PDIEvent<RemoteSource, Status>) message;
addStepPerformanceSnapShot();
getTransListeners().forEach(l -> {
try {
switch(transStatusEvent.getData()) {
case RUNNING:
l.transStarted(TransWebSocketEngineAdapter.this);
l.transActive(TransWebSocketEngineAdapter.this);
break;
case PAUSED:
break;
case STOPPED:
break;
case FAILED:
case FINISHED:
l.transFinished(TransWebSocketEngineAdapter.this);
setFinished(true);
break;
}
} catch (KettleException e) {
throw new RuntimeException(e);
}
});
}
@Override
public String getIdentifier() {
return TRANSFORMATION_STATUS;
}
});
messageEventService.addHandler(Util.getTransformationErrorEvent(), new MessageEventHandler() {
@Override
public void execute(Message message) throws MessageEventHandlerExecutionException {
Throwable throwable = ((PDIEvent<RemoteSource, LogEntry>) message).getData().getThrowable();
getLogChannel().logError("Error Executing Transformation", throwable);
errors.incrementAndGet();
finishProcess(true);
}
@Override
public String getIdentifier() {
return TRANSFORMATION_ERROR;
}
});
messageEventService.addHandler(Util.getStopMessage(), new MessageEventHandler() {
@Override
public void execute(Message message) throws MessageEventHandlerExecutionException {
StopMessage stopMessage = (StopMessage) message;
if (stopMessage.sessionWasKilled() || stopMessage.operationFailed()) {
getLogChannel().logError("Finalizing execution: " + stopMessage.getReasonPhrase());
} else {
getLogChannel().logBasic("Finalizing execution: " + stopMessage.getReasonPhrase());
}
finishProcess(false);
try {
getDaemonEndpoint().close(stopMessage.getReasonPhrase());
} catch (KettleException e) {
getLogChannel().logError("Error finalizing", e);
}
// let's shutdown the session monitor thread
closeSessionMonitor();
// Signal for the the waitUntilFinished blocker...
transFinishedSignal.countDown();
}
@Override
public String getIdentifier() {
return TRANSFORMATION_STOP;
}
});
}
Aggregations