use of org.jboss.netty.util.Timeout in project opentsdb by OpenTSDB.
the class TSDB method shutdown.
/**
* Gracefully shuts down this TSD instance.
* <p>
* The method must call {@code shutdown()} on all plugins as well as flush the
* compaction queue.
* @return A {@link Deferred} that will be called once all the un-committed
* data has been successfully and durably stored, and all resources used by
* this instance have been released. The value of the deferred object
* return is meaningless and unspecified, and can be {@code null}.
* @throws HBaseException (deferred) if there was a problem sending
* un-committed data to HBase. Please refer to the {@link HBaseException}
* hierarchy to handle the possible failures. Some of them are easily
* recoverable by retrying, some are not.
*/
public Deferred<Object> shutdown() {
final ArrayList<Deferred<Object>> deferreds = new ArrayList<Deferred<Object>>();
final class FinalShutdown implements Callback<Object, Object> {
@Override
public Object call(Object result) throws Exception {
if (result instanceof Exception) {
LOG.error("A previous shutdown failed", (Exception) result);
}
final Set<Timeout> timeouts = timer.stop();
// TODO - at some point we should clean these up.
if (timeouts.size() > 0) {
LOG.warn("There were " + timeouts.size() + " timer tasks queued");
}
LOG.info("Completed shutting down the TSDB");
return Deferred.fromResult(null);
}
}
final class SEHShutdown implements Callback<Object, Object> {
@Override
public Object call(Object result) throws Exception {
if (result instanceof Exception) {
LOG.error("Shutdown of the HBase client failed", (Exception) result);
}
LOG.info("Shutting down storage exception handler plugin: " + storage_exception_handler.getClass().getCanonicalName());
return storage_exception_handler.shutdown().addBoth(new FinalShutdown());
}
@Override
public String toString() {
return "SEHShutdown";
}
}
final class HClientShutdown implements Callback<Deferred<Object>, ArrayList<Object>> {
public Deferred<Object> call(final ArrayList<Object> args) {
if (storage_exception_handler != null) {
return client.shutdown().addBoth(new SEHShutdown());
}
return client.shutdown().addBoth(new FinalShutdown());
}
public String toString() {
return "shutdown HBase client";
}
}
final class ShutdownErrback implements Callback<Object, Exception> {
public Object call(final Exception e) {
final Logger LOG = LoggerFactory.getLogger(ShutdownErrback.class);
if (e instanceof DeferredGroupException) {
final DeferredGroupException ge = (DeferredGroupException) e;
for (final Object r : ge.results()) {
if (r instanceof Exception) {
LOG.error("Failed to shutdown the TSD", (Exception) r);
}
}
} else {
LOG.error("Failed to shutdown the TSD", e);
}
return new HClientShutdown().call(null);
}
public String toString() {
return "shutdown HBase client after error";
}
}
final class CompactCB implements Callback<Object, ArrayList<Object>> {
public Object call(ArrayList<Object> compactions) throws Exception {
return null;
}
}
if (config.enable_compactions()) {
LOG.info("Flushing compaction queue");
deferreds.add(compactionq.flush().addCallback(new CompactCB()));
}
if (startup != null) {
LOG.info("Shutting down startup plugin: " + startup.getClass().getCanonicalName());
deferreds.add(startup.shutdown());
}
if (search != null) {
LOG.info("Shutting down search plugin: " + search.getClass().getCanonicalName());
deferreds.add(search.shutdown());
}
if (rt_publisher != null) {
LOG.info("Shutting down RT plugin: " + rt_publisher.getClass().getCanonicalName());
deferreds.add(rt_publisher.shutdown());
}
if (meta_cache != null) {
LOG.info("Shutting down meta cache plugin: " + meta_cache.getClass().getCanonicalName());
deferreds.add(meta_cache.shutdown());
}
if (storage_exception_handler != null) {
LOG.info("Shutting down storage exception handler plugin: " + storage_exception_handler.getClass().getCanonicalName());
deferreds.add(storage_exception_handler.shutdown());
}
if (ts_filter != null) {
LOG.info("Shutting down time series filter plugin: " + ts_filter.getClass().getCanonicalName());
deferreds.add(ts_filter.shutdown());
}
if (uid_filter != null) {
LOG.info("Shutting down UID filter plugin: " + uid_filter.getClass().getCanonicalName());
deferreds.add(uid_filter.shutdown());
}
// wait for plugins to shutdown before we close the client
return deferreds.size() > 0 ? Deferred.group(deferreds).addCallbackDeferring(new HClientShutdown()).addErrback(new ShutdownErrback()) : new HClientShutdown().call(null);
}
use of org.jboss.netty.util.Timeout in project pinpoint by naver.
the class PinpointServerAcceptor method sendPing.
private void sendPing() {
logger.debug("sendPing");
final TimerTask pintTask = new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (timeout.isCancelled()) {
newPingTimeout(this);
return;
}
final ChannelGroupFuture write = channelGroup.write(PingPacket.PING_PACKET);
if (logger.isWarnEnabled()) {
write.addListener(new ChannelGroupFutureListener() {
private final ChannelFutureListener listener = new WriteFailFutureListener(logger, "ping write fail", "ping write success");
@Override
public void operationComplete(ChannelGroupFuture future) throws Exception {
if (logger.isWarnEnabled()) {
for (ChannelFuture channelFuture : future) {
channelFuture.addListener(listener);
}
}
}
});
}
newPingTimeout(this);
}
};
newPingTimeout(pintTask);
}
use of org.jboss.netty.util.Timeout in project pinpoint by naver.
the class DefaultFuture method cancelTimeout.
private void cancelTimeout() {
final Timeout timeout = this.timeout;
if (timeout != null) {
timeout.cancel();
this.timeout = null;
}
}
use of org.jboss.netty.util.Timeout in project pinpoint by naver.
the class RequestManager method addTimeoutTask.
private void addTimeoutTask(long timeoutMillis, DefaultFuture future) {
if (future == null) {
throw new NullPointerException("future");
}
try {
Timeout timeout = timer.newTimeout(future, timeoutMillis, TimeUnit.MILLISECONDS);
future.setTimeout(timeout);
} catch (IllegalStateException e) {
// this case is that timer has been shutdown. That maybe just means that socket has been closed.
future.setFailure(new PinpointSocketException("socket closed"));
}
}
use of org.jboss.netty.util.Timeout in project pinpoint by naver.
the class ZookeeperClient method reconnectWhenSessionExpired.
public void reconnectWhenSessionExpired() {
if (!stateContext.isStarted()) {
logger.warn("ZookeeperClient.reconnectWhenSessionExpired() failed. Error: Already closed.");
return;
}
ZooKeeper zookeeper = this.zookeeper;
if (zookeeper.getState().isConnected()) {
logger.warn("ZookeeperClient.reconnectWhenSessionExpired() failed. Error: session(0x{}) is connected.", Long.toHexString(zookeeper.getSessionId()));
return;
}
logger.warn("Execute ZookeeperClient.reconnectWhenSessionExpired()(Expired session:0x{}).", Long.toHexString(zookeeper.getSessionId()));
try {
zookeeper.close();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
ZooKeeper newZookeeper = createNewZookeeper();
if (newZookeeper == null) {
logger.warn("Failed to create new Zookeeper instance. It will be retry AFTER {}ms.", reconnectDelayWhenSessionExpired);
timer.newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (timeout.isCancelled()) {
return;
}
reconnectWhenSessionExpired();
}
}, reconnectDelayWhenSessionExpired, TimeUnit.MILLISECONDS);
} else {
this.zookeeper = newZookeeper;
}
}
Aggregations