Class SocketAcceptor
java.lang.Object
org.simpleframework.transport.connect.SocketAcceptor
The
SocketAcceptor
object is used to accept incoming
TCP connections from a specified socket address. This is used by
the Connection
object as a background process to
accept the connections and hand them to a socket connector.
This is capable of processing SSL connections created by the internal server socket. All SSL connections are forced to finish the SSL handshake before being dispatched to the server. This ensures that there are no problems with reading the request.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SocketAddress
This is the local address to bind the listen socket to.private final TraceAnalyzer
This is the tracing analyzer used to trace accepted sockets.private final SSLContext
If provided the SSL context is used to create SSL engines.private final ServerSocketChannel
This is the server socket channel used to accept connections.private final SocketProcessor
The handler that manages the incoming TCP connections.private final ServerSocket
This is the server socket to bind the socket address to.private final Trace
This is used to collect trace events with the acceptor. -
Constructor Summary
ConstructorsConstructorDescriptionSocketAcceptor
(SocketAddress address, SocketProcessor processor, TraceAnalyzer analyzer) Constructor for theSocketAcceptor
object.SocketAcceptor
(SocketAddress address, SocketProcessor processor, TraceAnalyzer analyzer, SSLContext context) Constructor for theSocketAcceptor
object. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
accept()
The main processing done by this object is done using a thread calling therun
method.void
bind()
This is used to configure the server socket for non-blocking mode.void
cancel()
This is used to cancel the operation if the reactor decides to reject it for some reason.void
close()
This is used to close the server socket channel so that the port that it is bound to is released.private void
configure
(SocketChannel channel) This method is used to configure the accepted channel.This is used to acquire the local socket address that this is listening to.This is theSelectableChannel
which is used to determine if the operation should be executed.getTrace()
This is used to acquire the trace object that is associated with the operation.private void
pause()
This is used to throttle the acceptor when there is an error such as exhaustion of file descriptors.private void
process
(SocketChannel channel, Trace trace) This method is used to dispatch the socket for processing.private void
process
(SocketChannel channel, Trace trace, SSLEngine engine) This method is used to dispatch the socket for processing.void
run()
This is used to accept a new TCP connections.
-
Field Details
-
listener
This is the server socket channel used to accept connections. -
processor
The handler that manages the incoming TCP connections. -
socket
This is the server socket to bind the socket address to. -
context
If provided the SSL context is used to create SSL engines. -
analyzer
This is the tracing analyzer used to trace accepted sockets. -
address
This is the local address to bind the listen socket to. -
trace
This is used to collect trace events with the acceptor.
-
-
Constructor Details
-
SocketAcceptor
public SocketAcceptor(SocketAddress address, SocketProcessor processor, TraceAnalyzer analyzer) throws IOException Constructor for theSocketAcceptor
object. This accepts new TCP connections from the specified server socket. Each of the connections that is accepted is configured for performance for the application.- Parameters:
address
- this is the address to accept connections fromprocessor
- this is used to initiate the HTTP processinganalyzer
- this is the tracing analyzer to be used- Throws:
IOException
-
SocketAcceptor
public SocketAcceptor(SocketAddress address, SocketProcessor processor, TraceAnalyzer analyzer, SSLContext context) throws IOException Constructor for theSocketAcceptor
object. This accepts new TCP connections from the specified server socket. Each of the connections that is accepted is configured for performance for the applications.- Parameters:
address
- this is the address to accept connections fromprocessor
- this is used to initiate the HTTP processinganalyzer
- this is the tracing analyzer to be usedcontext
- this is the SSL context used for secure HTTPS- Throws:
IOException
-
-
Method Details
-
getAddress
This is used to acquire the local socket address that this is listening to. This required in case the socket address that is specified is an emphemeral address, that is an address that is assigned dynamically when a port of 0 is specified.- Returns:
- this returns the address for the listening address
-
getTrace
This is used to acquire the trace object that is associated with the operation. A trace object is used to collection details on what operations are being performed. For instance it may contain information relating to I/O events or errors. -
getChannel
This is theSelectableChannel
which is used to determine if the operation should be executed. If the channel is ready for a given I/O event it can be run. For instance if the operation is used to perform some form of read operation it can be executed when ready to read data from the channel.- Specified by:
getChannel
in interfaceOperation
- Returns:
- this returns the channel used to govern execution
-
bind
This is used to configure the server socket for non-blocking mode. It will also bind the server socket to the socket port specified in theSocketAddress
object. Once done the acceptor is ready to accept newly arriving connections.- Parameters:
address
- this is the server socket address to bind to- Throws:
IOException
-
run
public void run()This is used to accept a new TCP connections. When the socket is ready to accept a connection this method is invoked. It will then create a HTTP pipeline object using the accepted socket and if provided with anSSLContext
it will also provide anSSLEngine
which is handed to the processor to handle the HTTP requests. -
pause
private void pause()This is used to throttle the acceptor when there is an error such as exhaustion of file descriptors. This will prevent the CPU from being hogged by the acceptor on such occasions. If the thread can not be put to sleep then this will freeze. -
cancel
public void cancel()This is used to cancel the operation if the reactor decides to reject it for some reason. Typically this method will never be invoked as this operation never times out. However, should the reactor cancel the operation this will close the socket. -
accept
The main processing done by this object is done using a thread calling therun
method. Here the TCP connections are accepted from theServerSocketChannel
which creates the socket objects. Each socket is then encapsulated in to a pipeline and dispatched to the processor for processing.- Throws:
IOException
- if there is a problem accepting the socket
-
configure
This method is used to configure the accepted channel. This will disable Nagles algorithm to improve the performance of the channel, also this will ensure the accepted channel disables blocking to ensure that it works within the processor object.- Parameters:
channel
- this is the channel that is to be configured- Throws:
IOException
-
process
This method is used to dispatch the socket for processing. The socket will be configured and connected to the client, this will hand processing to theServer
which will create the pipeline instance used to wrap the socket object.- Parameters:
channel
- this is the connected socket to be processedtrace
- this is the trace to associate with the socket- Throws:
IOException
-
process
This method is used to dispatch the socket for processing. The socket will be configured and connected to the client, this will hand processing to theServer
which will create the pipeline instance used to wrap the socket object.- Parameters:
channel
- this is the connected socket to be processedtrace
- this is the trace to associate with the socketengine
- this is the SSL engine used for secure HTTPS- Throws:
IOException
-
close
This is used to close the server socket channel so that the port that it is bound to is released. This allows the acceptor to close off the interface to the server. Ensuring the socket is closed allows it to be recreated at a later point.- Throws:
IOException
- thrown if the socket can not be closed
-