com.sun.sgs.impl.nio
Class ReactiveChannelGroup

java.lang.Object
  extended by com.sun.sgs.nio.channels.AsynchronousChannelGroup
      extended by com.sun.sgs.impl.nio.AsyncGroupImpl
          extended by com.sun.sgs.impl.nio.ReactiveChannelGroup

 class ReactiveChannelGroup
extends AsyncGroupImpl

A select-based AsynchronousChannelGroup.

This class is a container for a set of Reactors which do the actual work of registering and dispatching asynchronous operations on channels. It provides:

The default number of Reactors is set as the number of available processors, but it can be changed by setting the requested number in the system property "com.sun.sgs.nio.async.reactive.reactors".


Nested Class Summary
(package private)  class ReactiveChannelGroup.HashingReactorAssignmentStrategy
          A Reactor load balancing strategy that chooses a reactor based on the hash of the channel.
(package private) static interface ReactiveChannelGroup.ReactorAssignmentStrategy
          Interface for Reactor load balancing strategies.
(package private)  class ReactiveChannelGroup.Worker
          Worker to run a reactor and check termination when a reactor completes.
 
Field Summary
static int DEFAULT_REACTORS
          The default number of reactors to be used by channel groups: Runtime.getRuntime().availableProcessors()
protected static int DONE
          State: terminated
protected  int lifecycleState
          The lifecycle state of this group.
(package private) static Logger log
          The logger for this class.
(package private)  ReactiveChannelGroup.ReactorAssignmentStrategy reactorAssignmentStrategy
          The reactor load-balance strategy.
(package private)  List<Reactor> reactors
          The active reactors in this group.
static String REACTORS_PROPERTY
          The property to specify the number of reactors to be used by channel groups: "com.sun.sgs.nio.async.reactive.reactors"
protected static int RUNNING
          State: open and running
protected static int SHUTDOWN
          State: graceful shutdown in progress
protected static int SHUTDOWN_NOW
          State: forced shutdown in progress
(package private)  Object stateLock
          Lock held on updates to lifecycleState and reactors list, and the condition variable for awaiting group termination.
 
Fields inherited from class com.sun.sgs.impl.nio.AsyncGroupImpl
executor, uncaughtHandler
 
Constructor Summary
ReactiveChannelGroup(ReactiveAsyncChannelProvider provider, ExecutorService executor)
          Creates a new group with the default number of reactors.
ReactiveChannelGroup(ReactiveAsyncChannelProvider provider, ExecutorService executor, int requestedReactors)
          Creates a new group with the requested number of reactors.
 
Method Summary
 boolean awaitTermination(long timeout, TimeUnit unit)
          Awaits termination of the group.
 boolean isShutdown()
          Tells whether or not this asynchronous channel group is shutdown.
 boolean isTerminated()
          Tells whether or not this asynchronous channel group is terminated.
(package private)  AsyncKey register(SelectableChannel ch)
          Registers the given channel with this group, returning an AsyncKey that can be used to invoke asynchronous IO operations.
 ReactiveChannelGroup shutdown()
          Initiates an orderly shutdown of the group.
 ReactiveChannelGroup shutdownNow()
          Shuts down the group and closes all open channels in the group.
 
Methods inherited from class com.sun.sgs.impl.nio.AsyncGroupImpl
completionRunner, executor, finalize, selectorProvider
 
Methods inherited from class com.sun.sgs.nio.channels.AsynchronousChannelGroup
getDefaultUncaughtExceptionHandler, open, provider, setDefaultUncaughtExceptionHandler
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

static final Logger log
The logger for this class.


stateLock

final Object stateLock
Lock held on updates to lifecycleState and reactors list, and the condition variable for awaiting group termination.


lifecycleState

protected int lifecycleState
The lifecycle state of this group. Increases monotonically. It may only be accessed with stateLock held.


RUNNING

protected static final int RUNNING
State: open and running

See Also:
Constant Field Values

SHUTDOWN

protected static final int SHUTDOWN
State: graceful shutdown in progress

See Also:
Constant Field Values

SHUTDOWN_NOW

protected static final int SHUTDOWN_NOW
State: forced shutdown in progress

See Also:
Constant Field Values

DONE

protected static final int DONE
State: terminated

See Also:
Constant Field Values

reactors

final List<Reactor> reactors
The active reactors in this group. It may only be accessed with stateLock held.


REACTORS_PROPERTY

public static final String REACTORS_PROPERTY
The property to specify the number of reactors to be used by channel groups: "com.sun.sgs.nio.async.reactive.reactors"

See Also:
Constant Field Values

DEFAULT_REACTORS

public static final int DEFAULT_REACTORS
The default number of reactors to be used by channel groups: Runtime.getRuntime().availableProcessors()


reactorAssignmentStrategy

final ReactiveChannelGroup.ReactorAssignmentStrategy reactorAssignmentStrategy
The reactor load-balance strategy.

Constructor Detail

ReactiveChannelGroup

ReactiveChannelGroup(ReactiveAsyncChannelProvider provider,
                     ExecutorService executor)
               throws IOException
Creates a new group with the default number of reactors.

Parameters:
provider - the provider that created this group
executor - the executor for this group
Throws:
IOException - if an I/O error occurs

ReactiveChannelGroup

ReactiveChannelGroup(ReactiveAsyncChannelProvider provider,
                     ExecutorService executor,
                     int requestedReactors)
               throws IOException
Creates a new group with the requested number of reactors. If {code 0} reactors are requested, a default is chosen as the number of available processors.

Parameters:
provider - the provider that created this group
executor - the executor for this group
requestedReactors - the number of reactors to create in this group, or 0 to use the default
Throws:
IllegalArgumentException - if a negative number of reactors is requested
IOException - if an I/O error occurs
Method Detail

register

AsyncKey register(SelectableChannel ch)
            throws IOException
Registers the given channel with this group, returning an AsyncKey that can be used to invoke asynchronous IO operations. If this group is shutdown, this method will throw ShutdownChannelGroupException and close the channel.

Specified by:
register in class AsyncGroupImpl
Parameters:
ch - the underlying channel for IO operations
Returns:
an AsyncKey that supports asynchronous operations on the underlying channel
Throws:
IOException - if an I/O error occurs

awaitTermination

public boolean awaitTermination(long timeout,
                                TimeUnit unit)
                         throws InterruptedException
Awaits termination of the group.

This method blocks until all channels in the group have been closed and all resources associated with the group have been released.

Specified by:
awaitTermination in class AsynchronousChannelGroup
Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
true if the group has terminated; false if the timeout elapsed before termination
Throws:
InterruptedException - if interrupted while waiting

isShutdown

public boolean isShutdown()
Tells whether or not this asynchronous channel group is shutdown.

Specified by:
isShutdown in class AsynchronousChannelGroup
Returns:
true if this asynchronous channel group is shutdown

isTerminated

public boolean isTerminated()
Tells whether or not this asynchronous channel group is terminated.

Specified by:
isTerminated in class AsynchronousChannelGroup
Returns:
true if this asynchronous channel group is terminated

shutdown

public ReactiveChannelGroup shutdown()
Initiates an orderly shutdown of the group.

This method marks the group as shutdown. Further attempts to construct a channel that binds to this group will throw ShutdownChannelGroupException. The group terminates when all asynchronous channels in the group are closed and all resources have been released. This method has no effect if the group is already shutdown.

Specified by:
shutdown in class AsynchronousChannelGroup
Returns:
this group

shutdownNow

public ReactiveChannelGroup shutdownNow()
                                 throws IOException
Shuts down the group and closes all open channels in the group.

In addition to the actions performed by the AsynchronousChannelGroup.shutdown() method, this method invokes the close method on all open channels in the group. This method does not attempt to stop actively executing completion handlers.

The group is likely to terminate quickly after invoking this method but there is no guarantee that the group has terminated on completion of this method.

Specified by:
shutdownNow in class AsynchronousChannelGroup
Returns:
this group
Throws:
IOException - if an I/O error occurs

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved