@Override public void sendResponse(Throwable error) throws IOException { BytesStreamOutput stream; try { stream = BytesStreamOutput.Cached.cached(); writeResponseExceptionHeader(stream); RemoteTransportException tx = new RemoteTransportException( transport.nodeName(), transport.wrapAddress(channel.getLocalAddress()), action, error); ThrowableObjectOutputStream too = new ThrowableObjectOutputStream(stream); too.writeObject(tx); too.close(); } catch (NotSerializableException e) { stream = BytesStreamOutput.Cached.cached(); writeResponseExceptionHeader(stream); RemoteTransportException tx = new RemoteTransportException( transport.nodeName(), transport.wrapAddress(channel.getLocalAddress()), action, new NotSerializableTransportException(error)); ThrowableObjectOutputStream too = new ThrowableObjectOutputStream(stream); too.writeObject(tx); too.close(); } ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(stream.copiedByteArray()); buffer.setInt(0, buffer.writerIndex() - 4); // update real size. channel.write(buffer); }
@Override public void sendResponse(Streamable message) throws IOException { HandlesStreamOutput stream = BytesStreamOutput.Cached.cachedHandles(); stream.writeBytes(LENGTH_PLACEHOLDER); // fake size stream.writeLong(requestId); byte status = 0; status = setResponse(status); stream.writeByte(status); // 0 for request, 1 for response. message.writeTo(stream); byte[] data = ((BytesStreamOutput) stream.wrappedOut()).copiedByteArray(); ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(data); buffer.setInt(0, buffer.writerIndex() - 4); // update real size. channel.write(buffer); }