@Override public void copyTo(Copyable copy) { super.copyTo(copy); CacheableSelectionKeyHandler copyHandler = (CacheableSelectionKeyHandler) copy; copyHandler.inboundConnectionCache = inboundConnectionCache; }
/** * Registers {@link SelectionKey} to handle certain operations */ protected void doRegisterKey(SelectionKey key, int selectionKeyOps, long currentTime) { if (!key.isValid()) { return; } key.interestOps(key.interestOps() | selectionKeyOps); addExpirationStamp(key); }
/** * {@inheritDoc} */ @Override public void register(SelectionKey key, int selectionKeyOps) { doRegisterKey(key, selectionKeyOps, System.currentTimeMillis()); }
Long expire = getExpirationStamp(key); if (expire != null){ if (currentTime - expire >= timeout) { cancel(key); } else if (expire + timeout < nextKeysExpiration) { nextKeysExpiration = expire + timeout;
@Override public void cancel(SelectionKey key) { super.cancel(key); inboundConnectionCache.close(key.channel()); } }
@Override public void expire(Iterator<SelectionKey> keys) { super.expire(keys); }
@Override public void process(SelectionKey key) { super.process(key); inboundConnectionCache.requestReceived(key.channel()); }
/** * {@inheritDoc} */ @Override public void process(SelectionKey key) { super.process(key); removeExpirationStamp(key); }
new DefaultSelectionKeyHandler(selectorHandler);
@Override public void cancel(SelectionKey key) { if (key != null) { if (selectorThread.getThreadPool() instanceof StatsThreadPool) { if (selectorThread.isMonitoringEnabled() && ((StatsThreadPool) selectorThread.getThreadPool()).getStatistic().decrementOpenConnectionsCount(key.channel())) { selectorThread.getRequestGroupInfo().decreaseCountOpenConnections(); } } super.cancel(key); } }
@Override public void cancel(SelectionKey key) { if (key != null) { selectorThread.getKeepAliveCounter().untrap(key); } if (selectorThread.isMonitoringEnabled()) { selectorThread.getRequestGroupInfo().decreaseCountOpenConnections(); } super.cancel(key); }
@Override public void copyTo(Copyable copy) { super.copyTo(copy); SelectorThreadKeyHandler copyHandler = (SelectorThreadKeyHandler) copy; copyHandler.selectorThread = selectorThread; }
/** * {@inheritDoc} */ @Override public void register(Iterator<SelectionKey> keyIterator, int selectionKeyOps) { long currentTime = System.currentTimeMillis(); SelectionKey key; while (keyIterator.hasNext()) { key = keyIterator.next(); keyIterator.remove(); doRegisterKey(key, selectionKeyOps, currentTime); } }
/** * {@inheritDoc} */ @Override public void postProcess(SelectionKey key) { super.postProcess(key); addExpirationStamp(key); }
@Override public void copyTo(Copyable copy) { super.copyTo(copy); SelectorThreadKeyHandler copyHandler = (SelectorThreadKeyHandler) copy; copyHandler.selectorThread = selectorThread; }
/** * {@inheritDoc} */ @Override public void register(SelectableChannel channel, int ops) throws ClosedChannelException { if (!channel.isOpen()) { return; } Selector selector = selectorHandler.getSelector(); SelectionKey key = channel.keyFor(selector); long time = System.currentTimeMillis(); if (key == null) { key = channel.register(selector, ops, time); } else { doRegisterKey(key, ops, time); } }