Java Code Examples for org.elasticsearch.common.util.concurrent.FutureUtils#cancel()

The following examples show how to use org.elasticsearch.common.util.concurrent.FutureUtils#cancel() . 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: HttpBulkProcessor.java    From elasticsearch-helper with Apache License 2.0 6 votes vote down vote up
/**
 * Closes the processor. If flushing by time is enabled, then it's shutdown. Any remaining bulk actions are flushed.
 *
 * If concurrent requests are not enabled, returns {@code true} immediately.
 * If concurrent requests are enabled, waits for up to the specified timeout for all bulk requests to complete then returns {@code true},
 * If the specified waiting time elapses before all bulk requests complete, {@code false} is returned.
 *
 * @param timeout The maximum time to wait for the bulk requests to complete
 * @param unit The time unit of the {@code timeout} argument
 * @return {@code true} if all bulk requests completed and {@code false} if the waiting time elapsed before all the bulk requests completed
 * @throws InterruptedException If the current thread is interrupted
 */
public synchronized boolean awaitClose(long timeout, TimeUnit unit) throws InterruptedException {
    if (closed) {
        return true;
    }
    closed = true;
    if (this.scheduledFuture != null) {
        FutureUtils.cancel(this.scheduledFuture);
        this.scheduler.shutdown();
    }
    if (bulkRequest.numberOfActions() > 0) {
        execute();
    }
    if (this.concurrentRequests < 1) {
        return true;
    }
    if (semaphore.tryAcquire(this.concurrentRequests, timeout, unit)) {
        semaphore.release(this.concurrentRequests);
        return true;
    }
    return false;
}
 
Example 2
Source File: IndexShard.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public void close(String reason, boolean flushEngine) throws IOException {
    synchronized (mutex) {
        try {
            indexSettingsService.removeListener(applyRefreshSettings);
            if (state != IndexShardState.CLOSED) {
                FutureUtils.cancel(refreshScheduledFuture);
                refreshScheduledFuture = null;
                FutureUtils.cancel(mergeScheduleFuture);
                mergeScheduleFuture = null;
            }
            changeState(IndexShardState.CLOSED, reason);
            indexShardOperationCounter.decRef();
        } finally {
            final Engine engine = this.currentEngineReference.getAndSet(null);
            try {
                if (engine != null && flushEngine && this.flushOnClose) {
                    engine.flushAndClose();
                }
            } finally { // playing safe here and close the engine even if the above succeeds - close can be called multiple times
                IOUtils.close(engine, percolatorQueriesRegistry);
            }
        }
    }
}
 
Example 3
Source File: Translog.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void close() throws IOException {
    if (closed.compareAndSet(false, true)) {
        try (ReleasableLock lock = writeLock.acquire()) {
            try {
                current.sync();
            } finally {
                try {
                    IOUtils.close(current, currentCommittingTranslog);
                } finally {
                    IOUtils.close(recoveredTranslogs);
                    recoveredTranslogs.clear();
                }
            }
        } finally {
            FutureUtils.cancel(syncScheduler);
            logger.debug("translog closed");
        }
    }
}
 
Example 4
Source File: TransportClientNodesService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public void close() {
    synchronized (mutex) {
        if (closed) {
            return;
        }
        closed = true;
        FutureUtils.cancel(nodesSamplerFuture);
        for (DiscoveryNode node : nodes) {
            transportService.disconnectFromNode(node);
        }
        for (DiscoveryNode listedNode : listedNodes) {
            transportService.disconnectFromNode(listedNode);
        }
        nodes = Collections.emptyList();
    }
}
 
Example 5
Source File: InternalClusterService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void onNodeAck(DiscoveryNode node, @Nullable Throwable t) {
    if (!ackedTaskListener.mustAck(node)) {
        //we always wait for the master ack anyway
        if (!node.equals(nodes.masterNode())) {
            return;
        }
    }
    if (t == null) {
        logger.trace("ack received from node [{}], cluster_state update (version: {})", node, clusterStateVersion);
    } else {
        this.lastFailure = t;
        logger.debug("ack received from node [{}], cluster_state update (version: {})", t, node, clusterStateVersion);
    }

    if (countDown.countDown()) {
        logger.trace("all expected nodes acknowledged cluster_state update (version: {})", clusterStateVersion);
        FutureUtils.cancel(ackTimeoutCallback);
        ackedTaskListener.onAllNodesAcked(lastFailure);
    }
}
 
Example 6
Source File: BulkProcessor.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the processor. If flushing by time is enabled, then it's shutdown. Any remaining bulk actions are flushed.
 *
 * If concurrent requests are not enabled, returns {@code true} immediately.
 * If concurrent requests are enabled, waits for up to the specified timeout for all bulk requests to complete then returns {@code true},
 * If the specified waiting time elapses before all bulk requests complete, {@code false} is returned.
 *
 * @param timeout The maximum time to wait for the bulk requests to complete
 * @param unit The time unit of the {@code timeout} argument
 * @return {@code true} if all bulk requests completed and {@code false} if the waiting time elapsed before all the bulk requests completed
 * @throws InterruptedException If the current thread is interrupted
 */
public synchronized boolean awaitClose(long timeout, TimeUnit unit) throws InterruptedException {
    if (closed) {
        return true;
    }
    closed = true;
    if (this.scheduledFuture != null) {
        FutureUtils.cancel(this.scheduledFuture);
        this.scheduler.shutdown();
    }
    if (bulkRequest.numberOfActions() > 0) {
        execute();
    }
    return this.bulkRequestHandler.awaitClose(timeout, unit);
}
 
Example 7
Source File: BulkProcessor.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the processor. If flushing by time is enabled, then it's shutdown. Any remaining bulk actions are flushed.
 *
 * If concurrent requests are not enabled, returns {@code true} immediately.
 * If concurrent requests are enabled, waits for up to the specified timeout for all bulk requests to complete then returns {@code true},
 * If the specified waiting time elapses before all bulk requests complete, {@code false} is returned.
 *
 * @param timeout The maximum time to wait for the bulk requests to complete
 * @param unit The time unit of the {@code timeout} argument
 * @return {@code true} if all bulk requests completed and {@code false} if the waiting time elapsed before all the bulk requests completed
 * @throws InterruptedException If the current thread is interrupted
 */
public synchronized boolean awaitClose(long timeout, TimeUnit unit) throws InterruptedException {
    if (closed) {
        return true;
    }
    closed = true;
    if (this.scheduledFuture != null) {
        FutureUtils.cancel(this.scheduledFuture);
        this.scheduler.shutdown();
    }
    if (bulkRequest.numberOfActions() > 0) {
        execute();
    }
    return this.bulkRequestHandler.awaitClose(timeout, unit);
}
 
Example 8
Source File: Retry.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void finishHim() {
    try {
        listener.onResponse(getAccumulatedResponse());
    } finally {
        FutureUtils.cancel(scheduledRequestFuture);
    }
}
 
Example 9
Source File: Retry.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void onFailure(Throwable e) {
    try {
        listener.onFailure(e);
    } finally {
        FutureUtils.cancel(scheduledRequestFuture);
    }
}
 
Example 10
Source File: MetaDataDeleteIndexService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void onFailure(Throwable t) {
    if (notified.compareAndSet(false, true)) {
        FutureUtils.cancel(future);
        listener.onFailure(t);
    }
}
 
Example 11
Source File: MetaDataDeleteIndexService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void onResponse(final Response response) {
    if (notified.compareAndSet(false, true)) {
        FutureUtils.cancel(future);
        listener.onResponse(response);
    }
}
 
Example 12
Source File: InternalClusterService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStop() {
    FutureUtils.cancel(this.reconnectToNodes);
    for (NotifyTimeout onGoingTimeout : onGoingTimeouts) {
        onGoingTimeout.cancel();
        onGoingTimeout.listener.onClose();
    }
    ThreadPool.terminate(updateTasksExecutor, 10, TimeUnit.SECONDS);
    remove(localNodeMasterListeners);
}
 
Example 13
Source File: ResourceWatcherService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStop() {
    if (!enabled) {
        return;
    }
    FutureUtils.cancel(lowFuture);
    FutureUtils.cancel(mediumFuture);
    FutureUtils.cancel(highFuture);
}
 
Example 14
Source File: InternalClusterService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public void cancel() {
    FutureUtils.cancel(future);
}
 
Example 15
Source File: ScheduledCancellableAdapter.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public boolean cancel() {
    return FutureUtils.cancel(scheduledFuture);
}
 
Example 16
Source File: RoutingService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected void doClose() {
    FutureUtils.cancel(registeredNextDelayFuture);
    clusterService.remove(this);
}
 
Example 17
Source File: TranslogService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void close() {
    indexSettingsService.removeListener(applySettings);
    FutureUtils.cancel(this.future);
}
 
Example 18
Source File: SearchService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected void doClose() {
    doStop();
    FutureUtils.cancel(keepAliveReaper);
}
 
Example 19
Source File: IndexingMemoryController.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected void doStop() {
    FutureUtils.cancel(scheduler);
    scheduler = null;
}
 
Example 20
Source File: MeterMetric.java    From Elasticsearch with Apache License 2.0 votes vote down vote up
public void stop() { FutureUtils.cancel(future);}