Example usage for java.util.concurrent Future cancel

List of usage examples for java.util.concurrent Future cancel

Introduction

In this page you can find the example usage for java.util.concurrent Future cancel.

Prototype

boolean cancel(boolean mayInterruptIfRunning);

Source Link

Document

Attempts to cancel execution of this task.

Usage

From source file:com.agileEAP.module.cache.memcached.SpyMemcachedClient.java

/**
 * Set, ??updateTimeout, ?false??./*  ww w  .  j  a  va2 s  .c  om*/
 */
public boolean safeSet(String key, int expiration, Object value) {
    Future<Boolean> future = memcachedClient.set(key, expiration, value);
    try {
        return future.get(updateTimeout, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        future.cancel(false);
    }
    return false;
}

From source file:org.pssframework.cache.MemcachedImpl.java

public boolean safeDelete(String key) {
    Future<Boolean> future = client.delete(key);
    try {//from w w  w  .j a  v  a2 s .  c  o  m
        return future.get(1, TimeUnit.SECONDS);
    } catch (Exception e) {
        future.cancel(false);
    }
    return false;
}

From source file:org.apache.sling.distribution.trigger.impl.RemoteEventDistributionTrigger.java

public void unregister(@Nonnull DistributionRequestHandler requestHandler) throws DistributionException {
    Future<HttpResponse> httpResponseFuture = requests.remove(requestHandler.toString());
    if (httpResponseFuture != null) {
        httpResponseFuture.cancel(true);
    }/*from  w w  w  .ja v  a  2 s  .  com*/
    scheduler.unschedule(getJobName(requestHandler));
}

From source file:com.amazon.alexa.avs.NotificationManager.java

public void handleClearIndicator() {
    allowPersistentIndicator.set(false);
    synchronized (indicatorFutures) {
        for (Future<?> f : indicatorFutures) {
            f.cancel(true);
        }/*from  w w  w . j a va  2  s.c o m*/
    }
    indicatorFutures.clear();
    setIndicatorStatus(Status.NONE);
}

From source file:com.njmd.framework.utils.memcached.SpyMemcachedClient.java

/**
 * Set,1, ?false??./*w  ww. jav a2  s .  co m*/
 */
public boolean safeSet(String key, Object value, int expiration) {
    Future<Boolean> future = memcachedClient.set(key, expiration, value);
    try {
        return future.get(1, TimeUnit.SECONDS);
    } catch (Exception e) {
        future.cancel(false);
    }
    return false;
}

From source file:com.mozilla.bagheera.consumer.KafkaConsumer.java

@Override
public void close() {
    LOG.info("Shutting down!");
    if (executor != null) {
        // Regular shutdown doesn't do much for us here since
        // these are long running threads
        executor.shutdown();/*ww w  .  j  av a  2s  .  c o  m*/
        try {
            // To actually interrupt our workers we'll cancel each future.
            for (Future<?> worker : workers) {
                worker.cancel(true);
            }
            if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
                executor.shutdownNow();
                LOG.info("Shutting down now!");
                if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
                    LOG.error("Unable to shudown consumer thread pool");
                }
            }
        } catch (InterruptedException e) {
            executor.shutdownNow();
            Thread.currentThread().interrupt();
        } finally {
            // close the kafka consumer connector
            if (consumerConnector != null) {
                LOG.info("Shutting down consumer connector!");
                consumerConnector.shutdown();
            }
        }
    }
}

From source file:io.cloudslang.worker.management.services.WorkerManager.java

@SuppressWarnings("unused")
//scheduled in scoreWorkerSchedulerContext.xml
public void interruptCanceledExecutions() {
    for (Long executionId : mapOfRunningTasks.keySet()) {
        if (workerConfigurationService.isExecutionCancelled(executionId)) {
            Future future = mapOfRunningTasks.get(executionId);
            future.cancel(true);
        }//from www.ja va2 s.c  om
    }
}

From source file:org.apache.usergrid.services.notifications.QueueListener.java

public void stop() {
    if (logger.isDebugEnabled()) {
        logger.debug("stop processes");
    }// ww w.  j  av  a 2s.  c  o m

    if (futures == null) {
        return;
    }
    for (Future future : futures) {
        future.cancel(false);
    }

    pool.shutdownNow();
}

From source file:org.activiti.extension.cache.MemcachedManager.java

/**
 * Delete, ??updateTimeout, ?false??./* w  ww. j av  a2 s.  c o m*/
 */
@ManagedOperation(description = "Delete, ??updateTimeout, ?false??.")
@ManagedOperationParameters({ @ManagedOperationParameter(name = "key", description = "key") })
public boolean safeDelete(String key) {
    Future<Boolean> future = memcachedClient.delete(key);
    try {
        return future.get(updateTimeout, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        future.cancel(false);
    }
    return false;
}

From source file:org.pssframework.cache.MemcachedImpl.java

public Object get(String key) {
    Future<Object> future = client.asyncGet(key, serializingTranscoder);
    try {//w w  w.j  a v a  2 s  .c om
        return future.get(1, TimeUnit.SECONDS);
    } catch (Exception e) {
        future.cancel(false);
    }
    return null;
}