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() . These examples are extracted from open source projects. 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 Project: Elasticsearch   File: IndexShard.java    License: 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 2
Source Project: Elasticsearch   File: Translog.java    License: 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 3
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 4
@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 5
/**
 * 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 6
@Override
protected void doStop() {
    if (!enabled) {
        return;
    }
    FutureUtils.cancel(lowFuture);
    FutureUtils.cancel(mediumFuture);
    FutureUtils.cancel(highFuture);
}
 
Example 7
@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 8
@Override
public void onResponse(final Response response) {
    if (notified.compareAndSet(false, true)) {
        FutureUtils.cancel(future);
        listener.onResponse(response);
    }
}
 
Example 9
@Override
public void onFailure(Throwable t) {
    if (notified.compareAndSet(false, true)) {
        FutureUtils.cancel(future);
        listener.onFailure(t);
    }
}
 
Example 10
Source Project: Elasticsearch   File: Retry.java    License: 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 11
Source Project: Elasticsearch   File: Retry.java    License: Apache License 2.0 5 votes vote down vote up
private void finishHim() {
    try {
        listener.onResponse(getAccumulatedResponse());
    } finally {
        FutureUtils.cancel(scheduledRequestFuture);
    }
}
 
Example 12
Source Project: Elasticsearch   File: BulkProcessor.java    License: 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 13
/**
 * 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 14
@Override
protected void doStop() {
    FutureUtils.cancel(scheduler);
    scheduler = null;
}
 
Example 15
Source Project: Elasticsearch   File: SearchService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void doClose() {
    doStop();
    FutureUtils.cancel(keepAliveReaper);
}
 
Example 16
Source Project: Elasticsearch   File: TranslogService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void close() {
    indexSettingsService.removeListener(applySettings);
    FutureUtils.cancel(this.future);
}
 
Example 17
Source Project: Elasticsearch   File: RoutingService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void doClose() {
    FutureUtils.cancel(registeredNextDelayFuture);
    clusterService.remove(this);
}
 
Example 18
public void cancel() {
    FutureUtils.cancel(future);
}
 
Example 19
@Override
public boolean cancel() {
    return FutureUtils.cancel(scheduledFuture);
}
 
Example 20
Source Project: Elasticsearch   File: MeterMetric.java    License: Apache License 2.0 votes vote down vote up
public void stop() { FutureUtils.cancel(future);}