@Override public SelectionKey interestOps(int operations) { checkValid(); if ((operations & ~(channel().validOps())) != 0) { throw new IllegalArgumentException(); } synchronized (selector.keysLock) { interestOps = operations; } return this; }
/** * Registers an arbitrary {@link SelectableChannel}, not necessarily created by Netty, to the {@link Selector} * of this event loop. Once the specified {@link SelectableChannel} is registered, the specified {@code task} will * be executed by this event loop when the {@link SelectableChannel} is ready. */ public void register(final SelectableChannel ch, final int interestOps, final NioTask<?> task) { if (ch == null) { throw new NullPointerException("ch"); } if (interestOps == 0) { throw new IllegalArgumentException("interestOps must be non-zero."); } if ((interestOps & ~ch.validOps()) != 0) { throw new IllegalArgumentException( "invalid interestOps: " + interestOps + "(validOps: " + ch.validOps() + ')'); } if (task == null) { throw new NullPointerException("task"); } if (isShutdown()) { throw new IllegalStateException("event loop shut down"); } try { ch.register(selector, interestOps, task); } catch (Exception e) { throw new EventLoopException("failed to register a channel", e); } }
(SelectableChannel)scatteringByteChannel; if ((readSelectableChannel.validOps() & SelectionKey.OP_READ) == 0) { throw new IllegalArgumentException( "Scattering byte channel is not valid for reading"); (SelectableChannel)gatheringByteChannel; if ((writeSelectableChannel.validOps() & SelectionKey.OP_WRITE) == 0) { throw new IllegalArgumentException( "Gathering byte channel is not valid for writing");
private static SelectionKey registerSelect(Selector selector, ChannelFD attachment, SelectableChannel channel, int ops) throws IOException { channel.configureBlocking(false); // FIXME: I'm not sure we ever set it back to old blocking mode int real_ops = channel.validOps() & ops; SelectionKey key = channel.keyFor(selector); List<ChannelFD> attachmentSet; if (key != null) { key.interestOps(key.interestOps() | real_ops); attachmentSet = (List<ChannelFD>)key.attachment(); if (!attachmentSet.contains(attachment)) attachmentSet.add(attachment); return key; } else { attachmentSet = new ArrayList(1); attachmentSet.add(attachment); return channel.register(selector, real_ops, attachmentSet); } }
private static SelectionKey registerSelect(Selector selector, ChannelFD attachment, SelectableChannel channel, int ops) throws IOException { channel.configureBlocking(false); // FIXME: I'm not sure we ever set it back to old blocking mode int real_ops = channel.validOps() & ops; SelectionKey key = channel.keyFor(selector); List<ChannelFD> attachmentSet; if (key != null) { key.interestOps(key.interestOps() | real_ops); attachmentSet = (List<ChannelFD>)key.attachment(); if (!attachmentSet.contains(attachment)) attachmentSet.add(attachment); return key; } else { attachmentSet = new ArrayList(1); attachmentSet.add(attachment); return channel.register(selector, real_ops, attachmentSet); } }
@SuppressWarnings("unchecked") private static boolean registerSelect(Selector selector, Map<Character,Integer> obj, SelectableChannel channel, int ops) throws IOException { channel.configureBlocking(false); int real_ops = channel.validOps() & ops; SelectionKey key = channel.keyFor(selector); if (key == null) { Map<Character,Integer> attachment = new HashMap<Character,Integer> (1); attachment.putAll(obj); channel.register(selector, real_ops, attachment ); } else { key.interestOps(key.interestOps() | real_ops); Map<Character,Integer> att = (Map<Character,Integer>)key.attachment(); att.putAll(obj); key.attach(att); } return true; }
@Override public SelectionKey interestOps(int operations) { checkValid(); if ((operations & ~(channel().validOps())) != 0) { throw new IllegalArgumentException(); } synchronized (selector.keysLock) { interestOps = operations; } return this; }
@Override public SelectionKey interestOps(int operations) { checkValid(); if ((operations & ~(channel().validOps())) != 0) { throw new IllegalArgumentException(); } synchronized (selector.keysLock) { interestOps = operations; } return this; }
@SuppressWarnings("unchecked") private static boolean registerSelect(Selector selector, Map<Character,Integer> obj, SelectableChannel channel, int ops) throws IOException { channel.configureBlocking(false); int real_ops = channel.validOps() & ops; SelectionKey key = channel.keyFor(selector); if (key == null) { Map<Character,Integer> attachment = new HashMap<Character,Integer> (1); attachment.putAll(obj); channel.register(selector, real_ops, attachment ); } else { key.interestOps(key.interestOps() | real_ops); Map<Character,Integer> att = (Map<Character,Integer>)key.attachment(); att.putAll(obj); key.attach(att); } return true; }
@Override public SelectionKey interestOps(int operations) { checkValid(); if ((operations & ~(channel().validOps())) != 0) { throw new IllegalArgumentException(); } synchronized (selector.keysLock) { interestOps = operations; } return this; }
@Override public SelectionKey interestOps(int operations) { checkValid(); if ((operations & ~(channel().validOps())) != 0) { throw new IllegalArgumentException(); } synchronized (selector.keysLock) { interestOps = operations; } return this; }
@Override public SelectionKey interestOps(int operations) { checkValid(); if ((operations & ~(channel().validOps())) != 0) { throw new IllegalArgumentException(); } synchronized (selector.keysLock) { interestOps = operations; } return this; }
@Override public SelectionKey interestOps(int operations) { checkValid(); if ((operations & ~(channel().validOps())) != 0) { throw new IllegalArgumentException(); } synchronized (selector.keysLock) { interestOps = operations; } return this; }
@SuppressWarnings("unchecked") private static boolean registerSelect(ThreadContext context, Selector selector, Map<Character,Integer> obj, RubyIO ioObj, int ops) throws IOException { Channel channel = ioObj.getChannel(); if (channel == null || !(channel instanceof SelectableChannel)) { return false; } ((SelectableChannel) channel).configureBlocking(false); int real_ops = ((SelectableChannel) channel).validOps() & ops; SelectionKey key = ((SelectableChannel) channel).keyFor(selector); if (key == null) { Map<Character,Integer> attachment = new HashMap<Character,Integer> (1); attachment.putAll(obj); ((SelectableChannel) channel).register(selector, real_ops, attachment ); } else { key.interestOps(key.interestOps() | real_ops); Map<Character,Integer> att = (Map<Character,Integer>)key.attachment(); att.putAll(obj); key.attach(att); } return true; }
@SuppressWarnings("unchecked") private static boolean registerSelect(ThreadContext context, Selector selector, Map<Character,Integer> obj, RubyIO ioObj, int ops) throws IOException { Channel channel = ioObj.getChannel(); if (channel == null || !(channel instanceof SelectableChannel)) { return false; } ((SelectableChannel) channel).configureBlocking(false); int real_ops = ((SelectableChannel) channel).validOps() & ops; SelectionKey key = ((SelectableChannel) channel).keyFor(selector); if (key == null) { Map<Character,Integer> attachment = new HashMap<Character,Integer> (1); attachment.putAll(obj); ((SelectableChannel) channel).register(selector, real_ops, attachment ); } else { key.interestOps(key.interestOps() | real_ops); Map<Character,Integer> att = (Map<Character,Integer>)key.attachment(); att.putAll(obj); key.attach(att); } return true; }
public void registerPeer(Peer peer, ISocket socket) { try { if ((socket.getReadableChannel().validOps() & SelectionKey.OP_WRITE) != 0) { socket.getReadableChannel().register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE, peer); } else { socket.getReadableChannel().register(selector, SelectionKey.OP_READ, peer); socket.getWritableChannel().register(selector, SelectionKey.OP_WRITE, peer); } } catch (ClosedChannelException e) { throw new IllegalStateException("Channel mustn't be closed to be handled.", e); } }
private static boolean registerSelect(ThreadContext context, Selector selector, IRubyObject obj, RubyIO ioObj, int ops) throws IOException { Channel channel = ioObj.getChannel(); if (channel == null || !(channel instanceof SelectableChannel)) { return false; } ((SelectableChannel) channel).configureBlocking(false); int real_ops = ((SelectableChannel) channel).validOps() & ops; SelectionKey key = ((SelectableChannel) channel).keyFor(selector); if (key == null) { ((SelectableChannel) channel).register(selector, real_ops, obj); } else { key.interestOps(key.interestOps()|real_ops); } return true; }