Package org.glassfish.grizzly.nio
Class DefaultSelectorHandler
- java.lang.Object
-
- org.glassfish.grizzly.nio.DefaultSelectorHandler
-
- All Implemented Interfaces:
SelectorHandler
public class DefaultSelectorHandler extends Object implements SelectorHandler
Default implementation of NIOSelectorHandler
- Author:
- Alexey Stashok
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
DefaultSelectorHandler.DeregisterChannelOperation
protected static class
DefaultSelectorHandler.RegisterChannelOperation
protected static class
DefaultSelectorHandler.RegisterKeyTask
protected static class
DefaultSelectorHandler.RunnableTask
-
Nested classes/interfaces inherited from interface org.glassfish.grizzly.nio.SelectorHandler
SelectorHandler.Task
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
IS_WORKAROUND_SELECTOR_SPIN
protected long
selectTimeout
-
Fields inherited from interface org.glassfish.grizzly.nio.SelectorHandler
DEFAULT_SELECTOR_HANDLER
-
-
Constructor Summary
Constructors Constructor Description DefaultSelectorHandler()
DefaultSelectorHandler(long selectTimeout, TimeUnit timeunit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deregisterChannel(SelectorRunner selectorRunner, SelectableChannel channel)
Deregister the channel from theSelectorRunner
's Selector.void
deregisterChannelAsync(SelectorRunner selectorRunner, SelectableChannel channel, CompletionHandler<RegisterChannelResult> completionHandler)
Deregister the channel from theSelectorRunner
's Selector.void
deregisterKeyInterest(SelectorRunner selectorRunner, SelectionKey key, int interest)
Deregisters SelectionKey interest.void
enque(SelectorRunner selectorRunner, SelectorHandler.Task task, CompletionHandler<SelectorHandler.Task> completionHandler)
Execute task in a selector thread.void
execute(SelectorRunner selectorRunner, SelectorHandler.Task task, CompletionHandler<SelectorHandler.Task> completionHandler)
Execute task in a selector thread.long
getSelectTimeout()
boolean
onSelectorClosed(SelectorRunner selectorRunner)
void
postSelect(SelectorRunner selectorRunner)
boolean
preSelect(SelectorRunner selectorRunner)
void
registerChannel(SelectorRunner selectorRunner, SelectableChannel channel, int interest, Object attachment)
void
registerChannelAsync(SelectorRunner selectorRunner, SelectableChannel channel, int interest, Object attachment, CompletionHandler<RegisterChannelResult> completionHandler)
void
registerKeyInterest(SelectorRunner selectorRunner, SelectionKey key, int interest)
Set<SelectionKey>
select(SelectorRunner selectorRunner)
-
-
-
Constructor Detail
-
DefaultSelectorHandler
public DefaultSelectorHandler()
-
DefaultSelectorHandler
public DefaultSelectorHandler(long selectTimeout, TimeUnit timeunit)
-
-
Method Detail
-
getSelectTimeout
public long getSelectTimeout()
- Specified by:
getSelectTimeout
in interfaceSelectorHandler
-
preSelect
public boolean preSelect(SelectorRunner selectorRunner) throws IOException
- Specified by:
preSelect
in interfaceSelectorHandler
- Throws:
IOException
-
select
public Set<SelectionKey> select(SelectorRunner selectorRunner) throws IOException
- Specified by:
select
in interfaceSelectorHandler
- Throws:
IOException
-
postSelect
public void postSelect(SelectorRunner selectorRunner) throws IOException
- Specified by:
postSelect
in interfaceSelectorHandler
- Throws:
IOException
-
registerKeyInterest
public void registerKeyInterest(SelectorRunner selectorRunner, SelectionKey key, int interest) throws IOException
- Specified by:
registerKeyInterest
in interfaceSelectorHandler
- Throws:
IOException
-
deregisterKeyInterest
public void deregisterKeyInterest(SelectorRunner selectorRunner, SelectionKey key, int interest) throws IOException
Deregisters SelectionKey interest. This method must be called from the SelectorRunner's thread only!- Specified by:
deregisterKeyInterest
in interfaceSelectorHandler
- Throws:
IOException
-
registerChannel
public void registerChannel(SelectorRunner selectorRunner, SelectableChannel channel, int interest, Object attachment) throws IOException
- Specified by:
registerChannel
in interfaceSelectorHandler
- Throws:
IOException
-
registerChannelAsync
public void registerChannelAsync(SelectorRunner selectorRunner, SelectableChannel channel, int interest, Object attachment, CompletionHandler<RegisterChannelResult> completionHandler)
- Specified by:
registerChannelAsync
in interfaceSelectorHandler
-
deregisterChannel
public void deregisterChannel(SelectorRunner selectorRunner, SelectableChannel channel) throws IOException
Description copied from interface:SelectorHandler
Deregister the channel from theSelectorRunner
's Selector.- Specified by:
deregisterChannel
in interfaceSelectorHandler
- Parameters:
selectorRunner
-SelectorRunner
channel
-SelectableChannel
channel to deregister- Throws:
IOException
-
deregisterChannelAsync
public void deregisterChannelAsync(SelectorRunner selectorRunner, SelectableChannel channel, CompletionHandler<RegisterChannelResult> completionHandler)
Description copied from interface:SelectorHandler
Deregister the channel from theSelectorRunner
's Selector.- Specified by:
deregisterChannelAsync
in interfaceSelectorHandler
- Parameters:
selectorRunner
-SelectorRunner
channel
-SelectableChannel
channel to deregistercompletionHandler
-CompletionHandler
-
execute
public void execute(SelectorRunner selectorRunner, SelectorHandler.Task task, CompletionHandler<SelectorHandler.Task> completionHandler)
Description copied from interface:SelectorHandler
Execute task in a selector thread. UnlikeSelectorHandler.enque(org.glassfish.grizzly.nio.SelectorRunner, org.glassfish.grizzly.nio.SelectorHandler.Task, org.glassfish.grizzly.CompletionHandler)
, this operation will execute the task immediately if the current is a selector thread.- Specified by:
execute
in interfaceSelectorHandler
-
enque
public void enque(SelectorRunner selectorRunner, SelectorHandler.Task task, CompletionHandler<SelectorHandler.Task> completionHandler)
Description copied from interface:SelectorHandler
Execute task in a selector thread. UnlikeSelectorHandler.execute(org.glassfish.grizzly.nio.SelectorRunner, org.glassfish.grizzly.nio.SelectorHandler.Task, org.glassfish.grizzly.CompletionHandler)
, this operation will postpone the task execution if current thread is a selector thread, and execute it during the nextSelectorHandler.select(org.glassfish.grizzly.nio.SelectorRunner)
iteration.- Specified by:
enque
in interfaceSelectorHandler
-
onSelectorClosed
public boolean onSelectorClosed(SelectorRunner selectorRunner)
- Specified by:
onSelectorClosed
in interfaceSelectorHandler
-
-