Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.nio

public Class DefaultSelectorHandler

extends Object
implements SelectorHandler
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.nio.SelectorHandler
Imports
java.io.IOException, java.nio.channels.ClosedChannelException, .SelectableChannel, .SelectionKey, .Selector, java.util.Queue, .Set, java.util.concurrent.TimeUnit, java.util.logging.Level, .Logger, org.glassfish.grizzly.CompletionHandler, .Grizzly, org.glassfish.grizzly.impl.FutureImpl, .SafeFutureImpl, org.glassfish.grizzly.utils.Futures

Default implementation of NIO SelectorHandler
Author
Alexey Stashok

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
protected static class
protected static class
protected static class

Field Summary

Modifier and TypeField and Description
private static final long
public static final boolean
private static final Logger
protected final long
private static final int
SPIN_RATE_THRESHOLD

The threshold for detecting selector.select spin on linux, used for enabling workaround to prevent server from hanging.

Constructor Summary

AccessConstructor and Description
public
public
DefaultSelectorHandler(final long selectTimeout, final TimeUnit timeunit)

Method Summary

Modifier and TypeMethod and Description
private void
addPendingTask(final SelectorRunner selectorRunner, final SelectorHandlerTask task)

public void
deregisterChannel(final SelectorRunner selectorRunner, final SelectableChannel channel)

Implements org.glassfish.grizzly.nio.SelectorHandler.deregisterChannel.

Deregister the channel from the SelectorRunner's Selector.

private static void
deregisterChannel0(final SelectorRunner selectorRunner, final SelectableChannel channel, final CompletionHandler<RegisterChannelResult> completionHandler)

public void
deregisterChannelAsync(final SelectorRunner selectorRunner, final SelectableChannel channel, final CompletionHandler<RegisterChannelResult> completionHandler)

Implements org.glassfish.grizzly.nio.SelectorHandler.deregisterChannelAsync.

Deregister the channel from the SelectorRunner's Selector.

public void
deregisterKeyInterest(final SelectorRunner selectorRunner, final SelectionKey key, final int interest)

Implements org.glassfish.grizzly.nio.SelectorHandler.deregisterKeyInterest.

Deregisters SelectionKey interest.

public void
enque(final SelectorRunner selectorRunner, final SelectorHandler.Task task, final CompletionHandler<SelectorHandler.Task> completionHandler)

Implements org.glassfish.grizzly.nio.SelectorHandler.enque.

Execute task in a selector thread.

public void
execute(final SelectorRunner selectorRunner, final SelectorHandler.Task task, final CompletionHandler<SelectorHandler.Task> completionHandler)

Implements org.glassfish.grizzly.nio.SelectorHandler.execute.

Execute task in a selector thread.

private static void
public long
private static boolean
isSelectorRunnerThread(final SelectorRunner selectorRunner)

public boolean
public void
public boolean
private boolean
processPendingTaskQueue(final SelectorRunner selectorRunner, final Queue<SelectorHandlerTask> selectorHandlerTasks)

private boolean
processPendingTasks(final SelectorRunner selectorRunner)

public void
registerChannel(final SelectorRunner selectorRunner, final SelectableChannel channel, final int interest, final Object attachment)

Implements org.glassfish.grizzly.nio.SelectorHandler.registerChannel.

private static void
registerChannel0(final SelectorRunner selectorRunner, final SelectableChannel channel, final int interest, final Object attachment, final CompletionHandler<RegisterChannelResult> completionHandler)

public void
private static void
registerKey0(final SelectionKey selectionKey, final int interest)

public void
public Set<SelectionKey>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_SELECT_TIMEOUT_MILLISback to summary
private static final long DEFAULT_SELECT_TIMEOUT_MILLIS
IS_WORKAROUND_SELECTOR_SPINback to summary
public static final boolean IS_WORKAROUND_SELECTOR_SPIN
loggerback to summary
private static final Logger logger
selectTimeoutback to summary
protected final long selectTimeout
SPIN_RATE_THRESHOLDback to summary
private static final int SPIN_RATE_THRESHOLD

The threshold for detecting selector.select spin on linux, used for enabling workaround to prevent server from hanging.

Constructor Detail

DefaultSelectorHandlerback to summary
public DefaultSelectorHandler()
DefaultSelectorHandlerback to summary
public DefaultSelectorHandler(final long selectTimeout, final TimeUnit timeunit)

Method Detail

addPendingTaskback to summary
private void addPendingTask(final SelectorRunner selectorRunner, final SelectorHandlerTask task)
deregisterChannelback to summary
public void deregisterChannel(final SelectorRunner selectorRunner, final SelectableChannel channel) throws IOException

Implements org.glassfish.grizzly.nio.SelectorHandler.deregisterChannel.

Doc from org.glassfish.grizzly.nio.SelectorHandler.deregisterChannel.

Deregister the channel from the SelectorRunner's Selector.

Annotations
@Override
deregisterChannel0back to summary
private static void deregisterChannel0(final SelectorRunner selectorRunner, final SelectableChannel channel, final CompletionHandler<RegisterChannelResult> completionHandler)
deregisterChannelAsyncback to summary
public void deregisterChannelAsync(final SelectorRunner selectorRunner, final SelectableChannel channel, final CompletionHandler<RegisterChannelResult> completionHandler)

Implements org.glassfish.grizzly.nio.SelectorHandler.deregisterChannelAsync.

Doc from org.glassfish.grizzly.nio.SelectorHandler.deregisterChannelAsync.

Deregister the channel from the SelectorRunner's Selector.

Annotations
@Override
deregisterKeyInterestback to summary
public void deregisterKeyInterest(final SelectorRunner selectorRunner, final SelectionKey key, final int interest) throws IOException

Implements org.glassfish.grizzly.nio.SelectorHandler.deregisterKeyInterest.

Doc from org.glassfish.grizzly.nio.SelectorHandler.deregisterKeyInterest.

Deregisters SelectionKey interest. This method must be called from the SelectorRunner's thread only!

Annotations
@Override
enqueback to summary
public void enque(final SelectorRunner selectorRunner, final SelectorHandler.Task task, final CompletionHandler<SelectorHandler.Task> completionHandler)

Implements org.glassfish.grizzly.nio.SelectorHandler.enque.

Doc from org.glassfish.grizzly.nio.SelectorHandler.enque.

Execute task in a selector thread. Unlike 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 next select(org.glassfish.grizzly.nio.SelectorRunner) iteration.

Annotations
@Override
executeback to summary
public void execute(final SelectorRunner selectorRunner, final SelectorHandler.Task task, final CompletionHandler<SelectorHandler.Task> completionHandler)

Implements org.glassfish.grizzly.nio.SelectorHandler.execute.

Doc from org.glassfish.grizzly.nio.SelectorHandler.execute.

Execute task in a selector thread. Unlike 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.

Annotations
@Override
failChannelRegistrationback to summary
private static void failChannelRegistration(final CompletionHandler<RegisterChannelResult> completionHandler, final Throwable error)
getSelectTimeoutback to summary
public long getSelectTimeout()

Implements org.glassfish.grizzly.nio.SelectorHandler.getSelectTimeout.

Annotations
@Override
isSelectorRunnerThreadback to summary
private static boolean isSelectorRunnerThread(final SelectorRunner selectorRunner)
onSelectorClosedback to summary
public boolean onSelectorClosed(final SelectorRunner selectorRunner)

Implements org.glassfish.grizzly.nio.SelectorHandler.onSelectorClosed.

Annotations
@Override
postSelectback to summary
public void postSelect(final SelectorRunner selectorRunner) throws IOException

Implements org.glassfish.grizzly.nio.SelectorHandler.postSelect.

Annotations
@Override
preSelectback to summary
public boolean preSelect(final SelectorRunner selectorRunner) throws IOException

Implements org.glassfish.grizzly.nio.SelectorHandler.preSelect.

Annotations
@Override
processPendingTaskQueueback to summary
private boolean processPendingTaskQueue(final SelectorRunner selectorRunner, final Queue<SelectorHandlerTask> selectorHandlerTasks) throws IOException
processPendingTasksback to summary
private boolean processPendingTasks(final SelectorRunner selectorRunner) throws IOException
registerChannelback to summary
public void registerChannel(final SelectorRunner selectorRunner, final SelectableChannel channel, final int interest, final Object attachment) throws IOException

Implements org.glassfish.grizzly.nio.SelectorHandler.registerChannel.

Annotations
@Override
registerChannel0back to summary
private static void registerChannel0(final SelectorRunner selectorRunner, final SelectableChannel channel, final int interest, final Object attachment, final CompletionHandler<RegisterChannelResult> completionHandler)
registerChannelAsyncback to summary
public void registerChannelAsync(SelectorRunner selectorRunner, SelectableChannel channel, int interest, Object attachment, CompletionHandler<RegisterChannelResult> completionHandler)

Implements org.glassfish.grizzly.nio.SelectorHandler.registerChannelAsync.

Annotations
@Override
registerKey0back to summary
private static void registerKey0(final SelectionKey selectionKey, final int interest)
registerKeyInterestback to summary
public void registerKeyInterest(final SelectorRunner selectorRunner, final SelectionKey key, final int interest) throws IOException

Implements org.glassfish.grizzly.nio.SelectorHandler.registerKeyInterest.

Annotations
@Override
selectback to summary
public Set<SelectionKey> select(final SelectorRunner selectorRunner) throws IOException

Implements org.glassfish.grizzly.nio.SelectorHandler.select.

Annotations
@Override
org.glassfish.grizzly.nio back to summary

protected final Class DefaultSelectorHandler.DeregisterChannelOperation

extends Object
implements SelectorHandlerTask
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.nio.DefaultSelectorHandler.DeregisterChannelOperation
All Implemented Interfaces
org.glassfish.grizzly.nio.SelectorHandlerTask

Field Summary

Modifier and TypeField and Description
private final SelectableChannel
private final CompletionHandler<RegisterChannelResult>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

channelback to summary
private final SelectableChannel channel
completionHandlerback to summary
private final CompletionHandler<RegisterChannelResult> completionHandler

Constructor Detail

DeregisterChannelOperationback to summary
private DeregisterChannelOperation(final SelectableChannel channel, final CompletionHandler<RegisterChannelResult> completionHandler)

Method Detail

cancelback to summary
public void cancel()

Implements org.glassfish.grizzly.nio.SelectorHandlerTask.cancel.

Annotations
@Override
runback to summary
public boolean run(final SelectorRunner selectorRunner) throws IOException

Implements org.glassfish.grizzly.nio.SelectorHandlerTask.run.

Annotations
@Override
org.glassfish.grizzly.nio back to summary

protected final Class DefaultSelectorHandler.RegisterChannelOperation

extends Object
implements SelectorHandlerTask
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.nio.DefaultSelectorHandler.RegisterChannelOperation
All Implemented Interfaces
org.glassfish.grizzly.nio.SelectorHandlerTask

Field Summary

Modifier and TypeField and Description
private final Object
private final SelectableChannel
private final CompletionHandler<RegisterChannelResult>
private final int

Constructor Summary

AccessConstructor and Description
private
RegisterChannelOperation(final SelectableChannel channel, final int interest, final Object attachment, final CompletionHandler<RegisterChannelResult> completionHandler)

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attachmentback to summary
private final Object attachment
channelback to summary
private final SelectableChannel channel
completionHandlerback to summary
private final CompletionHandler<RegisterChannelResult> completionHandler
interestback to summary
private final int interest

Constructor Detail

RegisterChannelOperationback to summary
private RegisterChannelOperation(final SelectableChannel channel, final int interest, final Object attachment, final CompletionHandler<RegisterChannelResult> completionHandler)

Method Detail

cancelback to summary
public void cancel()

Implements org.glassfish.grizzly.nio.SelectorHandlerTask.cancel.

Annotations
@Override
runback to summary
public boolean run(final SelectorRunner selectorRunner) throws IOException

Implements org.glassfish.grizzly.nio.SelectorHandlerTask.run.

Annotations
@Override
org.glassfish.grizzly.nio back to summary

protected final Class DefaultSelectorHandler.RegisterKeyTask

extends Object
implements SelectorHandlerTask
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.nio.DefaultSelectorHandler.RegisterKeyTask
All Implemented Interfaces
org.glassfish.grizzly.nio.SelectorHandlerTask

Field Summary

Modifier and TypeField and Description
private final int
private final SelectionKey

Constructor Summary

AccessConstructor and Description
public
RegisterKeyTask(final SelectionKey selectionKey, final int interest)

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

interestback to summary
private final int interest
selectionKeyback to summary
private final SelectionKey selectionKey

Constructor Detail

RegisterKeyTaskback to summary
public RegisterKeyTask(final SelectionKey selectionKey, final int interest)

Method Detail

cancelback to summary
public void cancel()

Implements org.glassfish.grizzly.nio.SelectorHandlerTask.cancel.

Annotations
@Override
runback to summary
public boolean run(final SelectorRunner selectorRunner) throws IOException

Implements org.glassfish.grizzly.nio.SelectorHandlerTask.run.

Annotations
@Override
org.glassfish.grizzly.nio back to summary

protected final Class DefaultSelectorHandler.RunnableTask

extends Object
implements SelectorHandlerTask
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.nio.DefaultSelectorHandler.RunnableTask
All Implemented Interfaces
org.glassfish.grizzly.nio.SelectorHandlerTask

Field Summary

Modifier and TypeField and Description
private final CompletionHandler<SelectorHandler.Task>
private final SelectorHandler.Task

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

completionHandlerback to summary
private final CompletionHandler<SelectorHandler.Task> completionHandler
taskback to summary
private final SelectorHandler.Task task

Constructor Detail

RunnableTaskback to summary
private RunnableTask(final SelectorHandler.Task task, final CompletionHandler<SelectorHandler.Task> completionHandler)

Method Detail

cancelback to summary
public void cancel()

Implements org.glassfish.grizzly.nio.SelectorHandlerTask.cancel.

Annotations
@Override
runback to summary
public boolean run(final SelectorRunner selectorRunner) throws IOException

Implements org.glassfish.grizzly.nio.SelectorHandlerTask.run.

Annotations
@Override