public class SelectorLoop extends IdentifiableObject
Constructor and Description |
---|
SelectorLoop()
Constructs a unnamed selector loop.
|
SelectorLoop(String name)
Constructs a named selector loop
|
SelectorLoop(String name,
ISelectorLoopPool parentPool,
ISelectorLoopStructureFactory factory)
Constructs a named selector loop with specified parent pool
|
Modifier and Type | Method and Description |
---|---|
void |
dirtyStop()
Quickly stops this selector loop.
|
IFuture<Void> |
execute(Runnable task)
Executes a task in the selector-loop's thread.
|
void |
executenf(Runnable task)
Executes a task in the selector-loop's thread.
|
ISelectorLoopController |
getController()
Gets the controller determining the behavior of this selector loop.
|
Executor |
getExecutor()
Returns the executor that is used to execute delegated tasks required by
engine driven sessions to complete operations that block, or may take an
extended period of time to complete.
|
ISelectorLoopPool |
getParentPool()
Gets the selector loop pool that owns this selector loop.
|
ISelectorLoopPool |
getPool()
Gets the pool that is used by this selector loop to retrieve selector
loops for accepted channels.
|
int |
getSize()
Returns the size of the selector's key set associated with the selector loop
|
ThreadFactory |
getThreadFactory()
Returns the thread factory used to create a thread for this selector loop.
|
long |
getTotalWaitTime()
Returns the total time in nanoseconds this selector loop spent waiting
for I/O operations
|
long |
getTotalWorkTime()
Returns the total time in nanoseconds this selector loop spent processing
I/O operations
|
boolean |
inExecutor()
Tells if the current thread is the thread this executor uses to complete
an operation associated with a future.
|
boolean |
isOpen()
Tells if the selector associated with this selector loop is open.
|
boolean |
isStopped()
Tells if this selector loop is stopped.
|
boolean |
isStopping()
Tells if this selector is in the process of stopping.
|
void |
join()
Waits for this selector loop's thread to die.
|
boolean |
join(long millis)
Waits at most
millis milliseconds for this selector loop's
thread to die. |
void |
quickStop()
Quickly stops this selector loop.
|
void |
rebuild()
Rebuilds the associated selector by replacing it with newly created one.
|
IFuture<Void> |
register(DatagramChannel channel,
DatagramSession session)
Registers a datagram-oriented channel with this selector loop.
|
IFuture<Void> |
register(DatagramChannel channel,
IDatagramHandler handler)
Registers a datagram-oriented channel with this selector loop.
|
IFuture<Void> |
register(ServerSocketChannel channel,
IStreamSessionFactory factory)
Registers a listening stream-oriented channel with this selector loop.
|
IFuture<Void> |
register(SocketChannel channel,
IStreamHandler handler)
Registers a stream-oriented channel with this selector loop.
|
IFuture<Void> |
register(SocketChannel channel,
StreamSession session)
Registers a stream-oriented channel with this selector loop.
|
void |
setController(ISelectorLoopController controller)
Sets the controller determining the behavior of this selector loop.
|
void |
setExecutor(Executor executor)
Sets the executor that will be used to execute delegated tasks required
by engine driven sessions to complete operations that block, or may take
an extended period of time to complete.
|
void |
setPool(ISelectorLoopPool pool)
Sets the pool that will be used by this selector loop to retrieve
selector loops for accepted channels.
|
void |
setThreadFactory(ThreadFactory threadFactory)
Sets the thread factory used to create a thread for this selector loop.
|
void |
start()
Starts the selector loop in a new thread.
|
void |
start(boolean inCurrentThread)
Starts the selector loop in a new thread or in the current one.
|
void |
stop()
Gently stops this selector loop.
|
void |
wakeup()
Wakes up the associated selector.
|
getId, getName, toString
public SelectorLoop(String name, ISelectorLoopPool parentPool, ISelectorLoopStructureFactory factory) throws IOException
name
- the name for this selector loop, or null
if the
name should be auto generatedparentPool
- the parent pool that owns this selector loop, or
null
if the selector loop has no parent.factory
- a factory that will be used by this selector loop to
open its selector, or null
if default factory
should be usedIOException
- if the Selector
associated
with this selector loop could not be openedpublic SelectorLoop(String name) throws IOException
name
- the name for this selector loop, or null
if the name should
be auto generatedIOException
- if the Selector
associated with this
selector loop could not be openedpublic SelectorLoop() throws IOException
IOException
- if the Selector
associated with this
selector loop could not be openedpublic ISelectorLoopPool getParentPool()
null
if it has
no parent selector loop poolpublic void setPool(ISelectorLoopPool pool)
There is no need for the pool to be thread safe as long as it is used only by this selector loop.
pool
- the pool with selector loops for accepted channelspublic ISelectorLoopPool getPool()
public void setController(ISelectorLoopController controller)
controller
- the controllerpublic ISelectorLoopController getController()
public IFuture<Void> register(SocketChannel channel, IStreamHandler handler) throws ClosedChannelException
This method is asynchronous.
channel
- the stream-oriented channel to register with this selector
loophandler
- the handler that will be associated with the channelClosedChannelException
- if the channel is closedSelectorLoopStoppingException
- if selector loop is in the process of stoppingClosedSelectorException
- if the internal selector is closedIllegalArgumentException
- if a bit in ops does not correspond to an operation that is
supported by the channelpublic IFuture<Void> register(SocketChannel channel, StreamSession session) throws ClosedChannelException
This method is asynchronous.
channel
- the stream-oriented channel to register with this selector
loopsession
- the session that will be associated with the channelClosedChannelException
- if the channel is closedSelectorLoopStoppingException
- if selector loop is in the process of stoppingClosedSelectorException
- if the internal selector is closedIllegalArgumentException
- if a bit in ops does not correspond to an operation that is
supported by the channelIllegalArgumentException
- if the session argument is null
or the session
object is reused (was already registered with some selector
loop)public IFuture<Void> register(DatagramChannel channel, IDatagramHandler handler) throws ClosedChannelException
This method is asynchronous.
channel
- the datagram-oriented channel to register with this selector
loophandler
- the handler that will be associated with the channelClosedChannelException
- if the channel is closedSelectorLoopStoppingException
- if selector loop is in the process of stoppingClosedSelectorException
- if the internal selector is closedIllegalArgumentException
- if a bit in ops does not correspond to an operation that is
supported by the channelpublic IFuture<Void> register(DatagramChannel channel, DatagramSession session) throws ClosedChannelException
This method is asynchronous.
channel
- the datagram-oriented channel to register with this selector
loopsession
- the session that will be associated with the channelClosedChannelException
- if the channel is closedSelectorLoopStoppingException
- if selector loop is in the process of stoppingClosedSelectorException
- if the internal selector is closedIllegalArgumentException
- if a bit in ops does not correspond to an operation that is
supported by the channelIllegalArgumentException
- if the session argument is null
or the session
object is reused (was already registered with some selector
loop)public IFuture<Void> register(ServerSocketChannel channel, IStreamSessionFactory factory) throws ClosedChannelException
This method is asynchronous.
channel
- the listening stream-oriented channel to register with this
selector loopfactory
- the factory that will be associated with the channel. It will
be used to create sessions for newly accepted channelsClosedChannelException
- if the channel is closedSelectorLoopStoppingException
- if selector loop is in the process of stoppingClosedSelectorException
- if the internal selector is closedIllegalArgumentException
- if a bit in ops does not correspond to an operation that is
supported by the channelIllegalArgumentException
- if the factory argument is null
public long getTotalWaitTime()
public long getTotalWorkTime()
public void rebuild()
This operation is asynchronous.
public void setThreadFactory(ThreadFactory threadFactory)
start
method.threadFactory
- the new thread factoryNullPointerException
- If the threadFactory
argument is
null
public ThreadFactory getThreadFactory()
public void setExecutor(Executor executor)
executor
- the new executorNullPointerException
- If the executor
argument is null
public Executor getExecutor()
public int getSize()
ClosedSelectorException
- if the associated selector is closedpublic boolean isOpen()
true
if the associated selector is openpublic void start(boolean inCurrentThread)
inCurrentThread
- true
if the selector loop should run in the
current threadClosedSelectorException
- if the internal selector is closedpublic void start()
ClosedSelectorException
- if the internal selector is closedpublic void wakeup()
Selector.wakeup()
public final boolean inExecutor()
IFutureExecutor
inExecutor
in interface IFutureExecutor
true
if the current thread is the thread used by
this executor.public void stop()
close
method.
This method is asynchronous.
public void quickStop()
quickClose
method.
This method is asynchronous.
public void dirtyStop()
dirtyClose
method.
This method is asynchronous.
public boolean isStopping()
true
if stopping is in progress or this selector loop is already stoppedpublic boolean isStopped()
true
if this selector loop is stoppedpublic final boolean join(long millis) throws InterruptedException
millis
milliseconds for this selector loop's
thread to die.millis
- the time to wait in millisecondstrue
if the selector loop's thread diedInterruptedException
- if any thread has interrupted the current threadIllegalArgumentException
- if the value of millis
is negativepublic final void join() throws InterruptedException
InterruptedException
- if any thread has interrupted the current threadpublic void executenf(Runnable task)
This method should be used whenever there will be no need to synchronize on a future associated with the specified task. This will save some resources and may improve performance.
task
- task to be executed in the selector-loop's threadSelectorLoopStoppingException
- if selector loop is in the process of stoppingIllegalArgumentException
- if task
is nullpublic IFuture<Void> execute(Runnable task)
task
- task to be executed in the selector-loop's threadSelectorLoopStoppingException
- if selector loop is in the process of stoppingIllegalArgumentException
- if task
is nullCopyright © 2017–2021 SNF4J.ORG. All rights reserved.