TransportKeepAlive(ThreadPool threadPool, AsyncBiFunction<TcpChannel, BytesReference, Void> pingSender) { this.threadPool = threadPool; this.pingSender = pingSender; try (BytesStreamOutput out = new BytesStreamOutput()) { out.writeByte((byte) 'E'); out.writeByte((byte) 'S'); out.writeInt(PING_DATA_SIZE); pingMessage = out.bytes(); } catch (IOException e) { throw new AssertionError(e.getMessage(), e); // won't happen } this.lifecycle.moveToStarted(); }
private BytesReference writeHeader(int numFieldsWritten, boolean getTermStatistics, boolean getFieldStatistics, boolean scores) throws IOException { // now, write the information about offset of the terms in the // termVectors field BytesStreamOutput header = new BytesStreamOutput(); header.writeString(HEADER); header.writeInt(CURRENT_VERSION); header.writeBoolean(getTermStatistics); header.writeBoolean(getFieldStatistics); header.writeBoolean(scores); header.writeVInt(numFieldsWritten); for (int i = 0; i < fields.size(); i++) { header.writeString(fields.get(i)); header.writeVLong(fieldOffset.get(i).longValue()); } header.close(); return header.bytes(); }
private BytesReference writeHeader(int numFieldsWritten, boolean getTermStatistics, boolean getFieldStatistics, boolean scores) throws IOException { // now, write the information about offset of the terms in the // termVectors field BytesStreamOutput header = new BytesStreamOutput(); header.writeString(HEADER); header.writeInt(CURRENT_VERSION); header.writeBoolean(getTermStatistics); header.writeBoolean(getFieldStatistics); header.writeBoolean(scores); header.writeVInt(numFieldsWritten); for (int i = 0; i < fields.size(); i++) { header.writeString(fields.get(i)); header.writeVLong(fieldOffset.get(i).longValue()); } header.close(); return header.bytes(); }
private BytesReference writeHeader(int numFieldsWritten, boolean getTermStatistics, boolean getFieldStatistics, boolean scores) throws IOException { // now, write the information about offset of the terms in the // termVectors field BytesStreamOutput header = new BytesStreamOutput(); header.writeString(HEADER); header.writeInt(CURRENT_VERSION); header.writeBoolean(getTermStatistics); header.writeBoolean(getFieldStatistics); header.writeBoolean(scores); header.writeVInt(numFieldsWritten); for (int i = 0; i < fields.size(); i++) { header.writeString(fields.get(i)); header.writeVLong(fieldOffset.get(i).longValue()); } header.close(); return header.bytes(); }
private BytesReference writeHeader(int numFieldsWritten, boolean getTermStatistics, boolean getFieldStatistics, boolean scores) throws IOException { // now, write the information about offset of the terms in the // termVectors field BytesStreamOutput header = new BytesStreamOutput(); header.writeString(HEADER); header.writeInt(CURRENT_VERSION); header.writeBoolean(getTermStatistics); header.writeBoolean(getFieldStatistics); header.writeBoolean(scores); header.writeVInt(numFieldsWritten); for (int i = 0; i < fields.size(); i++) { header.writeString(fields.get(i)); header.writeVLong(fieldOffset.get(i).longValue()); } header.close(); return header.bytes(); }
private BytesReference writeHeader(int numFieldsWritten, boolean getTermStatistics, boolean getFieldStatistics, boolean scores) throws IOException { // now, write the information about offset of the terms in the // termVectors field BytesStreamOutput header = new BytesStreamOutput(); header.writeString(HEADER); header.writeInt(CURRENT_VERSION); header.writeBoolean(getTermStatistics); header.writeBoolean(getFieldStatistics); header.writeBoolean(scores); header.writeVInt(numFieldsWritten); for (int i = 0; i < fields.size(); i++) { header.writeString(fields.get(i)); header.writeVLong(fieldOffset.get(i).longValue()); } header.close(); return header.bytes(); }
out.writeByte((byte) 'E'); out.writeByte((byte) 'S'); out.writeInt(TcpTransport.PING_DATA_SIZE); pingMessage = out.bytes(); } catch (IOException e) {
private void readMessage(MockChannel mockChannel, StreamInput input) throws IOException { Socket socket = mockChannel.activeChannel; byte[] minimalHeader = new byte[TcpHeader.MARKER_BYTES_SIZE]; int firstByte = input.read(); if (firstByte == -1) { throw new IOException("Connection reset by peer"); } minimalHeader[0] = (byte) firstByte; minimalHeader[1] = (byte) input.read(); int msgSize = input.readInt(); if (msgSize == -1) { socket.getOutputStream().flush(); } else { BytesStreamOutput output = new BytesStreamOutput(); final byte[] buffer = new byte[msgSize]; input.readFully(buffer); output.write(minimalHeader); output.writeInt(msgSize); output.write(buffer); final BytesReference bytes = output.bytes(); if (TcpTransport.validateMessageHeader(bytes)) { InetSocketAddress remoteAddress = (InetSocketAddress) socket.getRemoteSocketAddress(); messageReceived(bytes.slice(TcpHeader.MARKER_BYTES_SIZE + TcpHeader.MESSAGE_LENGTH_SIZE, msgSize), mockChannel, mockChannel.profile, remoteAddress, msgSize); } else { // ping message - we just drop all stuff } } }