/** * @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); } }
@Override public <C extends NamedWriteable> C readNamedWriteable(Class<C> categoryClass) throws IOException { String name = readString(); return readNamedWriteable(categoryClass, name); }
@Override <C> C readNamedWriteable(Class<C> categoryClass) throws IOException { String name = readString(); NamedWriteable<? extends C> namedWriteable = namedWriteableRegistry.getPrototype(categoryClass, name); return namedWriteable.readFrom(this); } }
in = compressor.streamInput(in); in = new NamedWriteableAwareStreamInput(in, namedWriteableRegistry); in.setVersion(request.version());
@Override public <C extends NamedWriteable> C readNamedWriteable(Class<C> categoryClass) throws IOException { String name = readString(); return readNamedWriteable(categoryClass, name); }
streamIn = new NamedWriteableAwareStreamInput(streamIn, namedWriteableRegistry); streamIn.setVersion(version); threadPool.getThreadContext().readHeaders(streamIn);
@Override public <C extends NamedWriteable> C readNamedWriteable(Class<C> categoryClass) throws IOException { String name = readString(); return readNamedWriteable(categoryClass, name); }
StreamInput in = new NamedWriteableAwareStreamInput(bytesReference.streamInput(), namedWriteableRegistry); result.readFromWithId(context.id(), in); result.setSearchShardTarget(context.shardTarget());
@Override public <C extends NamedWriteable> C readNamedWriteable(Class<C> categoryClass) throws IOException { String name = readString(); return readNamedWriteable(categoryClass, name); }
/** * @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); } }
/** * @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); } }
/** * @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); } }
protected void handleResponse(StreamInput buffer, LocalTransport sourceTransport, final TransportResponseHandler handler) { buffer = new NamedWriteableAwareStreamInput(buffer, namedWriteableRegistry); final TransportResponse response = handler.newInstance(); response.remoteAddress(sourceTransport.boundAddress.publishAddress()); try { response.readFrom(buffer); } catch (Throwable e) { handleException(handler, new TransportSerializationException("Failed to deserialize response of type [" + response.getClass().getName() + "]", e)); return; } handleParsedResponse(response, handler); }
protected void handleResponse(StreamInput buffer, LocalTransport sourceTransport, final TransportResponseHandler handler) { buffer = new NamedWriteableAwareStreamInput(buffer, namedWriteableRegistry); final TransportResponse response = handler.newInstance(); response.remoteAddress(sourceTransport.boundAddress.publishAddress()); try { response.readFrom(buffer); } catch (Exception e) { handleException(handler, new TransportSerializationException( "Failed to deserialize response of type [" + response.getClass().getName() + "]", e)); return; } handleParsedResponse(response, handler); }
/** * Since custom metadata can be loaded by a plugin class loader that resides in a sub-node, we need to * marshal this object into something the tribe node can work with */ private MetaData.Custom marshal(MetaData.Custom custom) { try (BytesStreamOutput bytesStreamOutput = new BytesStreamOutput()){ bytesStreamOutput.writeNamedWriteable(custom); try(StreamInput input = bytesStreamOutput.bytes().streamInput()) { StreamInput namedInput = new NamedWriteableAwareStreamInput(input, namedWriteableRegistry); MetaData.Custom marshaled = namedInput.readNamedWriteable(MetaData.Custom.class); return marshaled; } } catch (IOException ex) { throw new IllegalStateException("cannot marshal object with type " + custom.getWriteableName() + " to tribe node"); } } }
/** * 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); } } }
/** * Since custom metadata can be loaded by a plugin class loader that resides in a sub-node, we need to * marshal this object into something the tribe node can work with */ private MetaData.Custom marshal(MetaData.Custom custom) { try (BytesStreamOutput bytesStreamOutput = new BytesStreamOutput()){ bytesStreamOutput.writeNamedWriteable(custom); try(StreamInput input = bytesStreamOutput.bytes().streamInput()) { StreamInput namedInput = new NamedWriteableAwareStreamInput(input, namedWriteableRegistry); MetaData.Custom marshaled = namedInput.readNamedWriteable(MetaData.Custom.class); return marshaled; } } catch (IOException ex) { throw new IllegalStateException("cannot marshal object with type " + custom.getWriteableName() + " to tribe node"); } } }
/** * Create a copy of an original {@link Writeable} object by running it through a {@link BytesStreamOutput} and * reading it in again using a provided {@link Writeable.Reader}. The stream that is wrapped around the {@link StreamInput} * potentially need to use a {@link NamedWriteableRegistry}, so this needs to be provided too (although it can be * empty if the object that is streamed doesn't contain any {@link NamedWriteable} objects itself. */ public static <T extends Writeable> T copyWriteable(T original, NamedWriteableRegistry namedWritabelRegistry, Writeable.Reader<T> reader) throws IOException { try (BytesStreamOutput output = new BytesStreamOutput()) { original.writeTo(output); try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWritabelRegistry)) { return reader.read(in); } } }
StreamInput streamInput = new ByteBufferStreamInput(ByteBuffer.wrap(slice)); NamedWriteableRegistry namedWriteableRegistry = getNamedWriteableRegistry(); try (StreamInput in = new NamedWriteableAwareStreamInput(streamInput, namedWriteableRegistry)) { deserializedRequest.readFrom(in);
StreamInput streamInput = new ByteBufferStreamInput(ByteBuffer.wrap(slice)); NamedWriteableRegistry namedWriteableRegistry = getNamedWriteableRegistry(); try (StreamInput in = new NamedWriteableAwareStreamInput(streamInput, namedWriteableRegistry)) { deserializedRequest.readFrom(in);