private void handleException(final TransportResponseHandler handler, Throwable error) { if (!(error instanceof RemoteTransportException)) { error = new RemoteTransportException(error.getMessage(), error); } final RemoteTransportException rtx = (RemoteTransportException) error; if (handler.executor() == ThreadPool.Names.SAME) { try { handler.handleException(rtx); } catch (Throwable e) { logger.error("failed to handle exception response [{}]", e, handler); } } else { threadPool .executor(handler.executor()) .execute( new Runnable() { @Override public void run() { try { handler.handleException(rtx); } catch (Throwable e) { logger.error("failed to handle exception response [{}]", e, handler); } } }); } }
protected void handleResponse( Channel channel, StreamInput buffer, final TransportResponseHandler handler) { final TransportResponse response = handler.newInstance(); response.remoteAddress( new InetSocketTransportAddress((InetSocketAddress) channel.getRemoteAddress())); response.remoteAddress(); try { response.readFrom(buffer); } catch (Throwable e) { handleException( handler, new TransportSerializationException( "Failed to deserialize response of type [" + response.getClass().getName() + "]", e)); return; } try { if (handler.executor() == ThreadPool.Names.SAME) { //noinspection unchecked handler.handleResponse(response); } else { threadPool.executor(handler.executor()).execute(new ResponseHandler(handler, response)); } } catch (Throwable e) { handleException(handler, new ResponseHandlerFailureTransportException(e)); } }