solar.service.transport
Class TcpConnection

java.lang.Object
  |
  +--solar.service.transport.TcpConnection
All Implemented Interfaces:
java.lang.Runnable

class TcpConnection
extends java.lang.Object
implements java.lang.Runnable

The connection between two TCP peers.

Version:
$Id: TcpConnection.java,v 1.3 2003/10/12 00:58:39 glchen Exp $
Author:
Guanling Chen

Field Summary
private  AduFactory _aduFactory
           
private  java.io.DataInputStream _datain
           
private  java.io.DataOutputStream _dataout
           
private  java.io.DataInput _in
           
private  java.io.ObjectInputStream _objin
           
private  java.io.ObjectOutputStream _objout
           
private  java.io.DataOutput _out
           
private  SocketAddress _peer
          The peer address.
private  java.lang.Thread _receiver
          The thread receiving messages from this connection.
private  boolean _serialize
           
private  java.net.Socket _sock
          The local socket for the connection.
private  TcpTransport _transport
           
private  byte[] COOKIE
          The cookie identifying our protocol handshake.
 
Constructor Summary
TcpConnection(boolean serialize, java.net.Socket sock, SocketAddress peer)
          Constructs a new connection from a local connected socket.
 
Method Summary
 void destroy()
          Destory this connection.
private  void doSend(Adu adu, Header header)
           
 void init(TcpTransport transport)
          Initialize this connection.
private  void initCookie(byte[] c)
           
private  boolean matchCookie(byte[] cookie)
           
 SocketAddress receivePeerAddress()
          Receive peer address from this connection.
 void run()
           
 void send(Adu adu, Header header)
          Send a message through this connection.
 void send(byte[] data, Header header)
          Send a message through this connection.
 void sendLocalAddress(SocketAddress addr)
          Send local address to peer through this connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COOKIE

private final byte[] COOKIE
The cookie identifying our protocol handshake.


_sock

private java.net.Socket _sock
The local socket for the connection.


_peer

private SocketAddress _peer
The peer address.


_receiver

private java.lang.Thread _receiver
The thread receiving messages from this connection.


_datain

private java.io.DataInputStream _datain

_dataout

private java.io.DataOutputStream _dataout

_objin

private java.io.ObjectInputStream _objin

_objout

private java.io.ObjectOutputStream _objout

_in

private java.io.DataInput _in

_out

private java.io.DataOutput _out

_serialize

private boolean _serialize

_aduFactory

private AduFactory _aduFactory

_transport

private TcpTransport _transport
Constructor Detail

TcpConnection

public TcpConnection(boolean serialize,
                     java.net.Socket sock,
                     SocketAddress peer)
              throws java.lang.Exception
Constructs a new connection from a local connected socket.

Method Detail

init

public void init(TcpTransport transport)
Initialize this connection.


destroy

public void destroy()
Destory this connection.


receivePeerAddress

public SocketAddress receivePeerAddress()
                                 throws java.lang.Exception
Receive peer address from this connection.

java.lang.Exception

sendLocalAddress

public void sendLocalAddress(SocketAddress addr)
                      throws java.lang.Exception
Send local address to peer through this connection.

java.lang.Exception

send

public void send(byte[] data,
                 Header header)
          throws java.lang.Exception
Send a message through this connection.

java.lang.Exception

send

public void send(Adu adu,
                 Header header)
          throws java.lang.Exception
Send a message through this connection.

java.lang.Exception

doSend

private void doSend(Adu adu,
                    Header header)
             throws java.lang.Exception
java.lang.Exception

initCookie

private void initCookie(byte[] c)

matchCookie

private boolean matchCookie(byte[] cookie)

run

public void run()
Specified by:
run in interface java.lang.Runnable