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

The following examples show how to use org.elasticsearch.common.io.stream.Writeable. 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: TransportShardAction.java    From crate with Apache License 2.0 6 votes vote down vote up
protected TransportShardAction(String actionName,
                               TransportService transportService,
                               IndexNameExpressionResolver indexNameExpressionResolver,
                               ClusterService clusterService,
                               IndicesService indicesService,
                               ThreadPool threadPool,
                               ShardStateAction shardStateAction,
                               Writeable.Reader<Request> reader,
                               SchemaUpdateClient schemaUpdateClient) {
    super(
        actionName,
        transportService,
        clusterService,
        indicesService,
        threadPool,
        shardStateAction,
        indexNameExpressionResolver,
        reader,
        reader,
        ThreadPool.Names.WRITE
    );
    this.mappingUpdate = (update, shardId, type) -> {
        validateMapping(update.root().iterator(), false);
        schemaUpdateClient.blockingUpdateOnMaster(shardId.getIndex(), update);
    };
}
 
Example #2
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 6 votes vote down vote up
protected void registerRequestHandlers(String actionName,
                                       TransportService transportService,
                                       Writeable.Reader<Request> reader,
                                       Writeable.Reader<ReplicaRequest> replicaRequestReader,
                                       String executor) {
    transportService.registerRequestHandler(actionName, reader, ThreadPool.Names.SAME, new OperationTransportHandler());
    transportService.registerRequestHandler(
        transportPrimaryAction, in -> new ConcreteShardRequest<>(in, reader), executor, new PrimaryOperationTransportHandler());
    // we must never reject on because of thread pool capacity on replicas
    transportService.registerRequestHandler(
        transportReplicaAction,
        in -> new ConcreteReplicaRequest<>(in, replicaRequestReader),
        executor,
        true,
        true,
        new ReplicaOperationTransportHandler());
}
 
Example #3
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 6 votes vote down vote up
protected TransportReplicationAction(String actionName,
                                     TransportService transportService,
                                     ClusterService clusterService,
                                     IndicesService indicesService,
                                     ThreadPool threadPool,
                                     ShardStateAction shardStateAction,
                                     IndexNameExpressionResolver indexNameExpressionResolver,
                                     Writeable.Reader<Request> reader,
                                     Writeable.Reader<ReplicaRequest> replicaReader,
                                     String executor,
                                     boolean syncGlobalCheckpointAfterOperation) {
    super(actionName, threadPool, indexNameExpressionResolver, transportService.getTaskManager());
    this.transportService = transportService;
    this.clusterService = clusterService;
    this.indicesService = indicesService;
    this.shardStateAction = shardStateAction;
    this.executor = executor;

    this.transportPrimaryAction = actionName + "[p]";
    this.transportReplicaAction = actionName + "[r]";
    registerRequestHandlers(actionName, transportService, reader, replicaReader, executor);

    this.transportOptions = transportOptions();

    this.syncGlobalCheckpointAfterOperation = syncGlobalCheckpointAfterOperation;
}
 
Example #4
Source File: TransportNodesAction.java    From crate with Apache License 2.0 6 votes vote down vote up
protected TransportNodesAction(String actionName,
                               ThreadPool threadPool,
                               ClusterService clusterService,
                               TransportService transportService,
                               IndexNameExpressionResolver indexNameExpressionResolver,
                               Writeable.Reader<NodesRequest> nodesRequestReader,
                               Writeable.Reader<NodeRequest> nodeRequestReader,
                               String nodeExecutor,
                               Class<NodeResponse> nodeResponseClass) {
    super(actionName, threadPool, transportService, nodesRequestReader, indexNameExpressionResolver);
    this.clusterService = Objects.requireNonNull(clusterService);
    this.transportService = Objects.requireNonNull(transportService);
    this.nodeResponseClass = Objects.requireNonNull(nodeResponseClass);

    this.transportNodeAction = actionName + "[n]";

    transportService.registerRequestHandler(
        transportNodeAction, nodeRequestReader, nodeExecutor, new NodeTransportHandler());
}
 
Example #5
Source File: TransportWriteAction.java    From crate with Apache License 2.0 6 votes vote down vote up
protected TransportWriteAction(String actionName,
                               TransportService transportService,
                               ClusterService clusterService,
                               IndicesService indicesService,
                               ThreadPool threadPool,
                               ShardStateAction shardStateAction,
                               IndexNameExpressionResolver indexNameExpressionResolver,
                               Writeable.Reader<Request> reader,
                               Writeable.Reader<ReplicaRequest> replicaReader,
                               String executor) {
    super(
        actionName,
        transportService,
        clusterService,
        indicesService,
        threadPool,
        shardStateAction,
        indexNameExpressionResolver,
        reader,
        replicaReader,
        executor,
        true);
}
 
Example #6
Source File: TransportBroadcastByNodeAction.java    From crate with Apache License 2.0 6 votes vote down vote up
public TransportBroadcastByNodeAction(
        String actionName,
        ThreadPool threadPool,
        ClusterService clusterService,
        TransportService transportService,
        IndexNameExpressionResolver indexNameExpressionResolver,
        Writeable.Reader<Request> reader,
        String executor,
        boolean canTripCircuitBreaker) {
    super(actionName, canTripCircuitBreaker, threadPool, transportService, reader, indexNameExpressionResolver);

    this.clusterService = clusterService;
    this.transportService = transportService;

    transportNodeBroadcastAction = actionName + "[n]";

    transportService.registerRequestHandler(transportNodeBroadcastAction, NodeRequest::new, executor, false, canTripCircuitBreaker,
        new BroadcastByNodeTransportRequestHandler());
}
 
Example #7
Source File: TransportResyncReplicationAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected void registerRequestHandlers(String actionName,
                                       TransportService transportService,
                                       Writeable.Reader<ResyncReplicationRequest> reader,
                                       Writeable.Reader<ResyncReplicationRequest> replicaReader,
                                       String executor) {
    transportService.registerRequestHandler(actionName, reader, ThreadPool.Names.SAME, new OperationTransportHandler());
    // we should never reject resync because of thread pool capacity on primary
    transportService.registerRequestHandler(
        transportPrimaryAction,
        in -> new ConcreteShardRequest<>(in, reader),
        executor,
        true,
        true,
        new PrimaryOperationTransportHandler());
    transportService.registerRequestHandler(
        transportReplicaAction,
        in -> new ConcreteReplicaRequest<>(in, replicaReader),
        executor,
        true,
        true,
        new ReplicaOperationTransportHandler());
}
 
Example #8
Source File: HandledTransportAction.java    From crate with Apache License 2.0 6 votes vote down vote up
protected HandledTransportAction(String actionName,
                                 boolean canTripCircuitBreaker,
                                 ThreadPool threadPool,
                                 TransportService transportService,
                                 Writeable.Reader<Request> requestReader,
                                 IndexNameExpressionResolver indexNameExpressionResolver) {
    super(actionName, threadPool, indexNameExpressionResolver, transportService.getTaskManager());
    transportService.registerRequestHandler(
        actionName,
        ThreadPool.Names.SAME,
        false,
        canTripCircuitBreaker,
        requestReader,
        new TransportHandler()
    );
}
 
Example #9
Source File: TransportKillNodeAction.java    From crate with Apache License 2.0 6 votes vote down vote up
TransportKillNodeAction(String name,
                        TasksService tasksService,
                        ClusterService clusterService,
                        TransportService transportService,
                        Writeable.Reader<Request> reader) {
    this.tasksService = tasksService;
    this.clusterService = clusterService;
    this.transportService = transportService;
    this.reader = reader;
    this.name = name;
    transportService.registerRequestHandler(
        name,
        reader,
        ThreadPool.Names.GENERIC,
        new NodeActionRequestHandler<>(this));
}
 
Example #10
Source File: TransportMasterNodeAction.java    From crate with Apache License 2.0 5 votes vote down vote up
protected TransportMasterNodeAction(String actionName,
                                    boolean canTripCircuitBreaker,
                                    TransportService transportService,
                                    ClusterService clusterService,
                                    ThreadPool threadPool,
                                    Writeable.Reader<Request> request,
                                    IndexNameExpressionResolver indexNameExpressionResolver) {
    super(actionName, canTripCircuitBreaker, threadPool, transportService, request, indexNameExpressionResolver);
    this.transportService = transportService;
    this.clusterService = clusterService;
    this.executor = executor();
}
 
Example #11
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 5 votes vote down vote up
protected TransportReplicationAction(String actionName,
                                     TransportService transportService,
                                     ClusterService clusterService,
                                     IndicesService indicesService,
                                     ThreadPool threadPool,
                                     ShardStateAction shardStateAction,
                                     IndexNameExpressionResolver indexNameExpressionResolver,
                                     Writeable.Reader<Request> reader,
                                     Writeable.Reader<ReplicaRequest> replicaReader,
                                     String executor) {
    this(actionName, transportService, clusterService, indicesService, threadPool, shardStateAction,
            indexNameExpressionResolver, reader, replicaReader, executor, false);
}
 
Example #12
Source File: HandledTransportAction.java    From crate with Apache License 2.0 5 votes vote down vote up
protected HandledTransportAction(String actionName,
                                 ThreadPool threadPool,
                                 TransportService transportService,
                                 Writeable.Reader<Request> reader,
                                 IndexNameExpressionResolver indexNameExpressionResolver) {
    this(actionName, true, threadPool, transportService, reader, indexNameExpressionResolver);
}
 
Example #13
Source File: TransportMasterNodeAction.java    From crate with Apache License 2.0 5 votes vote down vote up
protected TransportMasterNodeAction(String actionName,
                                    TransportService transportService,
                                    ClusterService clusterService,
                                    ThreadPool threadPool,
                                    Writeable.Reader<Request> request,
                                    IndexNameExpressionResolver indexNameExpressionResolver) {
    this(actionName, true, transportService, clusterService, threadPool, request, indexNameExpressionResolver);
}
 
Example #14
Source File: TransportMasterNodeReadAction.java    From crate with Apache License 2.0 5 votes vote down vote up
protected TransportMasterNodeReadAction(Settings settings,
                                        String actionName,
                                        boolean checkSizeLimit,
                                        TransportService transportService,
                                        ClusterService clusterService,
                                        ThreadPool threadPool,
                                        IndexNameExpressionResolver indexNameExpressionResolver,
                                        Writeable.Reader<Request> request) {
    super(actionName, checkSizeLimit, transportService, clusterService, threadPool, request, indexNameExpressionResolver);
    this.forceLocal = FORCE_LOCAL_SETTING.get(settings);
}
 
Example #15
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 #16
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 #17
Source File: AbstractDDLTransportAction.java    From crate with Apache License 2.0 5 votes vote down vote up
public AbstractDDLTransportAction(String actionName,
                                  TransportService transportService,
                                  ClusterService clusterService,
                                  ThreadPool threadPool,
                                  IndexNameExpressionResolver indexNameExpressionResolver,
                                  Writeable.Reader<Request> requestReader,
                                  Writeable.Reader<Response> responseReader,
                                  Function<Boolean, Response> ackedResponseFunction,
                                  String source) {
    super(actionName, transportService, clusterService, threadPool, requestReader, indexNameExpressionResolver);
    this.reader = responseReader;
    this.ackedResponseFunction = ackedResponseFunction;
    this.source = source;
}
 
Example #18
Source File: TransportBroadcastReplicationAction.java    From crate with Apache License 2.0 5 votes vote down vote up
public TransportBroadcastReplicationAction(String name,
                                           Writeable.Reader<Request> reader,
                                           ThreadPool threadPool,
                                           ClusterService clusterService,
                                           TransportService transportService,
                                           IndexNameExpressionResolver indexNameExpressionResolver,
                                           TransportReplicationAction replicatedBroadcastShardAction) {
    super(name, threadPool, transportService, reader, indexNameExpressionResolver);
    this.replicatedBroadcastShardAction = replicatedBroadcastShardAction;
    this.clusterService = clusterService;
}
 
Example #19
Source File: DiffableTestUtils.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that testInstance can be correctly.
 */
public static  <T extends Writeable> T assertSerialization(T testInstance, NamedWriteableRegistry namedWriteableRegistry,
                                                      Reader<T> reader) throws IOException {
    T deserializedInstance = copyInstance(testInstance, namedWriteableRegistry, reader);
    assertEquals(testInstance, deserializedInstance);
    assertEquals(testInstance.hashCode(), deserializedInstance.hashCode());
    assertNotSame(testInstance, deserializedInstance);
    return deserializedInstance;
}
 
Example #20
Source File: ActionListenerResponseHandler.java    From crate with Apache License 2.0 5 votes vote down vote up
public ActionListenerResponseHandler(ActionListener<? super Response> listener,
                                     Writeable.Reader<Response> reader,
                                     String executor) {
    this.listener = Objects.requireNonNull(listener);
    this.reader = Objects.requireNonNull(reader);
    this.executor = Objects.requireNonNull(executor);
}
 
Example #21
Source File: RequestHandlerRegistry.java    From crate with Apache License 2.0 5 votes vote down vote up
public RequestHandlerRegistry(String action, Writeable.Reader<Request> requestReader, TaskManager taskManager,
                              TransportRequestHandler<Request> handler, String executor, boolean forceExecution,
                              boolean canTripCircuitBreaker) {
    this.action = action;
    this.requestReader = requestReader;
    this.handler = handler;
    this.forceExecution = forceExecution;
    this.canTripCircuitBreaker = canTripCircuitBreaker;
    this.executor = executor;
    this.taskManager = taskManager;
}
 
Example #22
Source File: TransportService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Registers a new request handler
 *
 * @param action                The action the request handler is associated with
 * @param requestReader               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,
                                                                      String executor, boolean forceExecution,
                                                                      boolean canTripCircuitBreaker,
                                                                      Writeable.Reader<Request> requestReader,
                                                                      TransportRequestHandler<Request> handler) {
    validateActionName(action);
    handler = interceptor.interceptHandler(action, executor, forceExecution, handler);
    RequestHandlerRegistry<Request> reg = new RequestHandlerRegistry<>(
        action, requestReader, taskManager, handler, executor, forceExecution, canTripCircuitBreaker);
    transport.registerRequestHandler(reg);
}
 
Example #23
Source File: TransportService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Registers a new request handler
 *
 * @param action                The action the request handler is associated with
 * @param reader               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,
                                                                      Writeable.Reader<Request> reader,
                                                                      String executor,
                                                                      boolean forceExecution,
                                                                      boolean canTripCircuitBreaker,
                                                                      TransportRequestHandler<Request> handler) {
    validateActionName(action);
    handler = interceptor.interceptHandler(action, executor, forceExecution, handler);
    RequestHandlerRegistry<Request> reg = new RequestHandlerRegistry<>(
        action, reader, taskManager, handler, executor, forceExecution, canTripCircuitBreaker);
    transport.registerRequestHandler(reg);
}
 
Example #24
Source File: TransportService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Registers a new request handler
 *
 * @param action         The action the request handler is associated with
 * @param requestReader  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, String executor,
                                                                      Writeable.Reader<Request> requestReader,
                                                                      TransportRequestHandler<Request> handler) {
    validateActionName(action);
    handler = interceptor.interceptHandler(action, executor, false, handler);
    RequestHandlerRegistry<Request> reg = new RequestHandlerRegistry<>(
        action, requestReader, taskManager, handler, executor, false, true);
    transport.registerRequestHandler(reg);
}
 
Example #25
Source File: TransportService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Registers a new request handler
 *
 * @param action         The action the request handler is associated with
 * @param reader 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,
                                                                      Writeable.Reader<Request> reader,
                                                                      String executor,
                                                                      TransportRequestHandler<Request> handler) {
    validateActionName(action);
    handler = interceptor.interceptHandler(action, executor, false, handler);
    RequestHandlerRegistry<Request> reg = new RequestHandlerRegistry<>(
        action, reader, taskManager, handler, executor, false, true);
    transport.registerRequestHandler(reg);
}
 
Example #26
Source File: TransportChannelResponseHandler.java    From crate with Apache License 2.0 5 votes vote down vote up
public TransportChannelResponseHandler(Logger logger,
                                       TransportChannel channel,
                                       String extraInfoOnError,
                                       Writeable.Reader<T> reader) {
    this.logger = logger;
    this.channel = channel;
    this.extraInfoOnError = extraInfoOnError;
    this.reader = reader;
}
 
Example #27
Source File: ESTestCase.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * Same as {@link #copyWriteable(Writeable, NamedWriteableRegistry, Writeable.Reader)} but also allows to provide
 * a {@link Version} argument which will be used to write and read back the object.
 */
public static <T extends Writeable> T copyWriteable(T original, NamedWriteableRegistry namedWriteableRegistry,
                                                    Writeable.Reader<T> reader, Version version) throws IOException {
    return copyInstance(original, namedWriteableRegistry, (out, value) -> value.writeTo(out), reader, version);
}
 
Example #28
Source File: SnapshotsInProgressSerializationTests.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected Writeable.Reader<Diff<Custom>> diffReader() {
    return SnapshotsInProgress::readDiffFrom;
}
 
Example #29
Source File: SnapshotsInProgressSerializationTests.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected Writeable.Reader<Custom> instanceReader() {
    return SnapshotsInProgress::new;
}
 
Example #30
Source File: ClusteringAction.java    From elasticsearch-carrot2 with Apache License 2.0 4 votes vote down vote up
@Override
public Writeable.Reader<ClusteringActionResponse> getResponseReader() {
   return ClusteringActionResponse::new;
}