Example usage for io.netty.util TimerTask TimerTask

List of usage examples for io.netty.util TimerTask TimerTask

Introduction

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

Prototype

TimerTask

Source Link

Usage

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

License:Apache License

public void schedule(final Runnable runnable, long delay, TimeUnit unit) {
    executorService.newTimeout(new TimerTask() {
        @Override//from  w w  w .  j  av  a 2 s.c  o m
        public void run(Timeout timeout) throws Exception {
            runnable.run();
        }
    }, delay, unit);
}

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/*from   w w w . j a  v  a 2  s  .  c o m*/
        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/*w  ww.j  a  v a  2s .c o  m*/
        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

public void scheduleCallback(final SchedulerKey key, final Runnable runnable, long delay, TimeUnit unit) {
    Timeout timeout = executorService.newTimeout(new TimerTask() {
        @Override//from w w w. j a  v a  2  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);

    replaceScheduledFuture(key, timeout);
}

From source file:com.corundumstudio.socketio.scheduler.HashedWheelTimeoutScheduler.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  ww . ja va2  s . c  o m
        public void run(Timeout timeout) throws Exception {
            try {
                runnable.run();
            } finally {
                scheduledFutures.remove(key);
            }
        }
    }, delay, unit);

    replaceScheduledFuture(key, timeout);
}

From source file:com.github.spapageo.jannel.windowing.TimedDeferredRequest.java

License:Open Source License

/**
 * Intentional private local constructor
 * @param key the request key/*w  w w.  jav  a2  s  . co  m*/
 * @param request the request object
 * @param window the window
 * @param timeoutMillis the time after which this future will be cancelled
 * @param timer the timer used to implement the timeout functionality
 */
private TimedDeferredRequest(final K key, final R request, final Window<K, R, D> window, final Timer timer,
        final long timeoutMillis) {
    super(key, request, window);
    this.timeout = checkNotNull(timer).newTimeout(new TimerTask() {
        @Override
        public void run(Timeout timerTask) throws Exception {
            window.fail(checkNotNull(key), new TimeoutException("The operation timed out (Window full)"));
        }
    }, timeoutMillis, TimeUnit.MILLISECONDS);
}

From source file:com.heliosapm.streams.collector.timeout.TimeoutService.java

License:Apache License

/**
 * Schedules a task to run on the timeout period
 * @param delay the timeout period//w ww .  ja  v  a  2s . c  o m
 * @param unit the timeout unit
 * @param onTimeout the task to execute if the timer expires
 * @return the timeout handle
 */
public Timeout timeout(final long delay, final TimeUnit unit, final Runnable onTimeout) {
    return new WrappedTimeout(timer.newTimeout(new TimerTask() {
        @Override
        public void run(final Timeout timeout) throws Exception {
            try {
                onTimeout.run();
            } finally {
                pendingTimeouts.decrementAndGet();
                timeouts.increment();
            }
        }
    }, delay, unit));
}

From source file:com.heliosapm.streams.collector.timeout.TimeoutService.java

License:Apache License

/**
 * {@inheritDoc}/*  w  ww .  j a  v a2 s  . co m*/
 * @see io.netty.util.Timer#newTimeout(io.netty.util.TimerTask, long, java.util.concurrent.TimeUnit)
 */
@Override
public Timeout newTimeout(final TimerTask task, final long delay, final TimeUnit unit) {
    final WrappedTimeout[] t = new WrappedTimeout[1];
    t[0] = new WrappedTimeout(timer.newTimeout(new TimerTask() {
        @Override
        public void run(final Timeout timeout) throws Exception {
            try {
                task.run(t[0]);
            } finally {
                pendingTimeouts.decrementAndGet();
                timeouts.increment();
            }
        }
    }, delay, unit));
    return t[0];
}

From source file:com.king.platform.net.http.netty.pool.PoolingChannelPool.java

License:Apache License

public PoolingChannelPool(final Timer cleanupTimer, TimeProvider timeProvider, long timeoutInSeconds,
        final MetricCallback metricCallback) {
    this.timeProvider = timeProvider;
    this.metricCallback = metricCallback;

    maxTtl = TimeUnit.SECONDS.toMillis(timeoutInSeconds);

    cleanupTimer.newTimeout(new TimerTask() {
        @Override/*from w w  w  .java 2  s.  co m*/
        public void run(Timeout timeout) throws Exception {

            for (Map.Entry<ServerInfo, ServerPool> poolEntry : serverPoolMap.entrySet()) {
                ServerPool serverPool = poolEntry.getValue();
                ServerInfo serverInfo = poolEntry.getKey();

                serverPool.cleanExpiredConnections();
                if (serverPool.shouldRemovePool()) {
                    ServerPool remove = serverPoolMap.remove(serverInfo);
                    if (remove != null) {
                        metricCallback.onRemovedServerPool(serverInfo.getHost());
                    }
                }

            }

            cleanupTimer.newTimeout(timeout.task(), maxTtl, TimeUnit.MILLISECONDS);

        }
    }, maxTtl, TimeUnit.MILLISECONDS);
}

From source file:com.kradac.karview.netty.EchoServerHandler.java

private void processSendComand() {
    if (runTimerCmd) {
        if (timeCloseChannel > 0) {
            timeCloseChannel -= 5;/*  w  w w .j a  v a 2  s  .  c om*/
            ///Verifico si tiene un comando de envio el equipo que llego en la trama 
            Comandos cmd = cjc.getComandosToSend(e.getIdEquipo());
            if (cmd != null) {
                this.c.write(cmd.getComando() + "%%" + tipoEquipoGPRS);
                cmdSend.add(cmd);
                cmd.setIdTipoEstadoCmd(2);
                cmd.setFechaHoraEnvio(new Date());
                String msj = "Enviando [" + cmd.getComando() + "] -> [" + e.getEquipo() + "]";
                System.out.println(msj);
                try {
                    cjc.edit(cmd);
                } catch (Exception ex) {
                    System.out.println("Al Editar Envio de Comando: " + ex.getMessage());
                }
            }
            this.t.newTimeout(new TimerTask() {
                @Override
                public void run(Timeout tmt) throws Exception {
                    processSendComand();
                }
            }, 5, TimeUnit.SECONDS);
        } else {
            c.close();
        }
    }
}