public synchronized void stop() { if (transport == null) { return; } transport.stop(); transport = null; }
@Override protected void doStop() throws ElasticsearchException { final boolean setStopped = started.compareAndSet(true, false); assert setStopped : "service has already been stopped"; try { transport.stop(); } finally { // in case the transport is not connected to our local node (thus cleaned on node disconnect) // make sure to clean any leftover on going handles for (Map.Entry<Long, RequestHolder> entry : clientHandlers.entrySet()) { final RequestHolder holderToNotify = clientHandlers.remove(entry.getKey()); if (holderToNotify != null) { // callback that an exception happened, but on a different thread since we don't // want handlers to worry about stack overflows threadPool .generic() .execute( new Runnable() { @Override public void run() { holderToNotify .handler() .handleException( new TransportException( "transport stopped, action: " + holderToNotify.action())); } }); } } } }