List of usage examples for io.netty.util Timeout cancel
boolean cancel();
From source file:org.rzo.netty.ahessian.session.ServerSessionFilter.java
License:Apache License
private void handleSession(ChannelHandlerContext ctx, Session session, HandlerList pipeline) { _hasSession = true;/* w ww . j a v a2 s . c om*/ session.setClosed(false); // if we have a session timeout set, cancel it. Timeout timeOut = session.removeTimeout(); if (timeOut != null) timeOut.cancel(); if (pipeline.hasChannel()) { Constants.ahessianLogger.warn(ctx.channel() + " session already attached -> close connection"); pipeline.close(); } // now that we have a session extend the pipeline pipeline.mixin(ctx); ctx.channel().attr(SESSION).set(session); _channel = ctx.channel(); // first send session and wait until it has been transmitted ctx.writeAndFlush(Unpooled.wrappedBuffer(session.getId().getBytes())).awaitUninterruptibly(); // only then inform the mixin pipeline that we are connected ctx.fireChannelActive(); }
From source file:org.rzo.netty.ahessian.utils.TimedBlockingPriorityQueue.java
License:Apache License
public boolean offer(final T e, int group) { boolean result = false; _lock.lock();//w ww. j a v a 2 s .c o m try { // if (_size == 0) // System.out.println("LRUQueue not empty: "+ _name); _size++; if (group >= _queues.length) { Constants.ahessianLogger.warn("group " + group + " not defined -> using group 0"); group = 0; } final LinkedList<T> q = _queues[group]; result = q.offer((T) e); if (q.size() >= _sizes[group]) { // if queue is full remove an element and undo its timer T o = q.remove(); Timeout timer = _timers.remove(o); if (timer != null) timer.cancel(); Constants.ahessianLogger.warn("queue overflow -> removed " + e); } if (result) _last = e; if (_timer != null && result && _timeouts[group] > 0) { Timeout timer = _timer.newTimeout(new TimerTask() { public void run(Timeout arg0) throws Exception { _lock.lock(); try { q.remove(e); Constants.ahessianLogger.warn("message timed out -> removed from queue " + e); } finally { _lock.unlock(); } } }, _timeouts[group], TimeUnit.MILLISECONDS); } if (result && waiting) try { _hasData.signal(); } catch (Exception ex) { Constants.ahessianLogger.warn("", ex); } } finally { _lock.unlock(); } return result; }
From source file:org.rzo.netty.ahessian.utils.TimedBlockingPriorityQueue.java
License:Apache License
public T poll(int group) { LinkedList<T> q = _queues[group]; T result = null;// ww w . j a va 2 s .c o m if (q != null) { result = q.poll(); if (result != null) { Timeout timer = _timers.remove(result); if (timer != null) timer.cancel(); } } return result; }
From source file:org.traccar.database.ConnectionManager.java
License:Apache License
public void updateDevice(final long deviceId, String status, Date time) { Device device = Context.getIdentityManager().getById(deviceId); if (device == null) { return;//from w w w .j a v a 2 s .c o m } String oldStatus = device.getStatus(); device.setStatus(status); if (enableStatusEvents && !status.equals(oldStatus)) { String eventType; Map<Event, Position> events = new HashMap<>(); switch (status) { case Device.STATUS_ONLINE: eventType = Event.TYPE_DEVICE_ONLINE; break; case Device.STATUS_UNKNOWN: eventType = Event.TYPE_DEVICE_UNKNOWN; if (updateDeviceState) { events.putAll(updateDeviceState(deviceId)); } break; default: eventType = Event.TYPE_DEVICE_OFFLINE; if (updateDeviceState) { events.putAll(updateDeviceState(deviceId)); } break; } events.put(new Event(eventType, deviceId), null); Context.getNotificationManager().updateEvents(events); } Timeout timeout = timeouts.remove(deviceId); if (timeout != null) { timeout.cancel(); } if (time != null) { device.setLastUpdate(time); } if (status.equals(Device.STATUS_ONLINE)) { timeouts.put(deviceId, GlobalTimer.getTimer().newTimeout(new TimerTask() { @Override public void run(Timeout timeout) { if (!timeout.isCancelled()) { updateDevice(deviceId, Device.STATUS_UNKNOWN, null); } } }, deviceTimeout, TimeUnit.MILLISECONDS)); } try { Context.getDeviceManager().updateDeviceStatus(device); } catch (SQLException error) { LOGGER.warn("Update device status error", error); } updateDevice(device); if (status.equals(Device.STATUS_ONLINE) && !oldStatus.equals(Device.STATUS_ONLINE)) { Context.getCommandsManager().sendQueuedCommands(getActiveDevice(deviceId)); } }
From source file:qunar.tc.qmq.service.HeartbeatManager.java
License:Apache License
public void cancel(T key) { Timeout timeout = timeouts.remove(key); if (timeout == null) return;/*from w w w . ja v a2 s.co m*/ timeout.cancel(); }
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(); }//from w ww. j av a 2 s . co m }