|
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.lang.Thread
org.jppf.server.nio.NioServer<S,T>
S - the type of the states to use.T - the type of the transitions to use.public abstract class NioServer<S extends Enum<S>,T extends Enum<T>>
Generic server for non-blocking asynchronous socket channel based communications.
Instances of this class rely on a number of possible states for each socket channel,
along with the possible transitions between thoses states.
The design of this class enforces the use of typesafe enumerations for the states
and transitions, so the developers must think ahead of how to implement their server
as a state machine.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
Thread.State, Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
static String |
CLASS_SERVER
Name of the class server. |
protected NioServerFactory<S,T> |
factory
The factory for this server. |
protected ReentrantLock |
lock
Lock used to synchronize selector operations. |
static String |
NODE_SERVER
Name of the class server. |
protected int[] |
ports
The ports this server is listening to. |
protected ResourceProvider |
resourceProvider
Reads resource files from the classpath. |
protected Selector |
selector
the selector of all socket channels open with providers or nodes. |
protected long |
selectTimeout
Timeout for the select() operations. |
protected StateTransitionManager<S,T> |
transitionManager
Performs all operations that relate to channel states. |
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
|
NioServer(int[] ports,
String name,
boolean sequential)
Initialize this server with a specified list of port numbers and name. |
|
NioServer(int port,
String name)
Initialize this server with a specified port number and name. |
protected |
NioServer(String name)
Initialize this server with a specified port number and name. |
protected |
NioServer(String name,
boolean sequential)
Initialize this server with a specified port number and name. |
| Method Summary | |
|---|---|
protected abstract NioServerFactory<S,T> |
createFactory()
Create the factory holding all the states and transition mappings. |
abstract NioContext<?> |
createNioContext()
Define a context for a newly created channel. |
void |
end()
Close the underlying server socket and stop this socket server. |
protected boolean |
externalStopCondition()
Determine whether a stop condition external to this server has been reached. |
NioServerFactory<S,T> |
getFactory()
Get the factory for this server. |
abstract int |
getInitialInterest()
Get the IO operations a connection is initially interested in. |
ReentrantLock |
getLock()
Get the lock used to synchronize selector operations. |
int[] |
getPorts()
Get the ports this server is listening to. |
Selector |
getSelector()
Get the selector for this server. |
StateTransitionManager<S,T> |
getTransitionManager()
Get the manager that performs all operations that relate to channel states. |
void |
go(Set<SelectionKey> selectedKeys)
Process the keys selected by the selector for IO operations. |
protected void |
init(int[] ports)
Initialize the underlying server socket with a specified port. |
protected boolean |
isStopped()
Get the stopped state of this server. |
abstract void |
postAccept(ChannelWrapper<?> key)
Process a channel that was accepted by the server socket channel. |
void |
postAccept(ChannelWrapper<?> key,
ServerSocketChannel serverChannel)
Process a channel that was accepted by the server socket channel. |
void |
postSelect()
This method is invoked after all selected keys have been processed. |
void |
removeAllConnections()
Close and remove all connections accepted by this server. |
void |
run()
Start the underlying server socket by making it accept incoming connections. |
protected void |
setStopped(boolean stopped)
Set this server in the specified stopped state. |
| 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 |
| Field Detail |
|---|
public static final String CLASS_SERVER
public static final String NODE_SERVER
protected Selector selector
protected ResourceProvider resourceProvider
protected int[] ports
protected long selectTimeout
Selector.select() will be invoked without parameters.
protected NioServerFactory<S extends Enum<S>,T extends Enum<T>> factory
protected ReentrantLock lock
protected StateTransitionManager<S extends Enum<S>,T extends Enum<T>> transitionManager
| Constructor Detail |
|---|
protected NioServer(String name)
throws JPPFException
name - the name given to this thread.
JPPFException - if the underlying server socket can't be opened.
protected NioServer(String name,
boolean sequential)
throws JPPFException
name - the name given to this thread.sequential - determines whether the submission of state transitions should be
performed sequentially or through the executor thread pool.
JPPFException - if the underlying server socket can't be opened.
public NioServer(int port,
String name)
throws JPPFException
port - the port this socket server is listening to.name - the name given to this thread.
JPPFException - if the underlying server socket can't be opened.
public NioServer(int[] ports,
String name,
boolean sequential)
throws JPPFException
ports - the list of port this server accepts connections from.name - the name given to this thread.sequential - Determines whether the submission of state transitions should be
performed sequentially or through the executor thread pool.
JPPFException - if the underlying server socket can't be opened.| Method Detail |
|---|
protected abstract NioServerFactory<S,T> createFactory()
NioServerFactory instance.
protected final void init(int[] ports)
throws JPPFException
ports - the port the underlying server listens to.
JPPFException - if the server socket can't be opened on the specified port.public void run()
run in interface Runnablerun in class ThreadRunnable.run()protected boolean externalStopCondition()
public void go(Set<SelectionKey> selectedKeys)
throws Exception
selectedKeys - the set of keys thast were selected by the latest select() invocation.
Exception - if an error is raised while processing the keys.public void postSelect()
public void postAccept(ChannelWrapper<?> key,
ServerSocketChannel serverChannel)
key - the selection key for the socket channel to process.serverChannel - the ServerSocketChannel that accepted the channel.public abstract void postAccept(ChannelWrapper<?> key)
key - the selection key for the socket channel to process.public abstract NioContext<?> createNioContext()
NioContext instance.public abstract int getInitialInterest()
SelectionKey
constants definitions.public void end()
public void removeAllConnections()
public Selector getSelector()
public NioServerFactory<S,T> getFactory()
NioServerFactory instance.public ReentrantLock getLock()
ReentrantLock instance.protected void setStopped(boolean stopped)
stopped - true if this server is stopped, false otherwise.protected boolean isStopped()
public StateTransitionManager<S,T> getTransitionManager()
StateTransitionManager instance.public int[] getPorts()
|
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||