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."));
}
}
Aggregations