Package org.elasticsearch.common.io.stream

Examples of org.elasticsearch.common.io.stream.HandlesStreamOutput


@Test
public class HandlesStreamsTests {

    @Test public void testSharedUTFHandles() throws Exception {
        BytesStreamOutput bytesOut = new BytesStreamOutput();
        HandlesStreamOutput out = new HandlesStreamOutput(bytesOut, 5);
        String lowerThresholdValue = "test";
        String higherThresholdValue = "something that is higher than 5";
        out.writeUTF(lowerThresholdValue);
        out.writeUTF(higherThresholdValue);
        out.writeInt(1);
        out.writeUTF("else");
        out.writeUTF(higherThresholdValue);
        out.writeUTF(lowerThresholdValue);

        HandlesStreamInput in = new HandlesStreamInput(new BytesStreamInput(bytesOut.copiedByteArray()));
        assertThat(in.readUTF(), equalTo(lowerThresholdValue));
        assertThat(in.readUTF(), equalTo(higherThresholdValue));
        assertThat(in.readInt(), equalTo(1));
View Full Code Here


    private void sendPingRequest(int id, boolean remove) {
        synchronized (sendMutex) {
            CachedStreamOutput.Entry cachedEntry = CachedStreamOutput.popEntry();
            try {
                HandlesStreamOutput out = cachedEntry.cachedHandlesBytes();
                out.writeInt(id);
                clusterName.writeTo(out);
                nodesProvider.nodes().localNode().writeTo(out);
                datagramPacketSend.setData(cachedEntry.bytes().copiedByteArray());
            } catch (IOException e) {
                if (remove) {
View Full Code Here

        byte status = 0;
        status = TransportStreams.statusSetRequest(status);

        if (options.compress()) {
            status = TransportStreams.statusSetCompress(status);
            HandlesStreamOutput stream = cachedEntry.cachedHandlesLzfBytes();
            cachedEntry.bytes().write(HEADER_PLACEHOLDER);
            stream.writeUTF(action);
            message.writeTo(stream);
            stream.flush();
        } else {
            HandlesStreamOutput stream = cachedEntry.cachedHandlesBytes();
            cachedEntry.bytes().write(HEADER_PLACEHOLDER);
            stream.writeUTF(action);
            message.writeTo(stream);
            stream.flush();
        }
        TransportStreams.writeHeader(cachedEntry.bytes().unsafeByteArray(), cachedEntry.bytes().size(), requestId, status);
    }
View Full Code Here

        byte status = 0;
        status = TransportStreams.statusSetResponse(status);

        if (options.compress()) {
            status = TransportStreams.statusSetCompress(status);
            HandlesStreamOutput stream = cachedEntry.cachedHandlesLzfBytes();
            cachedEntry.bytes().write(HEADER_PLACEHOLDER);
            message.writeTo(stream);
            stream.flush();
        } else {
            HandlesStreamOutput stream = cachedEntry.cachedHandlesBytes();
            cachedEntry.bytes().write(HEADER_PLACEHOLDER);
            message.writeTo(stream);
            stream.flush();
        }
        TransportStreams.writeHeader(cachedEntry.bytes().unsafeByteArray(), cachedEntry.bytes().size(), requestId, status);
    }
View Full Code Here

    }

    @Override public void sendResponse(Streamable message, TransportResponseOptions options) throws IOException {
        CachedStreamOutput.Entry cachedEntry = CachedStreamOutput.popEntry();
        try {
            HandlesStreamOutput stream = cachedEntry.cachedHandlesBytes();
            stream.writeLong(requestId);
            byte status = 0;
            status = TransportStreams.statusSetResponse(status);
            stream.writeByte(status); // 0 for request, 1 for response.
            message.writeTo(stream);
            final byte[] data = cachedEntry.bytes().copiedByteArray();
            targetTransport.threadPool().cached().execute(new Runnable() {
                @Override public void run() {
                    targetTransport.messageReceived(data, action, sourceTransport, null);
View Full Code Here

    }

    @Override public <T extends Streamable> void sendRequest(final DiscoveryNode node, final long requestId, final String action, final Streamable message, TransportRequestOptions options) throws IOException, TransportException {
        CachedStreamOutput.Entry cachedEntry = CachedStreamOutput.popEntry();
        try {
            HandlesStreamOutput stream = cachedEntry.cachedHandlesBytes();

            stream.writeLong(requestId);
            byte status = 0;
            status = TransportStreams.statusSetRequest(status);
            stream.writeByte(status); // 0 for request, 1 for response.

            stream.writeUTF(action);
            message.writeTo(stream);

            final LocalTransport targetTransport = connectedNodes.get(node);
            if (targetTransport == null) {
                throw new NodeNotConnectedException(node, "Node not connected");
            }

            final byte[] data = ((BytesStreamOutput) stream.wrappedOut()).copiedByteArray();

            threadPool.cached().execute(new Runnable() {
                @Override public void run() {
                    targetTransport.messageReceived(data, action, LocalTransport.this, requestId);
                }
View Full Code Here

        status = TransportStatus.setRequest(status);

        BytesStreamOutput bStream = new BytesStreamOutput();
        bStream.skip(NettyHeader.HEADER_SIZE);
        StreamOutput stream = bStream;
        stream = new HandlesStreamOutput(stream);

        // we pick the smallest of the 2, to support both backward and forward compatibility
        // note, this is the only place we need to do this, since from here on, we use the serialized version
        // as the version to use also when the node receiving this request will send the response with
        Version version = Version.smallest(this.version, node.version());
View Full Code Here

*/
public class CachedStreamOutput {

    private static Entry newEntry() {
        BytesStreamOutput bytes = new BytesStreamOutput();
        HandlesStreamOutput handles = new HandlesStreamOutput(bytes);
        return new Entry(bytes, handles);
    }
View Full Code Here

            StreamOutput stream = bStream;
            if (options.compress()) {
                status = TransportStatus.setCompress(status);
                stream = CompressorFactory.defaultCompressor().streamOutput(stream);
            }
            stream = new HandlesStreamOutput(stream);
            stream.setVersion(version);
            response.writeTo(stream);
            stream.close();

            ReleasableBytesReference bytes = bStream.ourBytes();
View Full Code Here

        String test4 = "test4";
        String test5 = "test5";
        String test6 = "test6";

        BytesStreamOutput bout = new BytesStreamOutput();
        HandlesStreamOutput out = new HandlesStreamOutput(bout);
        out.writeString(test1);
        out.writeString(test1);
        out.writeString(test2);
        out.writeString(test3);
        out.writeSharedString(test4);
        out.writeSharedString(test4);
        out.writeSharedString(test5);
        out.writeSharedString(test6);

        BytesStreamInput bin = new BytesStreamInput(bout.bytes());
        HandlesStreamInput in = new HandlesStreamInput(bin);
        String s1 = in.readString();
        String s2 = in.readString();
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.io.stream.HandlesStreamOutput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.