@Override public void sendRequest( final DiscoveryNode node, final long requestId, final String action, final TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { final Version version = Version.smallest(node.getVersion(), this.version); try (BytesStreamOutput stream = new BytesStreamOutput()) { stream.setVersion(version); stream.writeLong(requestId); byte status = 0; status = TransportStatus.setRequest(status); stream.writeByte(status); // 0 for request, 1 for response. threadPool.getThreadContext().writeTo(stream); stream.writeString(action); request.writeTo(stream); stream.close(); final LocalTransport targetTransport = connectedNodes.get(node); if (targetTransport == null) { throw new NodeNotConnectedException(node, "Node not connected"); } final byte[] data = stream.bytes().toBytes(); transportServiceAdapter.sent(data.length); transportServiceAdapter.onRequestSent(node, requestId, action, request, options); targetTransport .workers() .execute( () -> { ThreadContext threadContext = targetTransport.threadPool.getThreadContext(); try (ThreadContext.StoredContext context = threadContext.stashContext()) { targetTransport.messageReceived( data, action, LocalTransport.this, version, requestId); } }); } }
@Override public void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e) throws Exception { transportServiceAdapter.sent(e.getWrittenAmount()); super.writeComplete(ctx, e); }