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 classDefaultSelectorHandler.DeregisterChannelOperationprotected static classDefaultSelectorHandler.RegisterChannelOperationprotected static classDefaultSelectorHandler.RegisterKeyTaskprotected static classDefaultSelectorHandler.RunnableTask-
Nested classes/interfaces inherited from interface org.glassfish.grizzly.nio.SelectorHandler
SelectorHandler.Task
-
-
Field Summary
Fields Modifier and Type Field Description static booleanIS_WORKAROUND_SELECTOR_SPINprotected longselectTimeout-
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 voidderegisterChannel(SelectorRunner selectorRunner, SelectableChannel channel)Deregister the channel from theSelectorRunner's Selector.voidderegisterChannelAsync(SelectorRunner selectorRunner, SelectableChannel channel, CompletionHandler<RegisterChannelResult> completionHandler)Deregister the channel from theSelectorRunner's Selector.voidderegisterKeyInterest(SelectorRunner selectorRunner, SelectionKey key, int interest)Deregisters SelectionKey interest.voidenque(SelectorRunner selectorRunner, SelectorHandler.Task task, CompletionHandler<SelectorHandler.Task> completionHandler)Execute task in a selector thread.voidexecute(SelectorRunner selectorRunner, SelectorHandler.Task task, CompletionHandler<SelectorHandler.Task> completionHandler)Execute task in a selector thread.longgetSelectTimeout()booleanonSelectorClosed(SelectorRunner selectorRunner)voidpostSelect(SelectorRunner selectorRunner)booleanpreSelect(SelectorRunner selectorRunner)voidregisterChannel(SelectorRunner selectorRunner, SelectableChannel channel, int interest, Object attachment)voidregisterChannelAsync(SelectorRunner selectorRunner, SelectableChannel channel, int interest, Object attachment, CompletionHandler<RegisterChannelResult> completionHandler)voidregisterKeyInterest(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:
getSelectTimeoutin interfaceSelectorHandler
-
preSelect
public boolean preSelect(SelectorRunner selectorRunner) throws IOException
- Specified by:
preSelectin interfaceSelectorHandler- Throws:
IOException
-
select
public Set<SelectionKey> select(SelectorRunner selectorRunner) throws IOException
- Specified by:
selectin interfaceSelectorHandler- Throws:
IOException
-
postSelect
public void postSelect(SelectorRunner selectorRunner) throws IOException
- Specified by:
postSelectin interfaceSelectorHandler- Throws:
IOException
-
registerKeyInterest
public void registerKeyInterest(SelectorRunner selectorRunner, SelectionKey key, int interest) throws IOException
- Specified by:
registerKeyInterestin 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:
deregisterKeyInterestin interfaceSelectorHandler- Throws:
IOException
-
registerChannel
public void registerChannel(SelectorRunner selectorRunner, SelectableChannel channel, int interest, Object attachment) throws IOException
- Specified by:
registerChannelin interfaceSelectorHandler- Throws:
IOException
-
registerChannelAsync
public void registerChannelAsync(SelectorRunner selectorRunner, SelectableChannel channel, int interest, Object attachment, CompletionHandler<RegisterChannelResult> completionHandler)
- Specified by:
registerChannelAsyncin interfaceSelectorHandler
-
deregisterChannel
public void deregisterChannel(SelectorRunner selectorRunner, SelectableChannel channel) throws IOException
Description copied from interface:SelectorHandlerDeregister the channel from theSelectorRunner's Selector.- Specified by:
deregisterChannelin interfaceSelectorHandler- Parameters:
selectorRunner-SelectorRunnerchannel-SelectableChannelchannel to deregister- Throws:
IOException
-
deregisterChannelAsync
public void deregisterChannelAsync(SelectorRunner selectorRunner, SelectableChannel channel, CompletionHandler<RegisterChannelResult> completionHandler)
Description copied from interface:SelectorHandlerDeregister the channel from theSelectorRunner's Selector.- Specified by:
deregisterChannelAsyncin interfaceSelectorHandler- Parameters:
selectorRunner-SelectorRunnerchannel-SelectableChannelchannel to deregistercompletionHandler-CompletionHandler
-
execute
public void execute(SelectorRunner selectorRunner, SelectorHandler.Task task, CompletionHandler<SelectorHandler.Task> completionHandler)
Description copied from interface:SelectorHandlerExecute 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:
executein interfaceSelectorHandler
-
enque
public void enque(SelectorRunner selectorRunner, SelectorHandler.Task task, CompletionHandler<SelectorHandler.Task> completionHandler)
Description copied from interface:SelectorHandlerExecute 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:
enquein interfaceSelectorHandler
-
onSelectorClosed
public boolean onSelectorClosed(SelectorRunner selectorRunner)
- Specified by:
onSelectorClosedin interfaceSelectorHandler
-
-