Example usage for java.util.concurrent ScheduledFuture cancel

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

Introduction

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

Prototype

boolean cancel(boolean mayInterruptIfRunning);

Source Link

Document

Attempts to cancel execution of this task.

Usage

From source file:org.apache.nifi.io.nio.ChannelListener.java

public void shutdown(final long period, final TimeUnit timeUnit) {
    channelDispatcher.stop();//from   www.ja  v a2 s.com
    for (SelectionKey selectionKey : socketChannelSelector.keys()) {
        final AbstractChannelReader reader = (AbstractChannelReader) selectionKey.attachment();
        selectionKey.cancel();
        if (reader != null) {
            while (!reader.isClosed()) {
                try {
                    Thread.sleep(channelReaderFrequencyMSecs);
                } catch (InterruptedException e) {
                }
            }
            final ScheduledFuture<?> readerFuture = reader.getScheduledFuture();
            readerFuture.cancel(false);
        }
        IOUtils.closeQuietly(selectionKey.channel()); // should already be closed via reader, but if reader did not exist...
    }
    IOUtils.closeQuietly(socketChannelSelector);

    for (SelectionKey selectionKey : serverSocketSelector.keys()) {
        selectionKey.cancel();
        IOUtils.closeQuietly(selectionKey.channel());
    }
    IOUtils.closeQuietly(serverSocketSelector);
    executor.shutdown();
    try {
        executor.awaitTermination(period, timeUnit);
    } catch (final InterruptedException ex) {
        LOGGER.warn("Interrupted while trying to shutdown executor");
    }
    final int currentBufferPoolSize = bufferPool.size();
    final String warning = (currentBufferPoolSize != initialBufferPoolSize)
            ? "Initial buffer count=" + initialBufferPoolSize + " Current buffer count=" + currentBufferPoolSize
                    + " Could indicate a buffer leak.  Ensure all consumers are executed until they complete."
            : "";
    LOGGER.info("Channel listener shutdown. " + warning);
}

From source file:org.openhab.binding.amazonechocontrol.handler.FlashBriefingProfileHandler.java

@Override
public void dispose() {
    ScheduledFuture<?> updateStateJob = this.updateStateJob;
    this.updateStateJob = null;
    if (updateStateJob != null) {
        updateStateJob.cancel(false);
    }/*from w  ww  .  j a  va  2s  .co m*/
    super.dispose();
}

From source file:com.l2jfree.gameserver.instancemanager.BossSpawnManager.java

/**
 * Saves all raidboss status and then clears all info from memory,
 * including all schedules./*w ww .  j av  a 2  s  .c  o m*/
 */
public void cleanUp() {
    updateDb();
    _bosses.clear();
    if (_schedules != null) {
        for (Integer bossId : _schedules.keySet()) {
            ScheduledFuture<?> f = _schedules.get(bossId);
            f.cancel(true);
        }
    }
    _schedules.clear();
    _storedInfo.clear();
    _spawns.clear();
}

From source file:org.apache.hadoop.security.ssl.ReloadingX509TrustManager.java

/**
 * Stops the reloader thread./*from  w ww.  j  a v a2 s  . co  m*/
 */
public void destroy() {
    if (reloader != null) {
        ScheduledFuture task = reloader.get();
        if (task != null) {
            task.cancel(true);
            reloader = null;
        }
    }
}

From source file:io.gravitee.gateway.services.healthcheck.HealthCheckService.java

private void stopHealthCheck(Api api) {
    ScheduledFuture scheduledFuture = scheduledTasks.remove(api);
    if (scheduledFuture != null) {
        if (!scheduledFuture.isCancelled()) {
            LOGGER.info("Stop health-check");
            scheduledFuture.cancel(true);
        } else {//from   w w w  .j  a  v  a 2  s . c  o m
            LOGGER.info("Health-check already shutdown");
        }
    }
}

From source file:com.l2jfree.gameserver.instancemanager.BossSpawnManager.java

public void deleteSpawn(L2Spawn spawnDat, boolean updateDb) {
    if (spawnDat == null)
        return;//from   www  .  j  a  v a 2  s .  co  m
    if (!_spawns.containsKey(spawnDat.getNpcId()))
        return;

    int bossId = spawnDat.getNpcId();

    SpawnTable.getInstance().deleteSpawn(spawnDat, false);
    _spawns.remove(bossId);

    if (_bosses.containsKey(bossId))
        _bosses.remove(bossId);

    if (_schedules.containsKey(bossId)) {
        ScheduledFuture<?> f = _schedules.get(bossId);
        f.cancel(true);
        _schedules.remove(bossId);
    }

    if (_storedInfo.containsKey(bossId))
        _storedInfo.remove(bossId);

    if (updateDb)
        deleteFromDb(spawnDat, bossId);
}

From source file:edu.umass.cs.gigapaxos.FailureDetection.java

private synchronized void cleanupFailedPingTask(NodeIDType id) {
    ScheduledFuture<PingTask> pingTask = this.futures.get(id);
    if (pingTask != null) {
        pingTask.cancel(true);
        this.futures.remove(id);
        sendKeepAlive(id);//from w  w  w . j a v a 2s  .com
    }
}

From source file:io.fabric8.che.starter.openshift.CheDeploymentConfig.java

private void waitUntilDeploymentConfigIsAvailable(final OpenShiftClient client, String namespace) {
    final BlockingQueue<Object> queue = new ArrayBlockingQueue<Object>(1);

    final Runnable readinessPoller = new Runnable() {
        public void run() {
            try {
                if (isDeploymentAvailable(client, namespace)) {
                    queue.put(true);//from  w  w w .j a v a2s .  co  m
                    return;
                } else {
                    queue.put(false);
                    return;
                }
            } catch (Throwable t) {
                try {
                    if (queue.isEmpty()) {
                        queue.put(false);
                    }
                    return;
                } catch (InterruptedException e) {
                }
            }
        }
    };

    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    ScheduledFuture<?> poller = executor.scheduleWithFixedDelay(readinessPoller, 0, 500, TimeUnit.MILLISECONDS);
    executor.schedule(new Runnable() {

        @Override
        public void run() {
            poller.cancel(true);
        }
    }, Integer.valueOf(startTimeout), TimeUnit.SECONDS);
    try {
        while (!waitUntilReady(queue)) {
        }
    } finally {
        if (!poller.isDone()) {
            poller.cancel(true);
        }
        executor.shutdown();
    }
}

From source file:org.apache.hadoop.security.ssl.ReloadingX509KeyManager.java

/**
 * Stops the reloading thread// www  .  j a  v a  2  s.  c o  m
 */
public void stop() {
    if (reloader != null) {
        ScheduledFuture task = reloader.get();
        if (task != null) {
            task.cancel(true);
            reloader = null;
        }
    }
}

From source file:com.adaptris.core.RetryMessageErrorHandlerImp.java

private void shutdownExecutor() {
    sweeper.cancel(true);//from w ww  . j  a  v a  2  s .  co  m
    for (ScheduledFuture f : retries) {
        f.cancel(true);
    }
    retries.clear();
    ManagedThreadFactory.shutdownQuietly(executor, DEFAULT_POOL_TIMEOUT);
    executor = null;
}