Search in sources :

Example 1 with HandlerRegistrationException

use of org.pentaho.di.trans.ael.websocket.exception.HandlerRegistrationException 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);
    }
}
Also used : HandlerRegistrationException(org.pentaho.di.trans.ael.websocket.exception.HandlerRegistrationException) ArrayList(java.util.ArrayList) MessageEventHandler(org.pentaho.di.trans.ael.websocket.handler.MessageEventHandler)

Aggregations

ArrayList (java.util.ArrayList)1 HandlerRegistrationException (org.pentaho.di.trans.ael.websocket.exception.HandlerRegistrationException)1 MessageEventHandler (org.pentaho.di.trans.ael.websocket.handler.MessageEventHandler)1