Java 类java.nio.channels.spi.AbstractSelectionKey 实例源码

项目:j2objc    文件:SelectorImpl.java   
/**
 * 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;
}
项目:In-the-Box-Fork    文件:SelectorImpl.java   
/**
 * 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;
}
项目:In-the-Box-Fork    文件:AbstractSelectorTest.java   
@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());
}
项目:cn1    文件:SelectorImpl.java   
/**
 * @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);
                }
            }
        }
    }
}
项目:freeVM    文件:SelectorImpl.java   
/**
 * @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);
                }
            }
        }
    }
}
项目:j2objc    文件:SelectorImpl.java   
@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);
                }
            }
        }
    }
}
项目:In-the-Box-Fork    文件:SelectorImpl.java   
@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);
                }
            }
        }
    }
}
项目:cn1    文件:EpollSelectorImpl.java   
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();
            }
        }
    }
}
项目:cn1    文件:EpollSelectorImpl.java   
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();
    }
}
项目:cn1    文件:SelectorImpl.java   
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();
    }
}
项目:freeVM    文件:SelectorImpl.java   
protected void implCloseSelector() throws IOException {
    doCancel();
    for (SelectionKey sk : keys) {
        deregister((AbstractSelectionKey) sk);
    }
    wakeup();
}
项目:freeVM    文件:SelectorImpl.java   
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();
    }
}
项目:freeVM    文件:EpollSelectorImpl.java   
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();
            }
        }
    }
}
项目:freeVM    文件:EpollSelectorImpl.java   
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();
    }
}
项目:freeVM    文件:SelectorImpl.java   
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();
    }
}
项目:In-the-Box-Fork    文件:MockAbstractSelector.java   
public void mockDeregister(AbstractSelectionKey key) {
    super.deregister(key);
}
项目:cn1    文件:SelectorImpl.java   
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;
            }
        }
    }
}
项目:cn1    文件:MockAbstractSelector.java   
protected void mockDeregister(AbstractSelectionKey key) {
    super.deregister(key);
}
项目:freeVM    文件:MockAbstractSelector.java   
protected void mockDeregister(AbstractSelectionKey key) {
    super.deregister(key);
}
项目:freeVM    文件:SelectorImpl.java   
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;
            }
        }
    }
}
项目:freeVM    文件:MockAbstractSelector.java   
protected void mockDeregister(AbstractSelectionKey key) {
    super.deregister(key);
}