public abstract class AbstractSelector extends Selector
这个类封装了所需的执行选择操作中断的低级机械。一个具体的选择器类必须调用begin
和end
方法之前和之后,分别调用I/O操作可能会无限期的阻塞。为了确保end
总是调用方法,这些方法应在一个try …用 finally块:
try { begin(); // Perform blocking I/O operation here ... } finally { end(); }
这类还定义了方法保持一个选择器的取消键设置为从通道的密钥集删除密钥,并宣称是通过选择信道的register
方法为了执行注册信道实际工作register
方法摘要。
Modifier | Constructor and Description |
---|---|
protected |
AbstractSelector(SelectorProvider provider)
初始化该类的一个新实例。
|
Modifier and Type | Method and Description |
---|---|
protected void |
begin()
标志着一个可能会被无限期阻止的I / O操作的开始。
|
protected Set<SelectionKey> |
cancelledKeys()
检索此选择器已取消的键集。
|
void |
close()
关闭此选择器。
|
protected void |
deregister(AbstractSelectionKey key)
从其通道的键组中移除给定的键。
|
protected void |
end()
标志着一个“I / O操作”的结束,可能会被无限期地阻止。
|
protected abstract void |
implCloseSelector()
关闭此选择器。
|
boolean |
isOpen()
告诉是否这个选择器是打开的。
|
SelectorProvider |
provider()
返回创建此通道的提供程序。
|
protected abstract SelectionKey |
register(AbstractSelectableChannel ch, int ops, Object att)
用这个选择器寄存器指定给定的通道。
|
protected AbstractSelector(SelectorProvider provider)
provider
-供应商,创造了这个选择器
public final void close() throws IOException
如果选择器已被关闭,则此方法将立即返回。否则,它标志着选择关闭,然后调用implCloseSelector
方法为了完成关闭操作。
close
接口
Closeable
close
接口
AutoCloseable
close
方法重写,继承类
Selector
IOException
如果I/O错误发生
protected abstract void implCloseSelector() throws IOException
这种方法是以close
方法调用执行关闭选择的实际工作。此方法仅在选择器尚未关闭时才调用,并且它从来没有被调用过不止一次。
此方法的实现必须安排被阻塞在选择操作在这个选择器立即返回如果通过调用任何其他线程wakeup
方法。
IOException
-如果发生I/O错误而关闭选择器
public final boolean isOpen()
Selector
public final SelectorProvider provider()
protected final Set<SelectionKey> cancelledKeys()
此设置只应在同步时使用。
protected abstract SelectionKey register(AbstractSelectableChannel ch, int ops, Object att)
这种方法是通过一个通道的register
方法为了履行与该选择器注册信道实际工作。
ch
-通道被注册
ops
-最初的兴趣,它必须是有效的
att
-产生的关键初始连接
protected final void deregister(AbstractSelectionKey key)
这个方法必须由每个通道选择器调用它撤销。
key
-选择键被删除
protected final void begin()
protected final void end()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.