org.jppf.server.nio.nodeserver
Class NodeNioServer

java.lang.Object
  extended by java.lang.Thread
      extended by org.jppf.server.nio.NioServer<NodeState,NodeTransition>
          extended by org.jppf.server.nio.nodeserver.NodeNioServer
All Implemented Interfaces:
Runnable, EventListener, ReaperListener

public class NodeNioServer
extends NioServer<NodeState,NodeTransition>
implements ReaperListener

Instances of this class serve task execution requests to the JPPF nodes.

Author:
Laurent Cohen

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class org.jppf.server.nio.NioServer
CLASS_SERVER, factory, lock, NODE_SERVER, ports, resourceProvider, selector, selectTimeout, transitionManager
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
NodeNioServer(int port)
          Initialize this server with a specified port number.
NodeNioServer(int[] ports)
          Initialize this server with the specified port numbers.
 
Method Summary
 void addIdleChannel(ChannelWrapper<?> channel)
          Add a channel to the list of idle channels.
static void closeNode(ChannelWrapper<?> channel, AbstractNodeContext context)
          Close a connection to a node.
 void connectionFailed(ReaperEvent event)
          Called when the Reaper detects that a connection is broken.
protected  NioServerFactory<NodeState,NodeTransition> createFactory()
          Create the factory holding all the states and transition mappings.
 NioContext<?> createNioContext()
          Define a context for a newly created channel.
protected  boolean externalStopCondition()
          Determine whether a stop condition external to this server has been reached.
 Bundler getBundler()
          Get the algorithm that dynamically computes the task bundle size.
 JPPFBundlerFactory getBundlerFactory()
          Get the factory object used to create bundler instances.
 List<ChannelWrapper<?>> getIdleChannels()
          Get the list of currently idle channels.
 int getInitialInterest()
          Get the IO operations a connection is initially interested in.
protected  JPPFJobManager getJobManager()
          Get a reference to the driver's job manager.
protected  JPPFQueue getQueue()
          Get a reference to the driver's tasks queue.
 void initLocalChannel(ChannelWrapper<?> localChannel)
          Initialize the local channel connection.
 void postAccept(ChannelWrapper<?> channel)
          Process a channel that was accepted by the server socket channel.
 ChannelWrapper<?> removeIdleChannel(ChannelWrapper<?> channel)
          Remove a channel from the list of idle channels.
 ChannelWrapper<?> removeIdleChannel(int index)
          Remove the channel at the specified index from the list of idle channels.
 void setBundler(Bundler bundler)
          Set the algorithm that dynamically computes the task bundle size.
 
Methods inherited from class org.jppf.server.nio.NioServer
end, getFactory, getLock, getPorts, getSelector, getTransitionManager, go, init, isStopped, postAccept, postSelect, removeAllConnections, run, setStopped
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NodeNioServer

public NodeNioServer(int port)
              throws Exception
Initialize this server with a specified port number.

Parameters:
port - the port this socket server is listening to.
Throws:
Exception - if the underlying server socket can't be opened.

NodeNioServer

public NodeNioServer(int[] ports)
              throws Exception
Initialize this server with the specified port numbers.

Parameters:
ports - the ports this socket server is listening to.
Throws:
Exception - if the underlying server socket can't be opened.
Method Detail

initLocalChannel

public void initLocalChannel(ChannelWrapper<?> localChannel)
Initialize the local channel connection.

Parameters:
localChannel - the local channel to use.

createFactory

protected NioServerFactory<NodeState,NodeTransition> createFactory()
Create the factory holding all the states and transition mappings.

Specified by:
createFactory in class NioServer<NodeState,NodeTransition>
Returns:
an NioServerFactory instance.

externalStopCondition

protected boolean externalStopCondition()
Determine whether a stop condition external to this server has been reached. The default implementation always returns false.
Subclasses may override this behavior.

Overrides:
externalStopCondition in class NioServer<NodeState,NodeTransition>
Returns:
true if this server should be stopped, false otherwise.

postAccept

public void postAccept(ChannelWrapper<?> channel)
Process a channel that was accepted by the server socket channel.

Specified by:
postAccept in class NioServer<NodeState,NodeTransition>
Parameters:
channel - the selection key for the socket channel to process.

addIdleChannel

public void addIdleChannel(ChannelWrapper<?> channel)
Add a channel to the list of idle channels.

Parameters:
channel - the channel to add to the list.

removeIdleChannel

public ChannelWrapper<?> removeIdleChannel(ChannelWrapper<?> channel)
Remove a channel from the list of idle channels.

Parameters:
channel - the channel to remove from the list.
Returns:
a reference to the removed channel.

removeIdleChannel

public ChannelWrapper<?> removeIdleChannel(int index)
Remove the channel at the specified index from the list of idle channels.

Parameters:
index - the index of the channel to remove from the list.
Returns:
a reference to the removed channel.

createNioContext

public NioContext<?> createNioContext()
Define a context for a newly created channel.

Specified by:
createNioContext in class NioServer<NodeState,NodeTransition>
Returns:
an NioContext instance.
See Also:
NioServer.createNioContext()

getInitialInterest

public int getInitialInterest()
Get the IO operations a connection is initially interested in.

Specified by:
getInitialInterest in class NioServer<NodeState,NodeTransition>
Returns:
a bit-wise combination of the interests, taken from SelectionKey constants definitions.
See Also:
NioServer.getInitialInterest()

closeNode

public static void closeNode(ChannelWrapper<?> channel,
                             AbstractNodeContext context)
Close a connection to a node.

Parameters:
channel - a SocketChannel that encapsulates the connection.
context - the context data associated with the channel.

getBundler

public Bundler getBundler()
Get the algorithm that dynamically computes the task bundle size.

Returns:
a Bundler instance.

setBundler

public void setBundler(Bundler bundler)
Set the algorithm that dynamically computes the task bundle size.

Parameters:
bundler - a Bundler instance.

getQueue

protected JPPFQueue getQueue()
Get a reference to the driver's tasks queue.

Returns:
a JPPFQueue instance.

getJobManager

protected JPPFJobManager getJobManager()
Get a reference to the driver's job manager.

Returns:
a JPPFQueue instance.

getBundlerFactory

public JPPFBundlerFactory getBundlerFactory()
Get the factory object used to create bundler instances.

Returns:
an instance of JPPFBundlerFactory.

getIdleChannels

public List<ChannelWrapper<?>> getIdleChannels()
Get the list of currently idle channels.

Returns:
a list of SelectableChannel instances.

connectionFailed

public void connectionFailed(ReaperEvent event)
Called when the Reaper detects that a connection is broken.

Specified by:
connectionFailed in interface ReaperListener
Parameters:
event - encapsulates the server-side connection to a remote peer.


Copyright © 2005-2010 JPPF Team.