Methods Summary |
---|
public final java.lang.Object | blockingLock()Gets the object used for the synchronization of {@code register} and
{@code configureBlocking}.
return blockingLock;
|
public final java.nio.channels.SelectableChannel | configureBlocking(boolean blockingMode)Sets the blocking mode of this channel. A call to this method blocks if
other calls to this method or to {@code register} are executing. The
actual setting of the mode is done by calling
{@code implConfigureBlocking(boolean)}.
if (isOpen()) {
synchronized (blockingLock) {
if (isBlocking == blockingMode) {
return this;
}
if (blockingMode && isRegistered()) {
throw new IllegalBlockingModeException();
}
implConfigureBlocking(blockingMode);
isBlocking = blockingMode;
}
return this;
}
throw new ClosedChannelException();
|
synchronized void | deregister(java.nio.channels.SelectionKey k)
if (null != keyList) {
keyList.remove(k);
}
|
protected final synchronized void | implCloseChannel()Implements the channel closing behavior. Calls
{@code implCloseSelectableChannel()} first, then loops through the list
of selection keys and cancels them, which unregisters this channel from
all selectors it is registered with.
implCloseSelectableChannel();
for (int i = 0; i < keyList.size(); i++) {
SelectionKey key = keyList.get(i);
if (null != key) {
key.cancel();
}
}
|
protected abstract void | implCloseSelectableChannel()Implements the closing function of the SelectableChannel. This method is
called from {@code implCloseChannel()}.
|
protected abstract void | implConfigureBlocking(boolean blockingMode)Implements the setting of the blocking mode.
|
public final boolean | isBlocking()Indicates whether this channel is in blocking mode.
synchronized (blockingLock) {
return isBlocking;
}
|
public final synchronized boolean | isRegistered()Indicates whether this channel is registered with one or more selectors.
return !keyList.isEmpty();
|
public final synchronized java.nio.channels.SelectionKey | keyFor(java.nio.channels.Selector selector)Gets this channel's selection key for the specified selector.
for (int i = 0; i < keyList.size(); i++) {
SelectionKey key = keyList.get(i);
if (null != key && key.selector() == selector) {
return key;
}
}
return null;
|
public final java.nio.channels.spi.SelectorProvider | provider()Returns the selector provider that has created this channel.
return provider;
|
public final java.nio.channels.SelectionKey | register(java.nio.channels.Selector selector, int interestSet, java.lang.Object attachment)Registers this channel with the specified selector for the specified
interest set. If the channel is already registered with the selector, the
{@link SelectionKey interest set} is updated to {@code interestSet} and
the corresponding selection key is returned. If the channel is not yet
registered, this method calls the {@code register} method of
{@code selector} and adds the selection key to this channel's key set.
if (!isOpen()) {
throw new ClosedChannelException();
}
if (!((interestSet & ~validOps()) == 0)) {
throw new IllegalArgumentException();
}
synchronized (blockingLock) {
if (isBlocking) {
throw new IllegalBlockingModeException();
}
if (!selector.isOpen()) {
if (0 == interestSet) {
// throw ISE exactly to keep consistency
throw new IllegalSelectorException();
}
// throw NPE exactly to keep consistency
throw new NullPointerException();
}
if (0 == interestSet) {
// throw ISE exactly to keep consistency
throw new IllegalSelectorException();
}
SelectionKey key = keyFor(selector);
if (null == key) {
key = ((AbstractSelector) selector).register(this, interestSet,
attachment);
keyList.add(key);
} else {
if (!key.isValid()) {
throw new CancelledKeyException();
}
key.interestOps(interestSet);
key.attach(attachment);
}
return key;
}
|