Search in sources :

Example 11 with MultiCallback

use of com.linkedin.common.callback.MultiCallback in project rest.li by linkedin.

the class AbstractNettyClient method shutdown.

@Override
public final void shutdown(final Callback<None> callback) {
    LOG.info("Shutdown requested");
    if (_state.compareAndSet(NettyClientState.RUNNING, NettyClientState.SHUTTING_DOWN)) {
        LOG.info("Shutting down");
        MultiCallback poolShutdown = new MultiCallback(new Callback<None>() {

            private void releaseCallbacks() {
                _userCallbacks.forEach(transportCallback -> transportCallback.onResponse(TransportResponseImpl.error(new TimeoutException("Operation did not complete before shutdown"))));
            }

            @Override
            public void onError(Throwable e) {
                releaseCallbacks();
                callback.onError(e);
            }

            @Override
            public void onSuccess(None result) {
                releaseCallbacks();
                callback.onSuccess(result);
            }
        }, 2);
        _channelPoolManager.shutdown(poolShutdown, () -> _state.set(NettyClientState.REQUESTS_STOPPING), () -> _state.set(NettyClientState.SHUTDOWN), _shutdownTimeout);
        _sslChannelPoolManager.shutdown(poolShutdown, () -> _state.set(NettyClientState.REQUESTS_STOPPING), () -> _state.set(NettyClientState.SHUTDOWN), _shutdownTimeout);
        _jmxManager.onProviderShutdown(_channelPoolManager);
        _jmxManager.onProviderShutdown(_sslChannelPoolManager);
        TimingKey.unregisterKey(TIMING_KEY);
    } else {
        callback.onError(new IllegalStateException("Shutdown has already been requested."));
    }
}
Also used : PoolStats(com.linkedin.r2.transport.http.client.PoolStats) SocketAddress(java.net.SocketAddress) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) LoggerFactory(org.slf4j.LoggerFactory) TimeoutTransportCallback(com.linkedin.r2.transport.http.client.TimeoutTransportCallback) TimeoutException(java.util.concurrent.TimeoutException) Callback(com.linkedin.common.callback.Callback) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) NettyClientState(com.linkedin.r2.netty.common.NettyClientState) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) TransportCallback(com.linkedin.r2.transport.common.bridge.common.TransportCallback) RestResponse(com.linkedin.r2.message.rest.RestResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpBridge(com.linkedin.r2.transport.http.common.HttpBridge) GlobalEventExecutor(io.netty.util.concurrent.GlobalEventExecutor) Request(com.linkedin.r2.message.Request) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HttpNettyClient(com.linkedin.r2.netty.client.HttpNettyClient) MessageType(com.linkedin.r2.transport.common.MessageType) RestRequest(com.linkedin.r2.message.rest.RestRequest) Logger(org.slf4j.Logger) Response(com.linkedin.r2.message.Response) AsyncPoolStats(com.linkedin.r2.transport.http.client.AsyncPoolStats) TimingNameConstants(com.linkedin.r2.message.timing.TimingNameConstants) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TimingKey(com.linkedin.r2.message.timing.TimingKey) MultiCallback(com.linkedin.common.callback.MultiCallback) UnknownHostException(java.net.UnknownHostException) InvokedOnceTransportCallback(com.linkedin.r2.transport.http.client.InvokedOnceTransportCallback) AbstractJmxManager(com.linkedin.r2.transport.http.client.AbstractJmxManager) TimeUnit(java.util.concurrent.TimeUnit) TransportResponseImpl(com.linkedin.r2.transport.common.bridge.common.TransportResponseImpl) RequestContext(com.linkedin.r2.message.RequestContext) None(com.linkedin.common.util.None) UnknownSchemeException(com.linkedin.r2.netty.common.UnknownSchemeException) TimingContextUtil(com.linkedin.r2.message.timing.TimingContextUtil) TimingImportance(com.linkedin.r2.message.timing.TimingImportance) MultiCallback(com.linkedin.common.callback.MultiCallback) None(com.linkedin.common.util.None) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

MultiCallback (com.linkedin.common.callback.MultiCallback)11 None (com.linkedin.common.util.None)7 FutureCallback (com.linkedin.common.callback.FutureCallback)4 ExecutorService (java.util.concurrent.ExecutorService)4 Test (org.testng.annotations.Test)4 Callback (com.linkedin.common.callback.Callback)2 Request (com.linkedin.r2.message.Request)2 RequestContext (com.linkedin.r2.message.RequestContext)2 RestRequest (com.linkedin.r2.message.rest.RestRequest)2 RestResponse (com.linkedin.r2.message.rest.RestResponse)2 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)2 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)2 TimingContextUtil (com.linkedin.r2.message.timing.TimingContextUtil)2 TimingImportance (com.linkedin.r2.message.timing.TimingImportance)2 TimingKey (com.linkedin.r2.message.timing.TimingKey)2 NettyClientState (com.linkedin.r2.netty.common.NettyClientState)2 UnknownSchemeException (com.linkedin.r2.netty.common.UnknownSchemeException)2 MessageType (com.linkedin.r2.transport.common.MessageType)2 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)2 TransportCallback (com.linkedin.r2.transport.common.bridge.common.TransportCallback)2