java.nio.channels.SelectableChannel#isRegistered()源码实例Demo

下面列出了java.nio.channels.SelectableChannel#isRegistered() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: WindowsSelectorImpl.java
protected void implDereg(SelectionKeyImpl ski) throws IOException{
    int i = ski.getIndex();
    assert (i >= 0);
    synchronized (closeLock) {
        if (i != totalChannels - 1) {
            // Copy end one over it
            SelectionKeyImpl endChannel = channelArray[totalChannels-1];
            channelArray[i] = endChannel;
            endChannel.setIndex(i);
            pollWrapper.replaceEntry(pollWrapper, totalChannels - 1,
                                                            pollWrapper, i);
        }
        ski.setIndex(-1);
    }
    channelArray[totalChannels - 1] = null;
    totalChannels--;
    if ( totalChannels != 1 && totalChannels % MAX_SELECTABLE_FDS == 1) {
        totalChannels--;
        threadsCount--; // The last thread has become redundant.
    }
    fdMap.remove(ski); // Remove the key from fdMap, keys and selectedKeys
    keys.remove(ski);
    selectedKeys.remove(ski);
    deregister(ski);
    SelectableChannel selch = ski.channel();
    if (!selch.isOpen() && !selch.isRegistered())
        ((SelChImpl)selch).kill();
}
 
源代码2 项目: TencentKona-8   文件: WindowsSelectorImpl.java
protected void implClose() throws IOException {
    synchronized (closeLock) {
        if (channelArray != null) {
            if (pollWrapper != null) {
                // prevent further wakeup
                synchronized (interruptLock) {
                    interruptTriggered = true;
                }
                wakeupPipe.sink().close();
                wakeupPipe.source().close();
                for(int i = 1; i < totalChannels; i++) { // Deregister channels
                    if (i % MAX_SELECTABLE_FDS != 0) { // skip wakeupEvent
                        deregister(channelArray[i]);
                        SelectableChannel selch = channelArray[i].channel();
                        if (!selch.isOpen() && !selch.isRegistered())
                            ((SelChImpl)selch).kill();
                    }
                }
                pollWrapper.free();
                pollWrapper = null;
                selectedKeys = null;
                channelArray = null;
                // Make all remaining helper threads exit
                for (SelectThread t: threads)
                     t.makeZombie();
                startLock.startThreads();
            }
        }
    }
}
 
源代码3 项目: TencentKona-8   文件: WindowsSelectorImpl.java
protected void implDereg(SelectionKeyImpl ski) throws IOException{
    int i = ski.getIndex();
    assert (i >= 0);
    synchronized (closeLock) {
        if (i != totalChannels - 1) {
            // Copy end one over it
            SelectionKeyImpl endChannel = channelArray[totalChannels-1];
            channelArray[i] = endChannel;
            endChannel.setIndex(i);
            pollWrapper.replaceEntry(pollWrapper, totalChannels - 1,
                                                            pollWrapper, i);
        }
        ski.setIndex(-1);
    }
    channelArray[totalChannels - 1] = null;
    totalChannels--;
    if ( totalChannels != 1 && totalChannels % MAX_SELECTABLE_FDS == 1) {
        totalChannels--;
        threadsCount--; // The last thread has become redundant.
    }
    fdMap.remove(ski); // Remove the key from fdMap, keys and selectedKeys
    keys.remove(ski);
    selectedKeys.remove(ski);
    deregister(ski);
    SelectableChannel selch = ski.channel();
    if (!selch.isOpen() && !selch.isRegistered())
        ((SelChImpl)selch).kill();
}
 
源代码4 项目: jdk8u60   文件: WindowsSelectorImpl.java
protected void implClose() throws IOException {
    synchronized (closeLock) {
        if (channelArray != null) {
            if (pollWrapper != null) {
                // prevent further wakeup
                synchronized (interruptLock) {
                    interruptTriggered = true;
                }
                wakeupPipe.sink().close();
                wakeupPipe.source().close();
                for(int i = 1; i < totalChannels; i++) { // Deregister channels
                    if (i % MAX_SELECTABLE_FDS != 0) { // skip wakeupEvent
                        deregister(channelArray[i]);
                        SelectableChannel selch = channelArray[i].channel();
                        if (!selch.isOpen() && !selch.isRegistered())
                            ((SelChImpl)selch).kill();
                    }
                }
                pollWrapper.free();
                pollWrapper = null;
                selectedKeys = null;
                channelArray = null;
                // Make all remaining helper threads exit
                for (SelectThread t: threads)
                     t.makeZombie();
                startLock.startThreads();
            }
        }
    }
}
 
源代码5 项目: jdk8u60   文件: WindowsSelectorImpl.java
protected void implDereg(SelectionKeyImpl ski) throws IOException{
    int i = ski.getIndex();
    assert (i >= 0);
    synchronized (closeLock) {
        if (i != totalChannels - 1) {
            // Copy end one over it
            SelectionKeyImpl endChannel = channelArray[totalChannels-1];
            channelArray[i] = endChannel;
            endChannel.setIndex(i);
            pollWrapper.replaceEntry(pollWrapper, totalChannels - 1,
                                                            pollWrapper, i);
        }
        ski.setIndex(-1);
    }
    channelArray[totalChannels - 1] = null;
    totalChannels--;
    if ( totalChannels != 1 && totalChannels % MAX_SELECTABLE_FDS == 1) {
        totalChannels--;
        threadsCount--; // The last thread has become redundant.
    }
    fdMap.remove(ski); // Remove the key from fdMap, keys and selectedKeys
    keys.remove(ski);
    selectedKeys.remove(ski);
    deregister(ski);
    SelectableChannel selch = ski.channel();
    if (!selch.isOpen() && !selch.isRegistered())
        ((SelChImpl)selch).kill();
}
 
源代码6 项目: openjdk-jdk8u   文件: WindowsSelectorImpl.java
protected void implClose() throws IOException {
    synchronized (closeLock) {
        if (channelArray != null) {
            if (pollWrapper != null) {
                // prevent further wakeup
                synchronized (interruptLock) {
                    interruptTriggered = true;
                }
                wakeupPipe.sink().close();
                wakeupPipe.source().close();
                for(int i = 1; i < totalChannels; i++) { // Deregister channels
                    if (i % MAX_SELECTABLE_FDS != 0) { // skip wakeupEvent
                        deregister(channelArray[i]);
                        SelectableChannel selch = channelArray[i].channel();
                        if (!selch.isOpen() && !selch.isRegistered())
                            ((SelChImpl)selch).kill();
                    }
                }
                pollWrapper.free();
                pollWrapper = null;
                selectedKeys = null;
                channelArray = null;
                // Make all remaining helper threads exit
                for (SelectThread t: threads)
                     t.makeZombie();
                startLock.startThreads();
                subSelector.freeFDSetBuffer();
            }
        }
    }
}
 
源代码7 项目: openjdk-jdk8u   文件: WindowsSelectorImpl.java
protected void implDereg(SelectionKeyImpl ski) throws IOException{
    int i = ski.getIndex();
    assert (i >= 0);
    synchronized (closeLock) {
        if (i != totalChannels - 1) {
            // Copy end one over it
            SelectionKeyImpl endChannel = channelArray[totalChannels-1];
            channelArray[i] = endChannel;
            endChannel.setIndex(i);
            pollWrapper.replaceEntry(pollWrapper, totalChannels - 1,
                                                            pollWrapper, i);
        }
        ski.setIndex(-1);
    }
    channelArray[totalChannels - 1] = null;
    totalChannels--;
    if ( totalChannels != 1 && totalChannels % MAX_SELECTABLE_FDS == 1) {
        totalChannels--;
        threadsCount--; // The last thread has become redundant.
    }
    fdMap.remove(ski); // Remove the key from fdMap, keys and selectedKeys
    keys.remove(ski);
    selectedKeys.remove(ski);
    deregister(ski);
    SelectableChannel selch = ski.channel();
    if (!selch.isOpen() && !selch.isRegistered())
        ((SelChImpl)selch).kill();
}
 
源代码8 项目: jdk8u_jdk   文件: WindowsSelectorImpl.java
protected void implClose() throws IOException {
    synchronized (closeLock) {
        if (channelArray != null) {
            if (pollWrapper != null) {
                // prevent further wakeup
                synchronized (interruptLock) {
                    interruptTriggered = true;
                }
                wakeupPipe.sink().close();
                wakeupPipe.source().close();
                for(int i = 1; i < totalChannels; i++) { // Deregister channels
                    if (i % MAX_SELECTABLE_FDS != 0) { // skip wakeupEvent
                        deregister(channelArray[i]);
                        SelectableChannel selch = channelArray[i].channel();
                        if (!selch.isOpen() && !selch.isRegistered())
                            ((SelChImpl)selch).kill();
                    }
                }
                pollWrapper.free();
                pollWrapper = null;
                selectedKeys = null;
                channelArray = null;
                // Make all remaining helper threads exit
                for (SelectThread t: threads)
                     t.makeZombie();
                startLock.startThreads();
                subSelector.freeFDSetBuffer();
            }
        }
    }
}
 
源代码9 项目: jdk8u_jdk   文件: WindowsSelectorImpl.java
protected void implDereg(SelectionKeyImpl ski) throws IOException{
    int i = ski.getIndex();
    assert (i >= 0);
    synchronized (closeLock) {
        if (i != totalChannels - 1) {
            // Copy end one over it
            SelectionKeyImpl endChannel = channelArray[totalChannels-1];
            channelArray[i] = endChannel;
            endChannel.setIndex(i);
            pollWrapper.replaceEntry(pollWrapper, totalChannels - 1,
                                                            pollWrapper, i);
        }
        ski.setIndex(-1);
    }
    channelArray[totalChannels - 1] = null;
    totalChannels--;
    if ( totalChannels != 1 && totalChannels % MAX_SELECTABLE_FDS == 1) {
        totalChannels--;
        threadsCount--; // The last thread has become redundant.
    }
    fdMap.remove(ski); // Remove the key from fdMap, keys and selectedKeys
    keys.remove(ski);
    selectedKeys.remove(ski);
    deregister(ski);
    SelectableChannel selch = ski.channel();
    if (!selch.isOpen() && !selch.isRegistered())
        ((SelChImpl)selch).kill();
}
 
源代码10 项目: openjdk-jdk9   文件: WindowsSelectorImpl.java
protected void implClose() throws IOException {
    synchronized (closeLock) {
        if (channelArray != null) {
            if (pollWrapper != null) {
                // prevent further wakeup
                synchronized (interruptLock) {
                    interruptTriggered = true;
                }
                wakeupPipe.sink().close();
                wakeupPipe.source().close();
                for(int i = 1; i < totalChannels; i++) { // Deregister channels
                    if (i % MAX_SELECTABLE_FDS != 0) { // skip wakeupEvent
                        deregister(channelArray[i]);
                        SelectableChannel selch = channelArray[i].channel();
                        if (!selch.isOpen() && !selch.isRegistered())
                            ((SelChImpl)selch).kill();
                    }
                }
                pollWrapper.free();
                pollWrapper = null;
                selectedKeys = null;
                channelArray = null;
                // Make all remaining helper threads exit
                for (SelectThread t: threads)
                     t.makeZombie();
                startLock.startThreads();
            }
        }
    }
}
 
源代码11 项目: jdk8u-jdk   文件: WindowsSelectorImpl.java
protected void implClose() throws IOException {
    synchronized (closeLock) {
        if (channelArray != null) {
            if (pollWrapper != null) {
                // prevent further wakeup
                synchronized (interruptLock) {
                    interruptTriggered = true;
                }
                wakeupPipe.sink().close();
                wakeupPipe.source().close();
                for(int i = 1; i < totalChannels; i++) { // Deregister channels
                    if (i % MAX_SELECTABLE_FDS != 0) { // skip wakeupEvent
                        deregister(channelArray[i]);
                        SelectableChannel selch = channelArray[i].channel();
                        if (!selch.isOpen() && !selch.isRegistered())
                            ((SelChImpl)selch).kill();
                    }
                }
                pollWrapper.free();
                pollWrapper = null;
                selectedKeys = null;
                channelArray = null;
                // Make all remaining helper threads exit
                for (SelectThread t: threads)
                     t.makeZombie();
                startLock.startThreads();
            }
        }
    }
}
 
源代码12 项目: jdk8u-jdk   文件: WindowsSelectorImpl.java
protected void implDereg(SelectionKeyImpl ski) throws IOException{
    int i = ski.getIndex();
    assert (i >= 0);
    synchronized (closeLock) {
        if (i != totalChannels - 1) {
            // Copy end one over it
            SelectionKeyImpl endChannel = channelArray[totalChannels-1];
            channelArray[i] = endChannel;
            endChannel.setIndex(i);
            pollWrapper.replaceEntry(pollWrapper, totalChannels - 1,
                                                            pollWrapper, i);
        }
        ski.setIndex(-1);
    }
    channelArray[totalChannels - 1] = null;
    totalChannels--;
    if ( totalChannels != 1 && totalChannels % MAX_SELECTABLE_FDS == 1) {
        totalChannels--;
        threadsCount--; // The last thread has become redundant.
    }
    fdMap.remove(ski); // Remove the key from fdMap, keys and selectedKeys
    keys.remove(ski);
    selectedKeys.remove(ski);
    deregister(ski);
    SelectableChannel selch = ski.channel();
    if (!selch.isOpen() && !selch.isRegistered())
        ((SelChImpl)selch).kill();
}
 
源代码13 项目: hottub   文件: WindowsSelectorImpl.java
protected void implClose() throws IOException {
    synchronized (closeLock) {
        if (channelArray != null) {
            if (pollWrapper != null) {
                // prevent further wakeup
                synchronized (interruptLock) {
                    interruptTriggered = true;
                }
                wakeupPipe.sink().close();
                wakeupPipe.source().close();
                for(int i = 1; i < totalChannels; i++) { // Deregister channels
                    if (i % MAX_SELECTABLE_FDS != 0) { // skip wakeupEvent
                        deregister(channelArray[i]);
                        SelectableChannel selch = channelArray[i].channel();
                        if (!selch.isOpen() && !selch.isRegistered())
                            ((SelChImpl)selch).kill();
                    }
                }
                pollWrapper.free();
                pollWrapper = null;
                selectedKeys = null;
                channelArray = null;
                // Make all remaining helper threads exit
                for (SelectThread t: threads)
                     t.makeZombie();
                startLock.startThreads();
            }
        }
    }
}
 
源代码14 项目: hottub   文件: WindowsSelectorImpl.java
protected void implDereg(SelectionKeyImpl ski) throws IOException{
    int i = ski.getIndex();
    assert (i >= 0);
    synchronized (closeLock) {
        if (i != totalChannels - 1) {
            // Copy end one over it
            SelectionKeyImpl endChannel = channelArray[totalChannels-1];
            channelArray[i] = endChannel;
            endChannel.setIndex(i);
            pollWrapper.replaceEntry(pollWrapper, totalChannels - 1,
                                                            pollWrapper, i);
        }
        ski.setIndex(-1);
    }
    channelArray[totalChannels - 1] = null;
    totalChannels--;
    if ( totalChannels != 1 && totalChannels % MAX_SELECTABLE_FDS == 1) {
        totalChannels--;
        threadsCount--; // The last thread has become redundant.
    }
    fdMap.remove(ski); // Remove the key from fdMap, keys and selectedKeys
    keys.remove(ski);
    selectedKeys.remove(ski);
    deregister(ski);
    SelectableChannel selch = ski.channel();
    if (!selch.isOpen() && !selch.isRegistered())
        ((SelChImpl)selch).kill();
}
 
源代码15 项目: openjdk-8-source   文件: WindowsSelectorImpl.java
protected void implClose() throws IOException {
    synchronized (closeLock) {
        if (channelArray != null) {
            if (pollWrapper != null) {
                // prevent further wakeup
                synchronized (interruptLock) {
                    interruptTriggered = true;
                }
                wakeupPipe.sink().close();
                wakeupPipe.source().close();
                for(int i = 1; i < totalChannels; i++) { // Deregister channels
                    if (i % MAX_SELECTABLE_FDS != 0) { // skip wakeupEvent
                        deregister(channelArray[i]);
                        SelectableChannel selch = channelArray[i].channel();
                        if (!selch.isOpen() && !selch.isRegistered())
                            ((SelChImpl)selch).kill();
                    }
                }
                pollWrapper.free();
                pollWrapper = null;
                selectedKeys = null;
                channelArray = null;
                // Make all remaining helper threads exit
                for (SelectThread t: threads)
                     t.makeZombie();
                startLock.startThreads();
            }
        }
    }
}
 
源代码16 项目: jdk8u-dev-jdk   文件: WindowsSelectorImpl.java
protected void implDereg(SelectionKeyImpl ski) throws IOException{
    int i = ski.getIndex();
    assert (i >= 0);
    synchronized (closeLock) {
        if (i != totalChannels - 1) {
            // Copy end one over it
            SelectionKeyImpl endChannel = channelArray[totalChannels-1];
            channelArray[i] = endChannel;
            endChannel.setIndex(i);
            pollWrapper.replaceEntry(pollWrapper, totalChannels - 1,
                                                            pollWrapper, i);
        }
        ski.setIndex(-1);
    }
    channelArray[totalChannels - 1] = null;
    totalChannels--;
    if ( totalChannels != 1 && totalChannels % MAX_SELECTABLE_FDS == 1) {
        totalChannels--;
        threadsCount--; // The last thread has become redundant.
    }
    fdMap.remove(ski); // Remove the key from fdMap, keys and selectedKeys
    keys.remove(ski);
    selectedKeys.remove(ski);
    deregister(ski);
    SelectableChannel selch = ski.channel();
    if (!selch.isOpen() && !selch.isRegistered())
        ((SelChImpl)selch).kill();
}
 
源代码17 项目: openjdk-8   文件: WindowsSelectorImpl.java
protected void implDereg(SelectionKeyImpl ski) throws IOException{
    int i = ski.getIndex();
    assert (i >= 0);
    synchronized (closeLock) {
        if (i != totalChannels - 1) {
            // Copy end one over it
            SelectionKeyImpl endChannel = channelArray[totalChannels-1];
            channelArray[i] = endChannel;
            endChannel.setIndex(i);
            pollWrapper.replaceEntry(pollWrapper, totalChannels - 1,
                                                            pollWrapper, i);
        }
        ski.setIndex(-1);
    }
    channelArray[totalChannels - 1] = null;
    totalChannels--;
    if ( totalChannels != 1 && totalChannels % MAX_SELECTABLE_FDS == 1) {
        totalChannels--;
        threadsCount--; // The last thread has become redundant.
    }
    fdMap.remove(ski); // Remove the key from fdMap, keys and selectedKeys
    keys.remove(ski);
    selectedKeys.remove(ski);
    deregister(ski);
    SelectableChannel selch = ski.channel();
    if (!selch.isOpen() && !selch.isRegistered())
        ((SelChImpl)selch).kill();
}
 
源代码18 项目: IoTgo_Android_App   文件: SelectChannelEndPoint.java
/**
 * Synchronize the interestOps with the actual key. Call is scheduled by a call to updateKey
 */
void doUpdateKey()
{
    synchronized (this)
    {
        if (getChannel().isOpen())
        {
            if (_interestOps>0)
            {
                if (_key==null || !_key.isValid())
                {
                    SelectableChannel sc = (SelectableChannel)getChannel();
                    if (sc.isRegistered())
                    {
                        updateKey();
                    }
                    else
                    {
                        try
                        {
                            _key=((SelectableChannel)getChannel()).register(_selectSet.getSelector(),_interestOps,this);
                        }
                        catch (Exception e)
                        {
                            LOG.ignore(e);
                            if (_key!=null && _key.isValid())
                            {
                                _key.cancel();
                            }

                            if (_open)
                            {
                                _selectSet.destroyEndPoint(this);
                            }
                            _open=false;
                            _key = null;
                        }
                    }
                }
                else
                {
                    _key.interestOps(_interestOps);
                }
            }
            else
            {
                if (_key!=null && _key.isValid())
                    _key.interestOps(0);
                else
                    _key=null;
            }
        }
        else
        {
            if (_key!=null && _key.isValid())
                _key.cancel();

            if (_open)
            {
                _open=false;
                _selectSet.destroyEndPoint(this);
            }
            _key = null;
        }
    }
}
 
源代码19 项目: IoTgo_Android_App   文件: SelectChannelEndPoint.java
/**
 * Synchronize the interestOps with the actual key. Call is scheduled by a call to updateKey
 */
void doUpdateKey()
{
    synchronized (this)
    {
        if (getChannel().isOpen())
        {
            if (_interestOps>0)
            {
                if (_key==null || !_key.isValid())
                {
                    SelectableChannel sc = (SelectableChannel)getChannel();
                    if (sc.isRegistered())
                    {
                        updateKey();
                    }
                    else
                    {
                        try
                        {
                            _key=((SelectableChannel)getChannel()).register(_selectSet.getSelector(),_interestOps,this);
                        }
                        catch (Exception e)
                        {
                            LOG.ignore(e);
                            if (_key!=null && _key.isValid())
                            {
                                _key.cancel();
                            }

                            if (_open)
                            {
                                _selectSet.destroyEndPoint(this);
                            }
                            _open=false;
                            _key = null;
                        }
                    }
                }
                else
                {
                    _key.interestOps(_interestOps);
                }
            }
            else
            {
                if (_key!=null && _key.isValid())
                    _key.interestOps(0);
                else
                    _key=null;
            }
        }
        else
        {
            if (_key!=null && _key.isValid())
                _key.cancel();

            if (_open)
            {
                _open=false;
                _selectSet.destroyEndPoint(this);
            }
            _key = null;
        }
    }
}
 
源代码20 项目: jolie   文件: CommCore.java
protected boolean isSelecting( SelectableStreamingCommChannel channel ) {
	SelectableChannel c = channel.selectableChannel();
	return c != null && c.isRegistered();
}