All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.vindell.websocket.session.handler.AbstractEnabledEventHandler Maven / Gradle / Ivy

The newest version!
package com.github.vindell.websocket.session.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.vindell.websocket.event.WebSocketMessageEvent;
import com.github.vindell.websocket.session.handler.chain.HandlerChain;

public abstract class AbstractEnabledEventHandler extends AbstractNameableEventHandler {

	protected final Logger LOG = LoggerFactory.getLogger(AbstractEnabledEventHandler.class);
	protected boolean enabled = true;

	protected abstract void doHandlerInternal(T event, HandlerChain handlerChain) throws Exception;

	@Override
	public void doHandler(T event, HandlerChain handlerChain) throws Exception {

		if (!isEnabled(event)) {
			LOG.debug("Handler '{}' is not enabled for the current event.  Proceeding without invoking this handler.",
					getName());
			// Proceed without invoking this handler...
			handlerChain.doHandler(event);
		} else {
			LOG.trace("Handler '{}' enabled.  Executing now.", getName());
			doHandlerInternal(event, handlerChain);
		}

	}
	
	protected boolean isEnabled(T event) throws Exception {
		return isEnabled();
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy