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:com.l2jfree.gameserver.gameobjects.L2Creature.java

/**
 * Disable this skill id for the duration of the delay in milliseconds.
 * /*from  w  w w. j  a  v  a2  s  . co  m*/
 * @param skillId
 * @param delay in milliseconds
 * @return modified
 */
public boolean disableSkill(int skillId, int delay) {
    if (delay < 100)
        return false;

    if (_disabledSkills == null)
        _disabledSkills = new FastMap<Integer, ScheduledFuture<?>>();

    final ScheduledFuture<?> oldTask = _disabledSkills.get(skillId);

    if (oldTask != null) {
        if (oldTask.getDelay(TimeUnit.MILLISECONDS) + 50 >= delay)
            return false;

        oldTask.cancel(false);
    }

    _disabledSkills.put(skillId, ThreadPoolManager.getInstance().schedule(new EnableSkill(skillId), delay));
    return true;
}

From source file:org.hyperledger.fabric.sdk.Channel.java

/**
 * Shutdown the channel with all resources released.
 *
 * @param force force immediate shutdown.
 *///  w w w .j  a  v  a  2s  .  c om

public synchronized void shutdown(boolean force) {

    if (shutdown) {
        return;
    }

    String ltransactionListenerProcessorHandle = transactionListenerProcessorHandle;
    transactionListenerProcessorHandle = null;
    if (null != ltransactionListenerProcessorHandle) {

        try {
            unregisterBlockListener(ltransactionListenerProcessorHandle);
        } catch (Exception e) {
            logger.error(format("Shutting down channel %s transactionListenerProcessorHandle", name), e);
        }
    }

    String lchaincodeEventUpgradeListenerHandle = chaincodeEventUpgradeListenerHandle;
    chaincodeEventUpgradeListenerHandle = null;
    if (null != lchaincodeEventUpgradeListenerHandle) {

        try {
            unregisterChaincodeEventListener(lchaincodeEventUpgradeListenerHandle);
        } catch (Exception e) {
            logger.error(format("Shutting down channel %s chaincodeEventUpgradeListenr", name), e);
        }
    }

    initialized = false;
    shutdown = true;

    final ServiceDiscovery lserviceDiscovery = serviceDiscovery;
    serviceDiscovery = null;
    if (null != lserviceDiscovery) {
        lserviceDiscovery.shutdown();
    }

    if (chainCodeListeners != null) {
        chainCodeListeners.clear();

    }

    if (blockListeners != null) {
        blockListeners.clear();
    }

    if (client != null) {
        client.removeChannel(this);
    }

    client = null;

    for (EventHub eh : eventHubs) {

        try {
            eh.shutdown();
        } catch (Exception e) {
            // Best effort.
        }

    }
    eventHubs.clear();
    for (Peer peer : new ArrayList<>(getPeers())) {

        try {
            removePeerInternal(peer);
            peer.shutdown(force);
        } catch (Exception e) {
            // Best effort.
        }
    }
    peers.clear(); // make sure.

    peerEndpointMap.clear();
    ordererEndpointMap.clear();

    //Make sure
    for (Set<Peer> peerRoleSet : peerRoleSetMap.values()) {
        peerRoleSet.clear();
    }

    for (Orderer orderer : getOrderers()) {
        orderer.shutdown(force);
    }

    orderers.clear();

    if (null != eventQueueThread) {
        eventQueueThread.interrupt();
        eventQueueThread = null;
    }
    ScheduledFuture<?> lsweeper = sweeper;
    sweeper = null;

    if (null != lsweeper) {
        lsweeper.cancel(true);
    }

    ScheduledExecutorService lse = sweeperExecutorService;
    sweeperExecutorService = null;
    if (null != lse) {
        lse.shutdownNow();
    }
}