Example usage for io.netty.util Timeout isExpired

List of usage examples for io.netty.util Timeout isExpired

Introduction

In this page you can find the example usage for io.netty.util Timeout isExpired.

Prototype

boolean isExpired();

Source Link

Document

Returns true if and only if the TimerTask associated with this handle has been expired.

Usage

From source file:com.corundumstudio.socketio.scheduler.HashedWheelScheduler.java

License:Apache License

public void scheduleCallback(final SchedulerKey key, final Runnable runnable, long delay, TimeUnit unit) {
    Timeout timeout = executorService.newTimeout(new TimerTask() {
        @Override/*  w  ww.j a va2 s  .  c  om*/
        public void run(Timeout timeout) throws Exception {
            ctx.executor().execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        runnable.run();
                    } finally {
                        scheduledFutures.remove(key);
                    }
                }
            });
        }
    }, delay, unit);

    if (!timeout.isExpired()) {
        scheduledFutures.put(key, timeout);
    }
}

From source file:com.corundumstudio.socketio.scheduler.HashedWheelScheduler.java

License:Apache License

public void schedule(final SchedulerKey key, final Runnable runnable, long delay, TimeUnit unit) {
    Timeout timeout = executorService.newTimeout(new TimerTask() {
        @Override//from   www  .  j av a  2s. com
        public void run(Timeout timeout) throws Exception {
            try {
                runnable.run();
            } finally {
                scheduledFutures.remove(key);
            }
        }
    }, delay, unit);

    if (!timeout.isExpired()) {
        scheduledFutures.put(key, timeout);
    }
}

From source file:com.corundumstudio.socketio.scheduler.HashedWheelTimeoutScheduler.java

License:Apache License

private void replaceScheduledFuture(final SchedulerKey key, final Timeout newTimeout) {
    final Timeout oldTimeout;

    if (newTimeout.isExpired()) {
        // no need to put already expired timeout to scheduledFutures map.
        // simply remove old timeout
        oldTimeout = scheduledFutures.remove(key);
    } else {/*from w  w w  .j a  va2 s  .  co m*/
        oldTimeout = scheduledFutures.put(key, newTimeout);
    }

    // if there was old timeout, cancel it
    if (oldTimeout != null) {
        oldTimeout.cancel();
    }
}

From source file:me.schiz.jmeter.ring.tcp.TimeoutTask.java

License:Apache License

@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isExpired() && !timeout.isCancelled() && !ring.get(id).isPrepared) {
        ring.timeout(id, reason);//from   www  .j  a  v  a 2s.  c  o m
    }
}

From source file:me.schiz.jmeter.ring.udp.TimeoutTask.java

License:Apache License

@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isExpired() && !timeout.isCancelled()) {
        ring.get(id).lock.lock();/*from   w  w w  .  j  a  v a2  s .c om*/
        log.error("Timeout token #" + id + ". Reason: " + reason);
        //ring.reset(id);
        Token t = ring.get(id);
        try {
            SampleResult sr = t.sampleResult;
            Queue queue = t.queue;
            t.sampleResult = null;
            t.queue = null;
            sr.setSuccessful(false);
            sr.setResponseCode(ERROR_502);
            sr.sampleEnd();
            while (!queue.offer(sr)) {
            }
        } catch (NullPointerException npe) {

        }
        ring.reset(id);
        ring.get(id).lock.unlock();
    }
}

From source file:net.qing.sms.simulator.HashedWheelScheduler.java

License:Apache License

public void schedule(final SchedulerKey key, final Runnable runnable, long delay, TimeUnit unit) {
    Timeout timeout = executorService.newTimeout(new TimerTask() {
        @Override/*  w w  w .  ja  v a2s .c  om*/
        public void run(Timeout timeout) throws Exception {
            try {
                runnable.run();
            } finally {
                scheduledFutures.remove(key);
            }
        }
    }, delay, unit);

    if (!timeout.isExpired()) {
        Timeout preTimeout = scheduledFutures.put(key, timeout);
        if (preTimeout != null) {
            preTimeout.cancel();
        }
    }
}

From source file:org.opendaylight.netvirt.ipv6service.utils.Ipv6TimerWheel.java

License:Open Source License

public void cancelPeriodicTransmissionTimeout(Timeout timeout) {
    if (timeout != null) {
        synchronized (timeout) {
            if (!timeout.isExpired()) {
                timeout.cancel();/*from  w  w w .j  ava2s . co m*/
            }
        }
    }
}

From source file:org.opendaylight.sfc.pot.netconf.renderer.provider.SfcPotTimerWheel.java

License:Open Source License

public void clearTimerContext(Timeout timeout) {
    if (timeout != null) {
        synchronized (sfcPotTimerWheelObj) {
            if (!timeout.isExpired()) {
                timeout.cancel();//  ww  w.  ja v a 2  s.  co m
            }
        }
    }
}

From source file:qunar.tc.qmq.service.HeartbeatManager.java

License:Apache License

public void refreshHeartbeat(T key, TimerTask task, long timeout, TimeUnit unit) {
    Timeout context = timer.newTimeout(task, timeout, unit);
    final Timeout old = timeouts.put(key, context);
    if (old != null && !old.isCancelled() && !old.isExpired()) {
        old.cancel();/* w ww  .ja v a 2s  .  c o m*/
    }
}