Package org.jppf.nio.acceptor
Class AcceptorNioServer
- All Implemented Interfaces:
Runnable
Instances of this class serve task execution requests to the JPPF nodes.
- Author:
- Laurent Cohen
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jppf.nio.StatelessNioServer
StatelessNioServer.ContextAction<C extends AbstractNioContext>, StatelessNioServer.ContextFilter<C extends AbstractNioContext>, StatelessNioServer.KeysetHandler<C extends AbstractNioContext>Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int[]The ports this server is listening to.protected final Map<Integer,ServerSocketChannel> List of opened server socket channels.protected int[]The SSL ports this server is listening to.Fields inherited from class org.jppf.nio.StatelessNioServer
acceptHandler, messageReader, messageWriter, readHandler, writeHandlerFields inherited from class org.jppf.nio.NioServer
attachment, configuration, identifier, requestShutdown, selecting, selector, selectTimeout, sslContext, sslHelper, stopped, sync, wakeUpActionFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionAcceptorNioServer(int[] ports, int[] sslPorts, JPPFStatistics stats, TypedProperties configuration) Initialize this server with the specified port numbers. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(ServerSocketChannel serverSocketChannel, SocketChannel channel, SSLHandler sslHandler, boolean ssl, boolean peer, Object... params) Register an incoming connection with this server's selector.booleanInitialize the underlying server sockets for the spcified array of ports.createNioContext(Object... params) Define a context for a newly created channel.protected voiddoAccept(SelectionKey key) accept the incoming connection.voidend()Close the underlying server socket and stop this socket server.int[]getPorts()Get the ports this server is listening to.int[]Get the SSL ports this server is listening to.getStats()protected voidhandleRead(SelectionKey key) Called when a selection key is selected andreadable.protected voidCalled when a selection key iswritable.protected voidhandleWrite(SelectionKey key) Called when a selection key is selected andwritable.protected voidinit()Initialize the underlying server sockets.protected voidprotected voidInitialize the message reader and writer.voidClose and remove all connections accepted by this server.voidremoveServer(int port) Remove the server identified by the local port it is listening to.Methods inherited from class org.jppf.nio.StatelessNioServer
doOperation, getAllContexts, go, isKeyValid, performContextAction, registerChannel, run, toString, toString, updateInterestOps, updateInterestOpsNoWakeupMethods inherited from class org.jppf.nio.NioServer
configurePeerSSL, configureSSLEngine, createSSLContext, externalStopCondition, getConfiguration, getIdentifier, getSelector, isStopped, setConfiguration, shutdown, wakeUpSelectorIfNeededMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, yield
-
Field Details
-
ports
protected int[] portsThe ports this server is listening to. -
sslPorts
protected int[] sslPortsThe SSL ports this server is listening to. -
servers
List of opened server socket channels.
-
-
Constructor Details
-
AcceptorNioServer
public AcceptorNioServer(int[] ports, int[] sslPorts, JPPFStatistics stats, TypedProperties configuration) throws Exception Initialize this server with the specified port numbers.- Parameters:
ports- the ports this socket server is listening to.sslPorts- the SSL ports this socket server is listening to.stats- the statsistics to update, if any.configuration- the JPPF configuration to use.- Throws:
Exception- if the underlying server socket can't be opened.
-
-
Method Details
-
init
Initialize the underlying server sockets.- Overrides:
initin classStatelessNioServer<AcceptorContext>- Throws:
Exception- if any error occurs while initializing the server sockets.
-
handleRead
Description copied from class:StatelessNioServerCalled when a selection key is selected andreadable.- Overrides:
handleReadin classStatelessNioServer<AcceptorContext>- Parameters:
key- the key to handle.- Throws:
Exception- if any error occurs.
-
handleWrite
Description copied from class:StatelessNioServerCalled when a selection key is selected andwritable.- Overrides:
handleWritein classStatelessNioServer<AcceptorContext>- Parameters:
key- the key to handle.- Throws:
Exception- if any error occurs.
-
handleSelectionException
Description copied from class:StatelessNioServerCalled when a selection key iswritable.- Specified by:
handleSelectionExceptionin classStatelessNioServer<AcceptorContext>- Parameters:
key- the key to handle.e- the exception to handle.
-
doAccept
Description copied from class:NioServeraccept the incoming connection. It accept and put it in a state to define what type of peer is. -
accept
public void accept(ServerSocketChannel serverSocketChannel, SocketChannel channel, SSLHandler sslHandler, boolean ssl, boolean peer, Object... params) throws Exception Register an incoming connection with this server's selector. The channel is registered with an empty set of initial interest operations, which means a call to the correspondingSelectionKey'sinterestOps()method will return 0.- Specified by:
acceptin classNioServer- Parameters:
serverSocketChannel- the server socket channel accepting the connection.channel- the socket channel representing the connection.sslHandler- an sslEngine eventually passed on from a different server.ssl- specifies whether anSSLHandlershould be initialized for the channel.peer- specifiies whether the channel is for a peer driver.params- optional parameters.- Throws:
Exception- if any error occurs.
-
createNioContext
Description copied from class:NioServerDefine a context for a newly created channel.- Specified by:
createNioContextin classNioServer- Parameters:
params- optional parameters.- Returns:
- an
NioContextinstance.
-
addServer
public boolean addServer(int portToInit, boolean ssl, Map<String, ?> env, boolean retryOnException) throws ExceptionDescription copied from class:NioServerInitialize the underlying server sockets for the spcified array of ports. This implementation throws aJPPFUnsupportedOperationException, it should be overriden by subclasses for a different outcome.- Overrides:
addServerin classNioServer- Parameters:
portToInit- the array of ports to initiialize.ssl-trueif the server sockets should be initialized with SSL enabled,falseotherwise.env- optional map of parameters to associate with the server socket channel.retryOnException- whether to retry if an exception occurs when binding the server.- Returns:
trueifd a new server was created,falseotherwxise.- Throws:
Exception- if any error occurs while initializing the server sockets.
-
removeServer
Remove the server identified by the local port it is listening to.- Overrides:
removeServerin classNioServer- Parameters:
port- the port the sever is listening to.- Throws:
IOException- if any error occurs closing the specified server socket channel.
-
removeAllConnections
public void removeAllConnections()Description copied from class:NioServerClose and remove all connections accepted by this server.- Overrides:
removeAllConnectionsin classNioServer
-
getPorts
public int[] getPorts()Get the ports this server is listening to.- Returns:
- an array of int values.
-
getSSLPorts
public int[] getSSLPorts()Get the SSL ports this server is listening to.- Returns:
- an array of int values.
-
getStats
- Returns:
- the statistics to update, if any.
-
initReaderAndWriter
protected void initReaderAndWriter()Description copied from class:StatelessNioServerInitialize the message reader and writer.- Specified by:
initReaderAndWriterin classStatelessNioServer<AcceptorContext>
-
initNioHandlers
protected void initNioHandlers()- Overrides:
initNioHandlersin classStatelessNioServer<AcceptorContext>
-
end
public void end()Description copied from class:NioServerClose the underlying server socket and stop this socket server.
-