Search in sources :

Example 1 with AbstractSelectionKey

use of java.nio.channels.spi.AbstractSelectionKey in project robovm by robovm.

the class SelectorImpl method doCancel.

/**
     * 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;
}
Also used : AbstractSelectionKey(java.nio.channels.spi.AbstractSelectionKey) SelectionKey(java.nio.channels.SelectionKey)

Example 2 with AbstractSelectionKey

use of java.nio.channels.spi.AbstractSelectionKey in project robovm by robovm.

the class SelectorImpl method implCloseSelector.

@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);
                }
            }
        }
    }
}
Also used : AbstractSelectionKey(java.nio.channels.spi.AbstractSelectionKey) SelectionKey(java.nio.channels.SelectionKey)

Example 3 with AbstractSelectionKey

use of java.nio.channels.spi.AbstractSelectionKey in project XobotOS by xamarin.

the class SelectorImpl method doCancel.

/**
     * 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;
}
Also used : AbstractSelectionKey(java.nio.channels.spi.AbstractSelectionKey) SelectionKey(java.nio.channels.SelectionKey)

Example 4 with AbstractSelectionKey

use of java.nio.channels.spi.AbstractSelectionKey in project j2objc by google.

the class SelectorImpl method implCloseSelector.

@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);
                }
            }
        }
    }
}
Also used : AbstractSelectionKey(java.nio.channels.spi.AbstractSelectionKey) SelectionKey(java.nio.channels.SelectionKey)

Example 5 with AbstractSelectionKey

use of java.nio.channels.spi.AbstractSelectionKey in project j2objc by google.

the class SelectorImpl method doCancel.

/**
     * 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;
}
Also used : AbstractSelectionKey(java.nio.channels.spi.AbstractSelectionKey) SelectionKey(java.nio.channels.SelectionKey)

Aggregations

SelectionKey (java.nio.channels.SelectionKey)6 AbstractSelectionKey (java.nio.channels.spi.AbstractSelectionKey)6