/** * 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; }
/** * Removes cancelled keys from the key set and selected key set, and * deregisters 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; }
@TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "deregister", args = {AbstractSelectionKey.class} ) public void test_deregister() throws Exception { MockSelectorProvider prov = new MockSelectorProvider(); AbstractSelector acceptSelector = prov.openSelector(); SocketChannel sc = prov.openSocketChannel(); sc.configureBlocking(false); SelectionKey acceptKey = sc.register(acceptSelector, SelectionKey.OP_READ, null); assertTrue(sc.isRegistered()); assertNotNull(acceptKey); ((MockAbstractSelector)acceptSelector).mockDeregister( (MockAbstractSelector.MockSelectionKey)acceptKey); assertFalse(sc.isRegistered()); }
/** * @see java.nio.channels.spi.AbstractSelector#implCloseSelector() */ @Override protected void implCloseSelector() throws IOException { wakeup(); synchronized (this) { synchronized (unmodifiableKeys) { synchronized (selectedKeys) { sink.close(); source.close(); doCancel(); for (SelectionKey sk : mutableKeys) { deregister((AbstractSelectionKey) sk); } } } } }
@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 void implCloseSelector() throws IOException { wakeup(); synchronized (this) { synchronized (unmodifiableKeys) { synchronized (selectedKeys) { wakeupPipe.sink().close(); wakeupPipe.source().close(); doCancel(); for (SelectionKey sk : mutableKeys) { deregister((AbstractSelectionKey) sk); } } } } }
protected void implCloseSelector() throws IOException { synchronized (this) { synchronized (keysSet) { synchronized (selectedKeys) { doCancel(); for (int c = 0; c < keysCount; c++) { if (keys[c] != null) { deregister((AbstractSelectionKey) keys[c]); } } wakeup(); } } } }
private void doCancel() { Set<SelectionKey> cancelledKeys = cancelledKeys(); synchronized (cancelledKeys) { if (cancelledKeys.size() > 0) { for (SelectionKey currentkey : cancelledKeys) { delKey(currentkey); deregister((AbstractSelectionKey) currentkey); selectedKeys.remove(currentkey); } } cancelledKeys.clear(); limitCapacity(); } }
private void doCancel() { Set<SelectionKey> cancelledKeys = cancelledKeys(); synchronized (cancelledKeys) { if (cancelledKeys.size() > 0) { for (SelectionKey currentkey : cancelledKeys) { delKey((SelectionKeyImpl)currentkey); mutableKeys.remove(currentkey); deregister((AbstractSelectionKey) currentkey); mutableSelectedKeys.remove(currentkey); } cancelledKeys.clear(); } limitCapacity(); } }
protected void implCloseSelector() throws IOException { doCancel(); for (SelectionKey sk : keys) { deregister((AbstractSelectionKey) sk); } wakeup(); }
private void doCancel() { Set<SelectionKey> cancelledKeys = cancelledKeys(); synchronized (cancelledKeys) { if (cancelledKeys.size() > 0) { for (SelectionKey currentkey : cancelledKeys) { deregister((AbstractSelectionKey) currentkey); keys.remove(currentkey); selectedKeys.remove(currentkey); } } cancelledKeys.clear(); } }
public void mockDeregister(AbstractSelectionKey key) { super.deregister(key); }
private int selectInternal(long timeout) throws IOException { closeCheck(); synchronized (this) { synchronized (unmodifiableKeys) { synchronized (selectedKeys) { doCancel(); boolean isBlock = (SELECT_NOW != timeout); prepareChannels(); boolean success; try { if (isBlock) { begin(); } success = Platform.getNetworkSystem().select( readableFDs, writableFDs, readableKeysCount, writableKeysCount, timeout, flags); } finally { if (isBlock) { end(); } } int selected = success ? processSelectResult() : 0; Arrays.fill(flags, 0); Set<SelectionKey> cancelledKeys = cancelledKeys(); synchronized (cancelledKeys) { if (cancelledKeys.size() > 0) { for (SelectionKey currentkey : cancelledKeys) { delKey((SelectionKeyImpl)currentkey); mutableKeys.remove(currentkey); deregister((AbstractSelectionKey) currentkey); if (mutableSelectedKeys.remove(currentkey)) { selected--; } } cancelledKeys.clear(); } limitCapacity(); } return selected; } } } }
protected void mockDeregister(AbstractSelectionKey key) { super.deregister(key); }