本文整理汇总了Java中java.nio.channels.spi.AbstractSelectionKey类的典型用法代码示例。如果您正苦于以下问题:Java AbstractSelectionKey类的具体用法?Java AbstractSelectionKey怎么用?Java AbstractSelectionKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractSelectionKey类属于java.nio.channels.spi包,在下文中一共展示了AbstractSelectionKey类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doCancel
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
/**
* 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;
}
示例2: doCancel
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
/**
* 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;
}
示例3: test_deregister
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
@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());
}
示例4: implCloseSelector
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
/**
* @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);
}
}
}
}
}
示例5: implCloseSelector
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
@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);
}
}
}
}
}
示例6: implCloseSelector
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
@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);
}
}
}
}
}
示例7: implCloseSelector
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
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();
}
}
}
}
示例8: doCancel
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
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();
}
}
示例9: doCancel
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
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();
}
}
示例10: implCloseSelector
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
protected void implCloseSelector() throws IOException {
doCancel();
for (SelectionKey sk : keys) {
deregister((AbstractSelectionKey) sk);
}
wakeup();
}
示例11: doCancel
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
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();
}
}
示例12: mockDeregister
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
public void mockDeregister(AbstractSelectionKey key) {
super.deregister(key);
}
示例13: selectInternal
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
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;
}
}
}
}
示例14: mockDeregister
import java.nio.channels.spi.AbstractSelectionKey; //导入依赖的package包/类
protected void mockDeregister(AbstractSelectionKey key) {
super.deregister(key);
}