static <T extends Streamable> Writeable.Reader<T> newWriteableReader(Supplier<T> supplier) { return (StreamInput in) -> { T request = supplier.get(); request.readFrom(in); return request; }; } }
/** * Writes a list of {@link Streamable} objects */ public void writeStreamableList(List<? extends Streamable> list) throws IOException { writeVInt(list.size()); for (Streamable obj: list) { obj.writeTo(this); } }
/** * Registers a new request handler * * @param action The action the request handler is associated with * @param requestFactory a callable to be used construct new instances for streaming * @param executor The executor the request handling will be executed on * @param handler The handler itself that implements the request handling */ public <Request extends TransportRequest> void registerRequestHandler(String action, Supplier<Request> requestFactory, String executor, TransportRequestHandler<Request> handler) { validateActionName(action); handler = interceptor.interceptHandler(action, executor, false, handler); RequestHandlerRegistry<Request> reg = new RequestHandlerRegistry<>( action, Streamable.newWriteableReader(requestFactory), taskManager, handler, executor, false, true); transport.registerRequestHandler(reg); }
/** * Round trip {@code instance} through binary serialization, setting the wire compatibility version to {@code version}. */ private T copyInstance(T instance, Version version) throws IOException { try (BytesStreamOutput output = new BytesStreamOutput()) { output.setVersion(version); instance.writeTo(output); try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), getNamedWriteableRegistry())) { in.setVersion(version); T newInstance = createBlankInstance(); newInstance.readFrom(in); return newInstance; } } }
/** * Serializes a potential null value. */ @Nullable public <T extends Streamable> T readOptionalStreamable(Supplier<T> supplier) throws IOException { if (readBoolean()) { T streamable = supplier.get(); streamable.readFrom(this); return streamable; } else { return null; } }
/** * Serializes a potential null value. */ public void writeOptionalStreamable(@Nullable Streamable streamable) throws IOException { if (streamable != null) { writeBoolean(true); streamable.writeTo(this); } else { writeBoolean(false); } }
/** * Registers a new request handler * * @param action The action the request handler is associated with * @param request The request class that will be used to construct new instances for streaming * @param executor The executor the request handling will be executed on * @param forceExecution Force execution on the executor queue and never reject it * @param canTripCircuitBreaker Check the request size and raise an exception in case the limit is breached. * @param handler The handler itself that implements the request handling */ public <Request extends TransportRequest> void registerRequestHandler(String action, Supplier<Request> request, String executor, boolean forceExecution, boolean canTripCircuitBreaker, TransportRequestHandler<Request> handler) { validateActionName(action); handler = interceptor.interceptHandler(action, executor, forceExecution, handler); RequestHandlerRegistry<Request> reg = new RequestHandlerRegistry<>( action, Streamable.newWriteableReader(request), taskManager, handler, executor, forceExecution, canTripCircuitBreaker); transport.registerRequestHandler(reg); }
/** * Read a {@link List} of {@link Streamable} objects, using the {@code constructor} to instantiate each instance. * <p> * This is expected to take the form: * <code> * List<MyStreamableClass> list = in.readStreamList(MyStreamableClass::new); * </code> * * @param constructor Streamable instance creator * @return Never {@code null}. * @throws IOException if any step fails */ public <T extends Streamable> List<T> readStreamableList(Supplier<T> constructor) throws IOException { int count = readArraySize(); List<T> builder = new ArrayList<>(count); for (int i=0; i<count; i++) { T instance = constructor.get(); instance.readFrom(this); builder.add(instance); } return builder; }
/** * Writes a list of {@link Streamable} objects */ public void writeStreamableList(List<? extends Streamable> list) throws IOException { writeVInt(list.size()); for (Streamable obj: list) { obj.writeTo(this); } }
/** * Registers a new request handler * * @param action The action the request handler is associated with * @param requestFactory a callable to be used construct new instances for streaming * @param executor The executor the request handling will be executed on * @param handler The handler itself that implements the request handling */ public <Request extends TransportRequest> void registerRequestHandler(String action, Supplier<Request> requestFactory, String executor, TransportRequestHandler<Request> handler) { validateActionName(action); handler = interceptor.interceptHandler(action, executor, false, handler); RequestHandlerRegistry<Request> reg = new RequestHandlerRegistry<>( action, Streamable.newWriteableReader(requestFactory), taskManager, handler, executor, false, true); transport.registerRequestHandler(reg); }
static <T extends Streamable> Writeable.Reader<T> newWriteableReader(Supplier<T> supplier) { return (StreamInput in) -> { T request = supplier.get(); request.readFrom(in); return request; }; } }
/** * Writes a list of {@link Writeable} objects */ public void writeList(List<? extends Writeable> list) throws IOException { writeVInt(list.size()); for (Writeable obj: list) { obj.writeTo(this); } }
/** * Registers a new request handler * * @param action The action the request handler is associated with * @param request The request class that will be used to construct new instances for streaming * @param executor The executor the request handling will be executed on * @param forceExecution Force execution on the executor queue and never reject it * @param canTripCircuitBreaker Check the request size and raise an exception in case the limit is breached. * @param handler The handler itself that implements the request handling */ public <Request extends TransportRequest> void registerRequestHandler(String action, Supplier<Request> request, String executor, boolean forceExecution, boolean canTripCircuitBreaker, TransportRequestHandler<Request> handler) { validateActionName(action); handler = interceptor.interceptHandler(action, executor, forceExecution, handler); RequestHandlerRegistry<Request> reg = new RequestHandlerRegistry<>( action, Streamable.newWriteableReader(request), taskManager, handler, executor, forceExecution, canTripCircuitBreaker); transport.registerRequestHandler(reg); }
static <T extends Streamable> Writeable.Reader<T> newWriteableReader(Supplier<T> supplier) { return (StreamInput in) -> { T request = supplier.get(); request.readFrom(in); return request; }; } }
/** * Writes a list of {@link Streamable} objects */ public void writeStreamableList(List<? extends Streamable> list) throws IOException { writeVInt(list.size()); for (Streamable obj: list) { obj.writeTo(this); } }
/** * Serializes a potential null value. */ public <T extends Streamable> T readOptionalStreamable(T streamable) throws IOException { if (readBoolean()) { streamable.readFrom(this); return streamable; } else { return null; } }
/** * Serializes a potential null value. */ public void writeOptionalStreamable(@Nullable Streamable streamable) throws IOException { if (streamable != null) { writeBoolean(true); streamable.writeTo(this); } else { writeBoolean(false); } }
/** * Read a {@link List} of {@link Streamable} objects, using the {@code constructor} to instantiate each instance. * <p> * This is expected to take the form: * <code> * List<MyStreamableClass> list = in.readStreamList(MyStreamableClass::new); * </code> * * @param constructor Streamable instance creator * @return Never {@code null}. * @throws IOException if any step fails */ public <T extends Streamable> List<T> readStreamableList(Supplier<T> constructor) throws IOException { int count = readArraySize(); List<T> builder = new ArrayList<>(count); for (int i=0; i<count; i++) { T instance = constructor.get(); instance.readFrom(this); builder.add(instance); } return builder; }
/** * Serializes a potential null value. */ public void writeOptionalStreamable(@Nullable Streamable streamable) throws IOException { if (streamable != null) { writeBoolean(true); streamable.writeTo(this); } else { writeBoolean(false); } }
/** * Read a {@link List} of {@link Streamable} objects, using the {@code constructor} to instantiate each instance. * <p> * This is expected to take the form: * <code> * List<MyStreamableClass> list = in.readStreamList(MyStreamableClass::new); * </code> * * @param constructor Streamable instance creator * @return Never {@code null}. * @throws IOException if any step fails */ public <T extends Streamable> List<T> readStreamableList(Supplier<T> constructor) throws IOException { int count = readArraySize(); List<T> builder = new ArrayList<>(count); for (int i=0; i<count; i++) { T instance = constructor.get(); instance.readFrom(this); builder.add(instance); } return builder; }