public static <T> PlainActionFuture<T> newFuture() { return new PlainActionFuture<>(); }
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; }
/** * 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); } }
protected QueryBuilder rewriteAndFetch(QueryBuilder builder, QueryRewriteContext context) throws IOException { PlainActionFuture<QueryBuilder> future = new PlainActionFuture<>(); Rewriteable.rewriteAndFetch(builder, context, future); return future.actionGet(); } }
public final ActionFuture<Response> execute(Request request) { PlainActionFuture<Response> future = newFuture(); execute(request, future); return future; }
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(); } } }
/** * 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"); } }
@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); } } }
@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; }
protected PlainActionFuture<Response> listener() { return new PlainActionFuture<>(); } }
@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); }
@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 } } }
/** * 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; }
public static <T> PlainActionFuture<T> newFuture() { return new PlainActionFuture<>(); }
} 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) {
@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); }
/** * 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); } }
public static <T> PlainActionFuture<T> newFuture() { return new PlainActionFuture<>(); }
/** * 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); } }
@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); }