public AbstractSelector openSelector() throws IOException { return new SelectorImpl(this); }
private int selectInternal(long timeout) throws IOException { checkClosed(); synchronized (this) { synchronized (unmodifiableKeys) { synchronized (selectedKeys) { doCancel(); boolean isBlocking = (timeout != 0); synchronized (keysLock) { preparePollFds(); begin(); end(); int readyCount = (rc > 0) ? processPollFds() : 0; readyCount -= doCancel(); return readyCount;
/** * Removes cancelled keys from the key set and selected key set, and * unregisters the corresponding channels. Returns the number of keys * removed from the selected key set. */ private int doCancel() { int deselected = 0; Set<SelectionKey> cancelledKeys = cancelledKeys(); synchronized (cancelledKeys) { if (cancelledKeys.size() > 0) { for (SelectionKey currentKey : cancelledKeys) { mutableKeys.remove(currentKey); deregister((AbstractSelectionKey) currentKey); if (mutableSelectedKeys.remove(currentKey)) { deselected++; } } cancelledKeys.clear(); } } return deselected; }
@Override protected void implCloseSelector() throws IOException { wakeup(); synchronized (this) { synchronized (unmodifiableKeys) { synchronized (selectedKeys) { IoUtils.close(wakeupIn); IoUtils.close(wakeupOut); doCancel(); for (SelectionKey sk : mutableKeys) { deregister((AbstractSelectionKey) sk); } } } } }
@Override protected SelectionKey register(AbstractSelectableChannel channel, int operations, Object attachment) { if (!provider().equals(channel.provider())) { throw new IllegalSelectorException(); } synchronized (this) { synchronized (unmodifiableKeys) { SelectionKeyImpl selectionKey = new SelectionKeyImpl(channel, operations, attachment, this); mutableKeys.add(selectionKey); ensurePollFdsCapacity(); return selectionKey; } } }
@Override public synchronized Set<SelectionKey> keys() { checkClosed(); return unmodifiableKeys; }
private void checkClosed() { if (!isOpen()) { throw new ClosedSelectorException(); } }
@Override protected void implCloseSelector() throws IOException { wakeup(); synchronized (this) { synchronized (unmodifiableKeys) { synchronized (selectedKeys) { IoUtils.close(wakeupIn); IoUtils.close(wakeupOut); doCancel(); for (SelectionKey sk : mutableKeys) { deregister((AbstractSelectionKey) sk); } } } } }
@Override protected SelectionKey register(AbstractSelectableChannel channel, int operations, Object attachment) { if (!provider().equals(channel.provider())) { throw new IllegalSelectorException(); } synchronized (this) { synchronized (unmodifiableKeys) { SelectionKeyImpl selectionKey = new SelectionKeyImpl(channel, operations, attachment, this); mutableKeys.add(selectionKey); ensurePollFdsCapacity(); return selectionKey; } } }
@Override public synchronized Set<SelectionKey> selectedKeys() { checkClosed(); return selectedKeys; }
private void checkClosed() { if (!isOpen()) { throw new ClosedSelectorException(); } }
private int selectInternal(long timeout) throws IOException { checkClosed(); synchronized (this) { synchronized (unmodifiableKeys) { synchronized (selectedKeys) { doCancel(); boolean isBlocking = (timeout != 0); synchronized (keysLock) { preparePollFds(); begin(); end(); int readyCount = (rc > 0) ? processPollFds() : 0; readyCount -= doCancel(); return readyCount;
@Override protected void implCloseSelector() throws IOException { wakeup(); synchronized (this) { synchronized (unmodifiableKeys) { synchronized (selectedKeys) { IoUtils.close(wakeupIn); IoUtils.close(wakeupOut); doCancel(); for (SelectionKey sk : mutableKeys) { deregister((AbstractSelectionKey) sk); } } } } }
@Override protected SelectionKey register(AbstractSelectableChannel channel, int operations, Object attachment) { if (!provider().equals(channel.provider())) { throw new IllegalSelectorException(); } synchronized (this) { synchronized (unmodifiableKeys) { SelectionKeyImpl selectionKey = new SelectionKeyImpl(channel, operations, attachment, this); mutableKeys.add(selectionKey); ensurePollFdsCapacity(); return selectionKey; } } }
/** * Removes cancelled keys from the key set and selected key set, and * unregisters the corresponding channels. Returns the number of keys * removed from the selected key set. */ private int doCancel() { int deselected = 0; Set<SelectionKey> cancelledKeys = cancelledKeys(); synchronized (cancelledKeys) { if (cancelledKeys.size() > 0) { for (SelectionKey currentKey : cancelledKeys) { mutableKeys.remove(currentKey); deregister((AbstractSelectionKey) currentKey); if (mutableSelectedKeys.remove(currentKey)) { deselected++; } } cancelledKeys.clear(); } } return deselected; }
@Override public synchronized Set<SelectionKey> selectedKeys() { checkClosed(); return selectedKeys; }
private void checkClosed() { if (!isOpen()) { throw new ClosedSelectorException(); } }
public AbstractSelector openSelector() throws IOException { return new SelectorImpl(this); }
private int selectInternal(long timeout) throws IOException { checkClosed(); synchronized (this) { synchronized (unmodifiableKeys) { synchronized (selectedKeys) { doCancel(); boolean isBlocking = (timeout != 0); synchronized (keysLock) { preparePollFds(); begin(); end(); int readyCount = (rc > 0) ? processPollFds() : 0; readyCount -= doCancel(); return readyCount;
@Override protected void implCloseSelector() throws IOException { wakeup(); synchronized (this) { synchronized (unmodifiableKeys) { synchronized (selectedKeys) { IoUtils.close(wakeupIn); IoUtils.close(wakeupOut); doCancel(); for (SelectionKey sk : mutableKeys) { deregister((AbstractSelectionKey) sk); } } } } }