case OPEN: if (Boolean.FALSE.equals(value)) { channel.worker.close(channel, future); case CONNECTED: if (value == null) { channel.worker.close(channel, future); channel.worker.setInterestOps(channel, future, ((Integer) value).intValue()); break; boolean offered = channel.writeBufferQueue.offer(event); assert offered; channel.worker.writeFromUserCode(channel);
public void executeInIoThread(Runnable task) { executeInIoThread(task, false); }
void writeFromUserCode(final AbstractNioChannel<?> channel) { if (!channel.isConnected()) { cleanUpWriteBuffer(channel); return; } if (scheduleWriteIfNecessary(channel)) { return; } // From here, we are sure Thread.currentThread() == workerThread. if (channel.writeSuspended) { return; } if (channel.inWriteNowLoop) { return; } write0(channel); }
int readyOps = k.readyOps(); if ((readyOps & SelectionKey.OP_READ) != 0 || readyOps == 0) { if (!read(k)) { writeFromSelectorLoop(k); close(k); if (cleanUpCancelledKeys()) { break; // break the loop to avoid ConcurrentModificationException
@Override protected void close(SelectionKey k) { AbstractNioChannel<?> ch = (AbstractNioChannel<?>) k.attachment(); close(ch, succeededFuture(ch)); }
boolean addOpWrite = false; boolean removeOpWrite = false; boolean iothread = isIoThread(channel); setOpWrite(channel); } else if (removeOpWrite) { clearOpWrite(channel); close(channel, succeededFuture(channel));
case OPEN: if (Boolean.FALSE.equals(value)) { childChannel.worker.close(childChannel, childFuture); ChannelFuture parentFuture = parentMessageEvent.getFuture(); parentFuture.addListener(f -> { childChannel.getWorker().executeInIoThread(() -> { if (f.isSuccess()) { childFuture.setSuccess(); boolean offered = parentChannel.writeBufferQueue.offer(parentMessageEvent); assert offered; parentChannel.worker.writeFromUserCode(parentChannel);
void writeFromTaskLoop(AbstractNioChannel<?> ch) { if (!ch.writeSuspended) { write0(ch); } }
protected void close(AbstractNioChannel<?> channel, ChannelFuture future) { boolean connected = channel.isConnected(); boolean bound = channel.isBound(); boolean iothread = isIoThread(channel); increaseCancelledKeys(); cleanUpWriteBuffer(channel); if (iothread) { fireChannelClosed(channel);
public void setWorker(AbstractNioWorker newWorker) { if (newWorker == null) { if (worker == null) { throw new IllegalStateException("Cannot deregister more than once without re-register"); } worker.deregister(this); } else { worker = newWorker; worker.register(this); } }
@Override public void run() { super.run(); recvBufferPool.releaseExternalResources(); } }
private static void connect(SelectionKey k) throws IOException { NioClientSocketChannel ch = (NioClientSocketChannel) k.attachment(); try { if (ch.channel.finishConnect()) { k.cancel(); if (ch.timoutTimer != null) { ch.timoutTimer.cancel(); } ch.worker.register(ch, ch.connectFuture); } } catch (ConnectException e) { ConnectException newE = new ConnectException(e.getMessage() + ": " + ch.requestedRemoteAddress); newE.setStackTrace(e.getStackTrace()); throw newE; } }
public void run() { setInterestOps(channel, future, interestOps); } });
@Override void writeFromUserCode(final AbstractNioChannel<?> channel) { if (channel instanceof NioDatagramChannel) { writeFromUserCodeUdp(channel); } else { super.writeFromUserCode(channel); } }
@Override protected void close(SelectionKey k) { NioClientSocketChannel ch = (NioClientSocketChannel) k.attachment(); ch.worker.close(ch, succeededFuture(ch)); }
int readyOps = k.readyOps(); if ((readyOps & SelectionKey.OP_READ) != 0 || readyOps == 0) { if (!read(k)) { writeFromSelectorLoop(k); close(k); if (cleanUpCancelledKeys()) { break; // break the loop to avoid ConcurrentModificationException
boolean addOpWrite = false; boolean removeOpWrite = false; boolean iothread = isIoThread(channel); setOpWrite(channel); } else if (removeOpWrite) { clearOpWrite(channel); close(channel, succeededFuture(channel));
public void writeFromUserCode(final AbstractNioChannel<?> channel) { if (!channel.isConnected()) { cleanUpWriteBuffer(channel); return; } if (scheduleWriteIfNecessary(channel)) { return; } // From here, we are sure Thread.currentThread() == workerThread. if (channel.writeSuspended) { return; } if (channel.inWriteNowLoop) { return; } write0(channel); }
void writeFromSelectorLoop(final SelectionKey k) { AbstractNioChannel<?> ch = (AbstractNioChannel<?>) k.attachment(); ch.writeSuspended = false; write0(ch); }