Java Code Examples for java.nio.channels.SelectableChannel#isRegistered()

The following examples show how to use java.nio.channels.SelectableChannel#isRegistered() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowsSelectorImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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();
            }
        }
    }
}
 
Example 2
Source File: WindowsSelectorImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 3
Source File: WindowsSelectorImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 4
Source File: WindowsSelectorImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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();
            }
        }
    }
}
 
Example 5
Source File: WindowsSelectorImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 6
Source File: WindowsSelectorImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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();
            }
        }
    }
}
 
Example 7
Source File: WindowsSelectorImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 8
Source File: WindowsSelectorImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
            }
        }
    }
}
 
Example 9
Source File: WindowsSelectorImpl.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 10
Source File: WindowsSelectorImpl.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
            }
        }
    }
}
 
Example 11
Source File: WindowsSelectorImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 12
Source File: WindowsSelectorImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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();
            }
        }
    }
}
 
Example 13
Source File: WindowsSelectorImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 14
Source File: WindowsSelectorImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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();
            }
        }
    }
}
 
Example 15
Source File: WindowsSelectorImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 16
Source File: WindowsSelectorImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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();
            }
        }
    }
}
 
Example 17
Source File: WindowsSelectorImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 18
Source File: SelectChannelEndPoint.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example 19
Source File: SelectChannelEndPoint.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example 20
Source File: CommCore.java    From jolie with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected boolean isSelecting( SelectableStreamingCommChannel channel ) {
	SelectableChannel c = channel.selectableChannel();
	return c != null && c.isRegistered();
}