com.lmax.disruptor.biz.event.handler.AbstractEnabledEventHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of disruptor-biz Show documentation
Show all versions of disruptor-biz Show documentation
Disruptor Event Chain Integration
The newest version!
/*
* Copyright (c) 2018 (https://github.com/hiwepy).
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.lmax.disruptor.biz.event.handler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.lmax.disruptor.biz.event.DisruptorEvent;
import com.lmax.disruptor.biz.event.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;
}
}