org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput Java Examples

The following examples show how to use org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockTransport.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * simulate a response for the given requestId
 */
@SuppressWarnings("unchecked")
public <Response extends TransportResponse> void handleResponse(final long requestId, final Response response) {
    final TransportResponseHandler<Response> transportResponseHandler =
        (TransportResponseHandler<Response>) responseHandlers.onResponseReceived(requestId, listener);
    if (transportResponseHandler != null) {
        final Response deliveredResponse;
        try (BytesStreamOutput output = new BytesStreamOutput()) {
            response.writeTo(output);
            deliveredResponse = transportResponseHandler.read(
                new NamedWriteableAwareStreamInput(output.bytes().streamInput(), writeableRegistry()));
        } catch (IOException | UnsupportedOperationException e) {
            throw new AssertionError("failed to serialize/deserialize response " + response, e);
        }
        transportResponseHandler.handleResponse(deliveredResponse);
    }
}
 
Example #2
Source File: ESTestCase.java    From crate with Apache License 2.0 5 votes vote down vote up
protected static <T> T copyInstance(T original, NamedWriteableRegistry namedWriteableRegistry, Writeable.Writer<T> writer,
                                  Writeable.Reader<T> reader, Version version) throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        output.setVersion(version);
        writer.write(output, original);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            in.setVersion(version);
            return reader.read(in);
        }
    }
}
 
Example #3
Source File: DiffableTestUtils.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Simulates sending diffs over the wire
 */
public static <T extends Writeable> T copyInstance(T diffs, NamedWriteableRegistry namedWriteableRegistry,
                                                              Reader<T> reader) throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        diffs.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            return reader.read(in);
        }
    }
}
 
Example #4
Source File: ClusterState.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * @param data      input bytes
 * @param localNode used to set the local node in the cluster state.
 */
public static ClusterState fromBytes(byte[] data, DiscoveryNode localNode, NamedWriteableRegistry registry) throws IOException {
    StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(data), registry);
    return readFrom(in, localNode);

}