Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (C) 2015 Stubhub.
*/
package io.bigdime.core.sink;
import java.util.LinkedHashSet;
import java.util.Observable;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import org.apache.flume.lifecycle.LifecycleState;
import io.bigdime.alert.Logger.ALERT_CAUSE;
import io.bigdime.alert.Logger.ALERT_SEVERITY;
import io.bigdime.alert.Logger.ALERT_TYPE;
import io.bigdime.alert.LoggerFactory;
import io.bigdime.core.ActionEvent.Status;
import io.bigdime.core.AdaptorConfigurationException;
import io.bigdime.core.Handler;
import io.bigdime.core.HandlerException;
import io.bigdime.core.Sink;
import io.bigdime.core.commons.AdaptorLogger;
import io.bigdime.core.config.ADAPTOR_TYPE;
import io.bigdime.core.config.AdaptorConfig;
import io.bigdime.core.constants.AdaptorConstants;
import io.bigdime.core.handler.HandlerManager;
import io.bigdime.core.handler.IllegalHandlerStateException;
/**
* Bigdime implementation of {@link Sink} interface. It uses HandlerManager to
* manage the handler chain. DataSink extends Observable to allow Sources to
* observe it. If the DataSink needs to be stopped for some reason, it notifies
* Sources about the same so that Sources can take appropriate action, e.g. stop
* or pause etc.
*
* @author Neeraj Jain
*
*/
public class DataSink extends Observable implements Sink {
private static final AdaptorLogger logger = new AdaptorLogger(LoggerFactory.getLogger(DataSink.class));
private final HandlerManager handlerManager;
private LinkedHashSet handlers;
private String name;
private String description;
private long sleepForMillis = AdaptorConstants.SLEEP_WHILE_WAITING_FOR_DATA;
private LifecycleState lifecycleState = LifecycleState.IDLE;
private final String id = UUID.randomUUID().toString();
/**
* Creates a new DataSink given the handlers and the name.
*
* @param handlers
* set of handlers that will read and process the data
* @param name
* name of the data sink
* @throws AdaptorConfigurationException
* if handler is null or empty
*/
public DataSink(final LinkedHashSet handlers, String name) throws AdaptorConfigurationException {
if ((handlers == null) || handlers.isEmpty()) {
logger.alert(ALERT_TYPE.ADAPTOR_FAILED_TO_START, ALERT_CAUSE.INVALID_ADAPTOR_CONFIGURATION,
ALERT_SEVERITY.BLOCKER, "handlers not configured");
throw new AdaptorConfigurationException("null or empty collection not allowed for handlers");
}
this.handlers = handlers;
this.handlerManager = new HandlerManager(handlers, name);
this.name = name;
}
@Override
public String toString() {
return "DataSink [handlers=" + handlers + ", name=" + name + ", description=" + description + "]";
}
@Override
public LinkedHashSet getHandlers() {
return handlers;
}
@Override
public void setHandlers(LinkedHashSet handlers) {
this.handlers = handlers;
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public LifecycleState getLifecycleState() {
return lifecycleState;
}
private boolean interrupted;
private FutureTask