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.openhab.binding.nest.internal.handler.NestBridgeHandler.java

/**
 * Clean up the handler.//  w w w .j a v  a2  s  .  c  o  m
 */
@Override
public void dispose() {
    logger.debug("Nest bridge disposed");
    stopStreamingUpdates();

    ScheduledFuture<?> localInitializeJob = initializeJob;
    if (localInitializeJob != null && !localInitializeJob.isCancelled()) {
        localInitializeJob.cancel(true);
        initializeJob = null;
    }

    ScheduledFuture<?> localTransmitJob = transmitJob;
    if (localTransmitJob != null && !localTransmitJob.isCancelled()) {
        localTransmitJob.cancel(true);
        transmitJob = null;
    }

    this.authorizer = null;
    this.redirectUrlSupplier = null;
    this.streamingRestClient = null;
}

From source file:org.openhab.binding.harmonyhub.internal.handler.HarmonyHubHandler.java

private void cancelRetry() {
    ScheduledFuture<?> localRetryJob = retryJob;
    if (localRetryJob != null && !localRetryJob.isDone()) {
        localRetryJob.cancel(false);
    }/*from  w ww. jav a  2  s  .co m*/
}

From source file:org.openhab.binding.harmonyhub.internal.handler.HarmonyHubHandler.java

private void disconnectFromHub() {
    ScheduledFuture<?> localHeartBeatJob = heartBeatJob;
    if (localHeartBeatJob != null && !localHeartBeatJob.isDone()) {
        localHeartBeatJob.cancel(false);
    }//from   w w  w .j ava  2 s  .c o  m
    client.disconnect();
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.security.JWTSecurityHandler.java

public void deregisterFromRenewer(ApplicationId appId) {
    if (!isJWTEnabled()) {
        return;/*from w ww.  j a  va2s  . c om*/
    }
    ScheduledFuture task = renewalTasks.get(appId);
    if (task != null) {
        task.cancel(true);
    }
}

From source file:org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.java

/**
 * Invoked when the underlying connection is closed.
 *//*from w ww. j  a v  a  2 s .  c o m*/
public final void delegateConnectionClosed(CloseStatus status) throws Exception {
    if (!isClosed()) {
        try {
            updateLastActiveTime();
            // Avoid cancelHeartbeat() and responseLock within server "close" callback
            ScheduledFuture<?> future = this.heartbeatFuture;
            if (future != null) {
                this.heartbeatFuture = null;
                future.cancel(false);
            }
        } finally {
            this.state = State.CLOSED;
            this.handler.afterConnectionClosed(this, status);
        }
    }
}

From source file:net.frontlinesms.plugins.reminders.RemindersThinletTabController.java

/**
 * Stop a Reminder/* www .j  av  a2  s .c  om*/
 */
public void stopReminder(Reminder reminder) {
    LOG.debug("Callback.stopReminder: " + reminder);
    if (reminder != null && this.futures.containsKey(reminder)) {
        ScheduledFuture<?> future = this.futures.get(reminder);
        if (future != null) {
            boolean result = future.cancel(true);
            LOG.debug("Future Cancel: " + result);
        }
        ScheduledFuture<?> expiry = this.expired.get(reminder);
        if (expiry != null) {
            boolean result = expiry.cancel(true);
            LOG.debug("Expiry Cancel: " + result);
        }
    }
}

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

private void cleanup() {
    logger.debug("cleanup {}", getThing().getUID().getAsString());
    @Nullable
    ScheduledFuture<?> refreshJob = this.refreshJob;
    if (refreshJob != null) {
        refreshJob.cancel(true);
        this.refreshJob = null;
    }//from www  .  ja va 2  s  .c o m
    @Nullable
    ScheduledFuture<?> refreshLogin = this.refreshLogin;
    if (refreshLogin != null) {
        refreshLogin.cancel(true);
        this.refreshLogin = null;
    }
    Connection connection = this.connection;
    if (connection != null) {
        connection.logout();
        this.connection = null;
    }
}

From source file:org.jumpmind.metl.core.runtime.AgentRuntime.java

protected void stop(AgentDeployment deployment) {
    ScheduledFuture<?> future = scheduledDeployments.get(deployment);
    if (future != null) {
        future.cancel(true);
        scheduledDeployments.remove(future);
    }/* w ww.j a  va2s.c om*/

    List<FlowRuntime> flowRuntimes = scheduledFlows.get(deployment);
    if (flowRuntimes != null) {
        for (FlowRuntime flowRuntime : flowRuntimes) {
            if (flowRuntime != null) {
                try {
                    flowRuntime.cancel();
                    log.info("Flow '{}' has been undeployed", deployment.getFlow().getName());
                } catch (Exception e) {
                    log.warn("Failed to stop '{}'", deployment.getFlow().getName(), e);
                }
            }
        }
    }
}

From source file:com.pushtechnology.consulting.SessionCreator.java

public void stop() {
    LOG.trace("SessionCreator#stop");
    switch (state) {
    case STARTED:
        for (ScheduledFuture<?> tmpFuture : addSessions) {
            if (tmpFuture != null) {
                tmpFuture.cancel(false);
            }//from  ww  w .j  a  v  a  2 s  .c  o m
        }
        state = STOPPED;
        break;
    default:
        break;
    }
    LOG.trace("Done SessionCreator#stop");
}

From source file:edu.umich.robot.HeadlessApplication.java

/**
 * <p>//from  ww w. j  ava 2s.c o m
 * Start Soar, wait for timeout or Soar to stop.
 * 
 * @param controller
 *            Simulation controller initialized.
 * @throws InterruptedException
 *             Thrown on thread interrupt.
 */
private void run(Controller controller) throws InterruptedException {
    final CountDownLatch doneSignal = new CountDownLatch(1);

    Thread shutdownHook = new Thread() {
        @Override
        public void run() {
            logger.warn("Shutdown detected.");
            shutdown.set(true);
            doneSignal.countDown();
        }
    };

    Runtime.getRuntime().addShutdownHook(shutdownHook);

    try {
        controller.addListener(SoarStoppedEvent.class, new RobotEventListener() {
            public void onEvent(RobotEvent event) {
                logger.info("Soar stop detected.");
                doneSignal.countDown();
            }
        });

        ScheduledExecutorService schexec = MoreExecutors
                .getExitingScheduledExecutorService(new ScheduledThreadPoolExecutor(1));
        ScheduledFuture<?> task = null;
        if (seconds > 0) {
            task = schexec.schedule(new Runnable() {
                public void run() {
                    logger.info("Time up.");
                    doneSignal.countDown();
                }
            }, seconds, TimeUnit.SECONDS);
        }

        controller.startSoar(cycles);

        doneSignal.await();

        if (task != null)
            task.cancel(true);
        schexec.shutdown();
    } finally {
        if (!shutdown.get())
            Runtime.getRuntime().removeShutdownHook(shutdownHook);
    }
}