Search in sources :

Example 1 with Timeout

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);
}
Also used : Timeout(org.jboss.netty.util.Timeout) Deferred(com.stumbleupon.async.Deferred) ArrayList(java.util.ArrayList) Logger(org.slf4j.Logger) DeferredGroupException(com.stumbleupon.async.DeferredGroupException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HBaseException(org.hbase.async.HBaseException) IOException(java.io.IOException) Callback(com.stumbleupon.async.Callback) DeferredGroupException(com.stumbleupon.async.DeferredGroupException)

Example 2 with Timeout

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);
}
Also used : TimerTask(org.jboss.netty.util.TimerTask) Timeout(org.jboss.netty.util.Timeout) ChannelGroupFuture(org.jboss.netty.channel.group.ChannelGroupFuture) ChannelGroupFutureListener(org.jboss.netty.channel.group.ChannelGroupFutureListener) WriteFailFutureListener(com.navercorp.pinpoint.rpc.client.WriteFailFutureListener) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException)

Example 3 with Timeout

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;
    }
}
Also used : Timeout(org.jboss.netty.util.Timeout)

Example 4 with Timeout

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"));
    }
}
Also used : Timeout(org.jboss.netty.util.Timeout) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException)

Example 5 with Timeout

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;
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) TimerTask(org.jboss.netty.util.TimerTask) Timeout(org.jboss.netty.util.Timeout) NoNodeException(com.navercorp.pinpoint.web.cluster.zookeeper.exception.NoNodeException) TimeoutException(com.navercorp.pinpoint.web.cluster.zookeeper.exception.TimeoutException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) AuthException(com.navercorp.pinpoint.web.cluster.zookeeper.exception.AuthException) BadOperationException(com.navercorp.pinpoint.web.cluster.zookeeper.exception.BadOperationException) ConnectionException(com.navercorp.pinpoint.web.cluster.zookeeper.exception.ConnectionException) PinpointZookeeperException(com.navercorp.pinpoint.web.cluster.zookeeper.exception.PinpointZookeeperException) UnknownException(com.navercorp.pinpoint.web.cluster.zookeeper.exception.UnknownException)

Aggregations

Timeout (org.jboss.netty.util.Timeout)9 IOException (java.io.IOException)5 TimerTask (org.jboss.netty.util.TimerTask)5 PinpointSocketException (com.navercorp.pinpoint.rpc.PinpointSocketException)2 Callback (com.stumbleupon.async.Callback)2 Deferred (com.stumbleupon.async.Deferred)2 ArrayList (java.util.ArrayList)2 KeeperException (org.apache.zookeeper.KeeperException)2 ZooKeeper (org.apache.zookeeper.ZooKeeper)2 AuthException (com.navercorp.pinpoint.collector.cluster.zookeeper.exception.AuthException)1 BadOperationException (com.navercorp.pinpoint.collector.cluster.zookeeper.exception.BadOperationException)1 ConnectionException (com.navercorp.pinpoint.collector.cluster.zookeeper.exception.ConnectionException)1 NoNodeException (com.navercorp.pinpoint.collector.cluster.zookeeper.exception.NoNodeException)1 PinpointZookeeperException (com.navercorp.pinpoint.collector.cluster.zookeeper.exception.PinpointZookeeperException)1 TimeoutException (com.navercorp.pinpoint.collector.cluster.zookeeper.exception.TimeoutException)1 UnknownException (com.navercorp.pinpoint.collector.cluster.zookeeper.exception.UnknownException)1 WriteFailFutureListener (com.navercorp.pinpoint.rpc.client.WriteFailFutureListener)1 AuthException (com.navercorp.pinpoint.web.cluster.zookeeper.exception.AuthException)1 BadOperationException (com.navercorp.pinpoint.web.cluster.zookeeper.exception.BadOperationException)1 ConnectionException (com.navercorp.pinpoint.web.cluster.zookeeper.exception.ConnectionException)1