Tabnine Logo
PlainActionFuture
Code IndexAdd Tabnine to your IDE (free)

How to use
PlainActionFuture
in
org.elasticsearch.action.support

Best Java code snippets using org.elasticsearch.action.support.PlainActionFuture (Showing top 20 results out of 315)

origin: org.elasticsearch/elasticsearch

public static <T> PlainActionFuture<T> newFuture() {
  return new PlainActionFuture<>();
}
origin: org.elasticsearch/elasticsearch

private Transport.Connection internalOpenConnection(DiscoveryNode node, ConnectionProfile connectionProfile) {
  PlainActionFuture<Transport.Connection> future = PlainActionFuture.newFuture();
  Releasable pendingConnection = transport.openConnection(node, connectionProfile, future);
  Transport.Connection connection;
  try {
    connection = future.actionGet();
  } catch (IllegalStateException e) {
    // If the future was interrupted we must cancel the pending connection to avoid channels leaking
    if (e.getCause() instanceof InterruptedException) {
      pendingConnection.close();
    }
    throw e;
  }
  try {
    connectionListener.onConnectionOpened(connection);
  } finally {
    connection.addCloseListener(ActionListener.wrap(() -> connectionListener.onConnectionClosed(connection)));
  }
  if (connection.isClosed()) {
    throw new ConnectTransportException(node, "a channel closed while connecting");
  }
  return connection;
}
origin: org.elasticsearch/elasticsearch

/**
 * Connects to all remote clusters in a blocking fashion. This should be called on node startup to establish an initial connection
 * to all configured seed nodes.
 */
void initializeRemoteClusters() {
  final TimeValue timeValue = REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings);
  final PlainActionFuture<Void> future = new PlainActionFuture<>();
  Map<String, Tuple<String, List<Tuple<String, Supplier<DiscoveryNode>>>>> seeds =
      RemoteClusterAware.buildRemoteClustersDynamicConfig(settings);
  updateRemoteClusters(seeds, future);
  try {
    future.get(timeValue.millis(), TimeUnit.MILLISECONDS);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
  } catch (TimeoutException ex) {
    logger.warn("failed to connect to remote clusters within {}", timeValue.toString());
  } catch (Exception e) {
    throw new IllegalStateException("failed to connect to remote clusters", e);
  }
}
origin: com.strapdata.elasticsearch.test/framework

  protected QueryBuilder rewriteAndFetch(QueryBuilder builder, QueryRewriteContext context) throws IOException {
    PlainActionFuture<QueryBuilder> future = new PlainActionFuture<>();
    Rewriteable.rewriteAndFetch(builder, context, future);
    return future.actionGet();
  }
}
origin: org.elasticsearch/elasticsearch

public final ActionFuture<Response> execute(Request request) {
  PlainActionFuture<Response> future = newFuture();
  execute(request, future);
  return future;
}
origin: com.strapdata.elasticsearch.test/framework

private static <S extends ESSelector> void startSelectors(Iterable<S> selectors, ThreadFactory threadFactory) {
  for (ESSelector acceptor : selectors) {
    if (acceptor.isRunning() == false) {
      threadFactory.newThread(acceptor::runLoop).start();
      acceptor.isRunningFuture().actionGet();
    }
  }
}
origin: com.strapdata.elasticsearch.test/framework

/**
 * Starts this selector. The selector will run until {@link #close()} is called.
 */
public void runLoop() {
  if (runLock.tryLock()) {
    isRunningFuture.onResponse(true);
    try {
      setThread();
      while (isOpen()) {
        singleLoop();
      }
    } finally {
      try {
        cleanupAndCloseChannels();
      } finally {
        try {
          selector.close();
        } catch (IOException e) {
          eventHandler.closeSelectorException(e);
        } finally {
          runLock.unlock();
          exitedLoop.countDown();
        }
      }
    }
  } else {
    throw new IllegalStateException("selector is already running");
  }
}
origin: com.strapdata.elasticsearch.test/framework

@Override
protected void doRun() throws Exception {
  go.await();
  for (int iter = 0; iter < 10; iter++) {
    PlainActionFuture<TestResponse> listener = new PlainActionFuture<>();
    final String info = sender + "_B_" + iter;
    serviceB.sendRequest(nodeA, "test", new TestRequest(info),
      new ActionListenerResponseHandler<>(listener, TestResponse::new));
    try {
      listener.actionGet();
    } catch (Exception e) {
      logger.trace(
        (Supplier<?>) () -> new ParameterizedMessage("caught exception while sending to node {}", nodeA), e);
    }
  }
}
origin: org.elasticsearch/elasticsearch

@Override
public final <Request extends ActionRequest, Response extends ActionResponse,
  RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> ActionFuture<Response> execute(
    Action<Request, Response, RequestBuilder> action, Request request) {
  PlainActionFuture<Response> actionFuture = PlainActionFuture.newFuture();
  execute(action, request, actionFuture);
  return actionFuture;
}
origin: com.strapdata.elasticsearch.test/framework

  protected PlainActionFuture<Response> listener() {
    return new PlainActionFuture<>();
  }
}
origin: org.elasticsearch/elasticsearch

@Override
protected WritePrimaryResult<BulkShardRequest, BulkShardResponse> shardOperationOnPrimary(BulkShardRequest request, IndexShard primary)
  throws Exception {
  ClusterStateObserver observer = new ClusterStateObserver(clusterService, request.timeout(), logger, threadPool.getThreadContext());
  CheckedRunnable<Exception> waitForMappingUpdate = () -> {
    PlainActionFuture<Void> waitingFuture = new PlainActionFuture<>();
    observer.waitForNextChange(new ClusterStateObserver.Listener() {
      @Override
      public void onNewClusterState(ClusterState state) {
        waitingFuture.onResponse(null);
      }
      @Override
      public void onClusterServiceClose() {
        waitingFuture.onFailure(new NodeClosedException(clusterService.localNode()));
      }
      @Override
      public void onTimeout(TimeValue timeout) {
        waitingFuture.onFailure(
          new MapperException("timed out while waiting for a dynamic mapping update"));
      }
    });
    waitingFuture.get();
  };
  return performOnPrimary(request, primary, updateHelper, threadPool::absoluteTimeInMillis,
    new ConcreteMappingUpdatePerformer(), waitForMappingUpdate);
}
origin: com.strapdata.elasticsearch.test/framework

@Override
protected void doRun() throws Exception {
  go.await();
  for (int iter = 0; iter < 10; iter++) {
    PlainActionFuture<TestResponse> listener = new PlainActionFuture<>();
    final String info = sender + "_" + iter;
    final DiscoveryNode node = nodeB; // capture now
    try {
      serviceA.sendRequest(node, "test", new TestRequest(info),
        new ActionListenerResponseHandler<>(listener, TestResponse::new));
      try {
        listener.actionGet();
      } catch (ConnectTransportException e) {
        // ok!
      } catch (Exception e) {
        logger.error(
          (Supplier<?>) () -> new ParameterizedMessage("caught exception while sending to node {}", node), e);
        sendingErrors.add(e);
      }
    } catch (NodeNotConnectedException ex) {
      // ok
    }
  }
}
origin: org.elasticsearch/elasticsearch

/**
 * Invokes #accept(BulkRequest, ActionListener). Backs off on the provided exception. Retries will be scheduled using
 * the class's thread pool.
 *
 * @param consumer The consumer to which apply the request and listener
 * @param bulkRequest The bulk request that should be executed.
 * @return a future representing the bulk response returned by the client.
 */
public PlainActionFuture<BulkResponse> withBackoff(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer,
                          BulkRequest bulkRequest) {
  PlainActionFuture<BulkResponse> future = PlainActionFuture.newFuture();
  withBackoff(consumer, bulkRequest, future);
  return future;
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

public static <T> PlainActionFuture<T> newFuture() {
  return new PlainActionFuture<>();
}
origin: org.elasticsearch/elasticsearch

} else {
  logger.trace("waiting for cluster state version {} (current: {})", clusterStateVersion, clusterState.getVersion());
  final PlainActionFuture<Long> future = new PlainActionFuture<>();
  observer.waitForNextChange(new ClusterStateObserver.Listener() {
    long currentVersion = future.get();
    logger.trace("successfully waited for cluster state with version {} (current: {})", clusterStateVersion, currentVersion);
  } catch (Exception e) {
origin: org.elasticsearch.plugin/percolator-client

@Override
public void parse(ParseContext context) throws IOException {
  QueryShardContext queryShardContext = this.queryShardContext.get();
  if (context.doc().getField(queryBuilderField.name()) != null) {
    // If a percolator query has been defined in an array object then multiple percolator queries
    // could be provided. In order to prevent this we fail if we try to parse more than one query
    // for the current document.
    throw new IllegalArgumentException("a document can only contain one percolator query");
  }
  XContentParser parser = context.parser();
  QueryBuilder queryBuilder = parseQueryBuilder(
      parser, parser.getTokenLocation()
  );
  verifyQuery(queryBuilder);
  // Fetching of terms, shapes and indexed scripts happen during this rewrite:
  PlainActionFuture<QueryBuilder> future = new PlainActionFuture<>();
  Rewriteable.rewriteAndFetch(queryBuilder, queryShardContext, future);
  queryBuilder = future.actionGet();
  Version indexVersion = context.mapperService().getIndexSettings().getIndexVersionCreated();
  createQueryBuilderField(indexVersion, queryBuilderField, queryBuilder, context);
  QueryBuilder queryBuilderForProcessing = queryBuilder.rewrite(new QueryShardContext(queryShardContext) {
    @Override
    public boolean convertNowRangeToMatchAll() {
      return true;
    }
  });
  Query query = toQuery(queryShardContext, isMapUnmappedFieldAsText(), queryBuilderForProcessing);
  processQuery(query, context);
}
origin: org.elasticsearch/elasticsearch

/**
 * Closes the channels.
 *
 * @param channels to close
 * @param blocking indicates if we should block on channel close
 */
static <C extends CloseableChannel> void closeChannels(List<C> channels, boolean blocking) {
  try {
    IOUtils.close(channels);
  } catch (IOException e) {
    // The CloseableChannel#close method does not throw IOException, so this should not occur.
    throw new AssertionError(e);
  }
  if (blocking) {
    ArrayList<ActionFuture<Void>> futures = new ArrayList<>(channels.size());
    for (final C channel : channels) {
      PlainActionFuture<Void> closeFuture = PlainActionFuture.newFuture();
      channel.addCloseListener(closeFuture);
      futures.add(closeFuture);
    }
    blockOnFutures(futures);
  }
}
origin: com.strapdata.elasticsearch/elasticsearch

public static <T> PlainActionFuture<T> newFuture() {
  return new PlainActionFuture<>();
}
origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Connects to all remote clusters in a blocking fashion. This should be called on node startup to establish an initial connection
 * to all configured seed nodes.
 */
void initializeRemoteClusters() {
  final TimeValue timeValue = REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings);
  final PlainActionFuture<Void> future = new PlainActionFuture<>();
  Map<String, List<DiscoveryNode>> seeds = RemoteClusterAware.buildRemoteClustersSeeds(settings);
  updateRemoteClusters(seeds, future);
  try {
    future.get(timeValue.millis(), TimeUnit.MILLISECONDS);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
  } catch (TimeoutException ex) {
    logger.warn("failed to connect to remote clusters within {}", timeValue.toString());
  } catch (Exception e) {
    throw new IllegalStateException("failed to connect to remote clusters", e);
  }
}
origin: org.codelibs.elasticsearch.module/percolator

@Override
public void parse(ParseContext context) throws IOException {
  QueryShardContext queryShardContext = this.queryShardContext.get();
  if (context.doc().getField(queryBuilderField.name()) != null) {
    // If a percolator query has been defined in an array object then multiple percolator queries
    // could be provided. In order to prevent this we fail if we try to parse more than one query
    // for the current document.
    throw new IllegalArgumentException("a document can only contain one percolator query");
  }
  XContentParser parser = context.parser();
  QueryBuilder queryBuilder = parseQueryBuilder(
      parser, parser.getTokenLocation()
  );
  verifyQuery(queryBuilder);
  // Fetching of terms, shapes and indexed scripts happen during this rewrite:
  PlainActionFuture<QueryBuilder> future = new PlainActionFuture<>();
  Rewriteable.rewriteAndFetch(queryBuilder, queryShardContext, future);
  queryBuilder = future.actionGet();
  Version indexVersion = context.mapperService().getIndexSettings().getIndexVersionCreated();
  createQueryBuilderField(indexVersion, queryBuilderField, queryBuilder, context);
  QueryBuilder queryBuilderForProcessing = queryBuilder.rewrite(new QueryShardContext(queryShardContext) {
    @Override
    public boolean convertNowRangeToMatchAll() {
      return true;
    }
  });
  Query query = toQuery(queryShardContext, isMapUnmappedFieldAsText(), queryBuilderForProcessing);
  processQuery(query, context);
}
org.elasticsearch.action.supportPlainActionFuture

Most used methods

  • <init>
  • actionGet
  • newFuture
  • get
  • onResponse

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSharedPreferences (Context)
  • compareTo (BigDecimal)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • Menu (java.awt)
  • Socket (java.net)
    Provides a client-side TCP socket.
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now