Spring Integration

org.springframework.integration.ip.tcp.connection
Class TcpNetConnection

java.lang.Object
  extended by org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
      extended by org.springframework.integration.ip.tcp.connection.TcpNetConnection
All Implemented Interfaces:
java.lang.Runnable, TcpConnection

public class TcpNetConnection
extends TcpConnectionSupport

A TcpConnection that uses and underlying Socket.

Since:
2.0
Author:
Gary Russell

Field Summary
 
Fields inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
logger
 
Constructor Summary
TcpNetConnection(java.net.Socket socket, boolean server, boolean lookupHost)
          Deprecated. Use TcpNetConnection(Socket, boolean, boolean, ApplicationEventPublisher, String) TODO: Remove in 3.1/4.0
TcpNetConnection(java.net.Socket socket, boolean server, boolean lookupHost, org.springframework.context.ApplicationEventPublisher applicationEventPublisher, java.lang.String connectionFactoryName)
          Constructs a TcpNetConnection for the socket.
 
Method Summary
 void close()
          Closes this connection.
 java.lang.Object getDeserializerStateKey()
           
 java.lang.Object getPayload()
          Uses the deserializer to obtain the message payload from the connection's input stream.
 int getPort()
           
protected  boolean handleReadException(java.lang.Exception e)
           
 boolean isOpen()
           
 void run()
          If there is no listener, and this connection is not for single use, this method exits.
 void send(Message<?> message)
          Converts and sends the message.
 
Methods inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
afterSend, closeConnection, getConnectionId, getDeserializer, getHostAddress, getHostName, getListener, getMapper, getSender, getSerializer, incrementAndGetConnectionSequence, isServer, isSingleUse, publishConnectionCloseEvent, publishConnectionExceptionEvent, publishConnectionOpenEvent, publishEvent, registerListener, registerSender, setDeserializer, setMapper, setSerializer, setSingleUse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TcpNetConnection

@Deprecated
public TcpNetConnection(java.net.Socket socket,
                                   boolean server,
                                   boolean lookupHost)
Deprecated. Use TcpNetConnection(Socket, boolean, boolean, ApplicationEventPublisher, String) TODO: Remove in 3.1/4.0

Constructs a TcpNetConnection for the socket.

Parameters:
socket - the socket
server - if true this connection was created as a result of an incoming request.
lookupHost - true if hostname lookup should be performed, otherwise the connection will be identified using the ip address.

TcpNetConnection

public TcpNetConnection(java.net.Socket socket,
                        boolean server,
                        boolean lookupHost,
                        org.springframework.context.ApplicationEventPublisher applicationEventPublisher,
                        java.lang.String connectionFactoryName)
Constructs a TcpNetConnection for the socket.

Parameters:
socket - the socket
server - if true this connection was created as a result of an incoming request.
lookupHost - true if hostname lookup should be performed, otherwise the connection will be identified using the ip address.
applicationEventPublisher - the publisher to which OPEN, CLOSE and EXCEPTION events will be sent; may be null if event publishing is not required.
connectionFactoryName - the name of the connection factory creating this connection; used during event publishing, may be null, in which case "unknown" will be used.
Method Detail

close

public void close()
Closes this connection.

Specified by:
close in interface TcpConnection
Overrides:
close in class TcpConnectionSupport

isOpen

public boolean isOpen()
Returns:
true if the connection is open.

send

public void send(Message<?> message)
          throws java.lang.Exception
Description copied from interface: TcpConnection
Converts and sends the message.

Parameters:
message - The message
Throws:
java.lang.Exception

getPayload

public java.lang.Object getPayload()
                            throws java.lang.Exception
Description copied from interface: TcpConnection
Uses the deserializer to obtain the message payload from the connection's input stream.

Returns:
The payload
Throws:
java.lang.Exception

getPort

public int getPort()
Returns:
the port

getDeserializerStateKey

public java.lang.Object getDeserializerStateKey()
Returns:
a key that can be used to reference state in a Deserializer that maintains state for this connection. Currently, this would be the InputStream associated with the connection, but the object should be treated as opaque and ONLY used as a key.

run

public void run()
If there is no listener, and this connection is not for single use, this method exits. When there is a listener, the method runs in a loop reading input from the connections's stream, data is converted to an object using the Deserializer and the listener's TcpListener.onMessage(Message) method is called. For single use connections with no listener, the socket is closed after its timeout expires. If data is received on a single use socket with no listener, a warning is logged.


handleReadException

protected boolean handleReadException(java.lang.Exception e)

Spring Integration