List of usage examples for io.netty.util TimerTask run
void run(Timeout timeout) throws Exception;
From source file:com.heliosapm.streams.collector.timeout.TimeoutService.java
License:Apache License
/** * {@inheritDoc}//from w w w . j a v a 2s. com * @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:org.rzo.netty.ahessian.heartbeat.IntervalTimer.java
License:Apache License
public IntervalTimer(final Timer timer, final TimerTask task, final long interval) { _timer = timer;//from ww w.java2 s .c om _task = new TimerTask() { public void run(Timeout timeout) throws Exception { _lock.lock(); try { if (!timeout.equals(getTimeout())) { // System.out.println("other timeout -> ignore"); return; } // System.out.println(new Date()+" timer called " + // _name+"/"+_interval); try { task.run(timeout); } catch (Throwable ex) { ex.printStackTrace(); } if (getTimeout() != null) setTimeout(_timer.newTimeout(this, interval, TimeUnit.MILLISECONDS)); } finally { _lock.unlock(); } } }; _interval = interval; }