public void setLastWriteTime(long lastWriteTime) { idleInfo.setLastWriteTime(lastWriteTime); }
public void setLastReadTime(long lastReadTime) { idleInfo.setLastReadTime(lastReadTime); }
public void stop() { task.stop(); }
private void idleCheck0(NioChannelImpl channel, long currentTime) { IdleInfo idle = channel.getIdleInfo(); long lastReadTime = idle.getLastReadTime(); long lastWriteTime = idle.getLastWriteTime(); long lastIoTime = Math.max(lastReadTime, lastWriteTime); NioConfig config = channel.getConfig(); if (config.getIdleTimeBoth() > 0) { notifyIdle(channel, IdleState.BOTH_IDLE, currentTime, config.getIdleTimeBoth() * 1000, Math.max(lastIoTime, idle.getLastBothIdleTime())); } if (config.getIdleTimeRead() > 0) { notifyIdle(channel, IdleState.READER_IDLE, currentTime, config.getIdleTimeRead() * 1000, Math.max(lastIoTime, idle.getLastReadIdleTime())); } if (config.getIdleTimeWrite() > 0) { notifyIdle(channel, IdleState.WRITER_IDLE, currentTime, config.getIdleTimeWrite() * 1000, Math.max(lastIoTime, idle.getLastWriteIdleTime())); } notifyWriteTimeout(channel, currentTime); }
public void fireChannelIdle(IdleState state, long currentTime) { switch (state) { case BOTH_IDLE: idleInfo.setLastBothIdleTime(currentTime); break; case WRITER_IDLE: idleInfo.setLastWriteIdleTime(currentTime); break; case READER_IDLE: idleInfo.setLastReadIdleTime(currentTime); break; } eventHandler().channelIdle(this, state); }
public AbstractNioProcessor(NioHandler eventHandler, ChannelInitializer channelInitializer) { this.eventHandler = eventHandler; this.executor = Executors.newFixedThreadPool(Constants.AVAILABLE_PROCESSOR, new NamedThreadFactory("NioProcessorExecutor", true)); this.selectorLoop = new NioSelectorLoop("AcceptSelectorLoop-I/O", this); // this.readWriteSelectorPool = new FixedNioSelectorLoopPool(Constants.AVAILABLE_PROCESSOR + 1, "Server", this); this.idleDetector = new IdleDetector(); this.channelInitializer = channelInitializer; this.idleDetector.start(); }
@Override public void operationComplete(Future future) throws Exception { removeChannel(((Futures.CloseFuture) future).channel()); } });
public NioChannelImpl(NioSelectorLoop selectorLoop, NioProcessor processor, SocketChannel channel, NioHandler eventHandler, NioConfig config) { this.channel = channel; this.selectorLoop = selectorLoop; this.processor = processor; this.eventHandler = eventHandler; this.id = CONN_ID.incrementAndGet(); this.idleInfo = new IdleInfo(); this.config = config; closeFuture.setChannel(this); }
@Override public void run() { thread = Thread.currentThread(); while (!stop) { long currentTime = SystemClock.now(); for (NioChannel channel : channels) { if (channel.isConnected()) { idleCheck0((NioChannelImpl) channel, currentTime); } } try { Thread.sleep(1000L); } catch (InterruptedException ignored) { } } }
this.idleDetector.addChannel(channel);
private void idleCheck0(NioChannelImpl channel, long currentTime) { IdleInfo idle = channel.getIdleInfo(); long lastReadTime = idle.getLastReadTime(); long lastWriteTime = idle.getLastWriteTime(); long lastIoTime = Math.max(lastReadTime, lastWriteTime); NioConfig config = channel.getConfig(); if (config.getIdleTimeBoth() > 0) { notifyIdle(channel, IdleState.BOTH_IDLE, currentTime, config.getIdleTimeBoth() * 1000, Math.max(lastIoTime, idle.getLastBothIdleTime())); } if (config.getIdleTimeRead() > 0) { notifyIdle(channel, IdleState.READER_IDLE, currentTime, config.getIdleTimeRead() * 1000, Math.max(lastIoTime, idle.getLastReadIdleTime())); } if (config.getIdleTimeWrite() > 0) { notifyIdle(channel, IdleState.WRITER_IDLE, currentTime, config.getIdleTimeWrite() * 1000, Math.max(lastIoTime, idle.getLastWriteIdleTime())); } notifyWriteTimeout(channel, currentTime); }
public void fireChannelIdle(IdleState state, long currentTime) { switch (state) { case BOTH_IDLE: idleInfo.setLastBothIdleTime(currentTime); break; case WRITER_IDLE: idleInfo.setLastWriteIdleTime(currentTime); break; case READER_IDLE: idleInfo.setLastReadIdleTime(currentTime); break; } eventHandler().channelIdle(this, state); }
public AbstractNioProcessor(NioHandler eventHandler, ChannelInitializer channelInitializer) { this.eventHandler = eventHandler; this.executor = Executors.newFixedThreadPool(Constants.AVAILABLE_PROCESSOR, new NamedThreadFactory("NioProcessorExecutor", true)); this.selectorLoop = new NioSelectorLoop("AcceptSelectorLoop-I/O", this); // this.readWriteSelectorPool = new FixedNioSelectorLoopPool(Constants.AVAILABLE_PROCESSOR + 1, "Server", this); this.idleDetector = new IdleDetector(); this.channelInitializer = channelInitializer; this.idleDetector.start(); }
public void setLastWriteTime(long lastWriteTime) { idleInfo.setLastWriteTime(lastWriteTime); }
public void setLastReadTime(long lastReadTime) { idleInfo.setLastReadTime(lastReadTime); }
public void stop() { task.stop(); }
@Override public void operationComplete(Future future) throws Exception { removeChannel(((Futures.CloseFuture) future).channel()); } });
public NioChannelImpl(NioSelectorLoop selectorLoop, NioProcessor processor, SocketChannel channel, NioHandler eventHandler, NioConfig config) { this.channel = channel; this.selectorLoop = selectorLoop; this.processor = processor; this.eventHandler = eventHandler; this.id = CONN_ID.incrementAndGet(); this.idleInfo = new IdleInfo(); this.config = config; closeFuture.setChannel(this); }
@Override public void run() { thread = Thread.currentThread(); while (!stop) { long currentTime = SystemClock.now(); for (NioChannel channel : channels) { if (channel.isConnected()) { idleCheck0((NioChannelImpl) channel, currentTime); } } try { Thread.sleep(1000L); } catch (InterruptedException ignored) { } } }
idleDetector.addChannel(channel); connectFuture.setSuccess(true); connectFuture.setChannel(channel);