Spring Integration

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

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

public class TcpNetConnection
extends AbstractTcpConnection

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.AbstractTcpConnection
connectionId, inputConverter, listener, logger, mapper, outputConverter, sender, server, singleUse
 
Constructor Summary
TcpNetConnection(Socket socket, boolean server)
          Constructs a TcpNetConnection for the socket.
 
Method Summary
 void close()
          Closes this connection.
 String getConnectionId()
           
 String getHostAddress()
           
 String getHostName()
           
 Object getPayload()
          Uses the input converter to obtain the message payload from the connection's input stream.
 int getPort()
           
 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.AbstractTcpConnection
getInputConverter, getListener, getMapper, getOutputConverter, isServer, isSingleUse, registerListener, registerSender, setInputConverter, setMapper, setOutputConverter, setSingleUse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TcpNetConnection

public TcpNetConnection(Socket socket,
                        boolean server)
Constructs a TcpNetConnection for the socket.

Parameters:
socket - the socket
server - if true this connection was created as a result of an incoming request.
Method Detail

close

public void close()
Closes this connection.

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

isOpen

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

send

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

Parameters:
message - The message
Throws:
Exception

getHostAddress

public String getHostAddress()
Returns:
the host address

getHostName

public String getHostName()
Returns:
the host name

getPayload

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

Returns:
The payload
Throws:
Exception

getPort

public int getPort()
Returns:
the port

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 InputStreamingConverter 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.


getConnectionId

public String getConnectionId()
Returns:
a string uniquely representing a connection.

Spring Integration

Copyright © 2010. All Rights Reserved.