org.simpleframework.transport.connect
Class SocketConnection

java.lang.Object
  extended by org.simpleframework.transport.connect.SocketConnection
All Implemented Interfaces:
Closeable, Connection

public class SocketConnection
extends Object
implements Connection

The SocketConnectionis used to manage connections from a server socket. In order to achieve this it spawns a task to listen for incoming connect requests. When a TCP connection request arrives it hands off the SocketChannel to the SocketProcessor which processes the request.

This handles connections from a ServerSocketChannel object so that features such as SSL can be used by a server that uses this package. The background acceptor process will terminate if the connection is closed.

Author:
Niall Gallagher
See Also:
SocketProcessor

Constructor Summary
SocketConnection(SocketProcessor processor)
          Constructor for the SocketConnection object.
SocketConnection(SocketProcessor processor, TraceAnalyzer analyzer)
          Constructor for the SocketConnection object.
 
Method Summary
 void close()
          This is used to close the connection and the server socket used to accept connections.
 SocketAddress connect(SocketAddress address)
          This creates a new background task that will listen to the specified ServerAddress for incoming TCP connect requests.
 SocketAddress connect(SocketAddress address, SSLContext context)
          This creates a new background task that will listen to the specified ServerAddress for incoming TCP connect requests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketConnection

public SocketConnection(SocketProcessor processor)
                 throws IOException
Constructor for the SocketConnection object. This will create a new connection that accepts incoming connections and hands these connections as Socket objects to the specified connector. This in turn will deliver request and response objects to the internal container.

Parameters:
processor - this is the connector that receives requests
Throws:
IOException

SocketConnection

public SocketConnection(SocketProcessor processor,
                        TraceAnalyzer analyzer)
                 throws IOException
Constructor for the SocketConnection object. This will create a new connection that accepts incoming connections and hands these connections as Socket objects to the specified processor. This in turn will deliver request and response objects to the internal container.

Parameters:
processor - this is the connector that receives requests
analyzer - this is used to create a trace for the socket
Throws:
IOException
Method Detail

connect

public SocketAddress connect(SocketAddress address)
                      throws IOException
This creates a new background task that will listen to the specified ServerAddress for incoming TCP connect requests. When an connection is accepted it is handed to the internal socket connector.

Specified by:
connect in interface Connection
Parameters:
address - this is the address used to accept connections
Returns:
this returns the actual local address that is used
Throws:
IOException

connect

public SocketAddress connect(SocketAddress address,
                             SSLContext context)
                      throws IOException
This creates a new background task that will listen to the specified ServerAddress for incoming TCP connect requests. When an connection is accepted it is handed to the internal socket connector.

Specified by:
connect in interface Connection
Parameters:
address - this is the address used to accept connections
context - this is used for secure SSL connections
Returns:
this returns the actual local address that is used
Throws:
IOException

close

public void close()
           throws IOException
This is used to close the connection and the server socket used to accept connections. This will perform a close of all connected server sockets that have been created from using the connect method. The connection can be reused after the existing server sockets have been closed.

Specified by:
close in interface Closeable
Throws:
IOException - thrown if there is a problem closing


Copyright © 2014. All Rights Reserved.