solar.service.transport
Class UdpTransport

java.lang.Object
  |
  +--solar.service.transport.UdpTransport
All Implemented Interfaces:
java.lang.Runnable, Transport, TransportConstants
Direct Known Subclasses:
UdpObjectTransport

public class UdpTransport
extends java.lang.Object
implements Transport, java.lang.Runnable, TransportConstants

The UDP transport layer, converting ADU to bytes for sending.

Version:
$Id: UdpTransport.java,v 1.17 2003/10/12 03:56:35 glchen Exp $
Author:
Guanling Chen

Field Summary
protected  AduFactory _aduFactory
          The factory to parse received byte array into ADU.
protected  java.lang.String _hostname
          Particular interface to bind to.
protected  Address _laddr
          The local address for UDP.
protected  java.util.List _listeners
          The list of transport listeners.
protected static org.apache.log4j.Logger _log
          Logging facility.
protected  int _port
          The listening server port.
protected  java.lang.Thread _receiver
          The receiver thread receiving new messages.
protected  java.net.DatagramSocket _ssock
          The socket to listen to.
 
Fields inherited from interface solar.service.transport.TransportConstants
PASTRY_ADDRESS, SOCKET_ADDRESS, TRANSPORT_PASTRY_PORT, TRANSPORT_TCP_PORT, TRANSPORT_UDP_MSS, TRANSPORT_UDP_PORT
 
Constructor Summary
UdpTransport()
           
UdpTransport(int port)
           
UdpTransport(java.lang.String hostname, int port)
           
 
Method Summary
 void addTransportListener(TransportListener listener)
          Add a transport listener.
 Address getAddressByKey(java.lang.String key)
          Return a peer address by specified key.
 Address getLocalAddress()
          Return the local address of this transport layer.
private  void notifyDataReceived(Adu adu, Header header)
          Notify transport listeners about received message.
 void removeTransportListener(TransportListener listener)
          Remove a transport listener.
 void run()
           
 void send(Adu adu, Address dest)
          Send the adu over transport to destination.
 void send(Adu adu, Address dest, Id multiplex)
          Send the adu over transport to destination, with a multipex ID.
 void send(byte[] data, Address dest)
          Send an data unit to destination address.
 void send(byte[] data, Address dest, Id multiplex)
          Send an data unit to destination address with a multiplexer.
 void setAduFactory(AduFactory factory)
          Set the factory that parse the received bytes into data unit.
private  void start()
          Start the UDP transport.
 void stop()
          Stop the transport layer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

protected static org.apache.log4j.Logger _log
Logging facility.


_hostname

protected java.lang.String _hostname
Particular interface to bind to.


_port

protected int _port
The listening server port.


_ssock

protected java.net.DatagramSocket _ssock
The socket to listen to.


_receiver

protected java.lang.Thread _receiver
The receiver thread receiving new messages.


_listeners

protected java.util.List _listeners
The list of transport listeners.


_laddr

protected Address _laddr
The local address for UDP.


_aduFactory

protected AduFactory _aduFactory
The factory to parse received byte array into ADU.

Constructor Detail

UdpTransport

public UdpTransport()
             throws java.lang.Exception

UdpTransport

public UdpTransport(int port)
             throws java.lang.Exception

UdpTransport

public UdpTransport(java.lang.String hostname,
                    int port)
             throws java.lang.Exception
Method Detail

setAduFactory

public void setAduFactory(AduFactory factory)
Description copied from interface: Transport
Set the factory that parse the received bytes into data unit.

Specified by:
setAduFactory in interface Transport

getLocalAddress

public Address getLocalAddress()
Description copied from interface: Transport
Return the local address of this transport layer.

Specified by:
getLocalAddress in interface Transport

getAddressByKey

public Address getAddressByKey(java.lang.String key)
                        throws TransportException
Description copied from interface: Transport
Return a peer address by specified key.

Specified by:
getAddressByKey in interface Transport
TransportException

send

public void send(byte[] data,
                 Address dest)
          throws TransportException
Description copied from interface: Transport
Send an data unit to destination address.

Specified by:
send in interface Transport
TransportException

send

public void send(byte[] data,
                 Address dest,
                 Id multiplex)
          throws TransportException
Description copied from interface: Transport
Send an data unit to destination address with a multiplexer.

Specified by:
send in interface Transport
TransportException

send

public void send(Adu adu,
                 Address dest)
          throws TransportException
Description copied from interface: Transport
Send the adu over transport to destination.

Specified by:
send in interface Transport
TransportException

send

public void send(Adu adu,
                 Address dest,
                 Id multiplex)
          throws TransportException
Description copied from interface: Transport
Send the adu over transport to destination, with a multipex ID.

Specified by:
send in interface Transport
TransportException

addTransportListener

public void addTransportListener(TransportListener listener)
Description copied from interface: Transport
Add a transport listener.

Specified by:
addTransportListener in interface Transport

removeTransportListener

public void removeTransportListener(TransportListener listener)
Description copied from interface: Transport
Remove a transport listener.

Specified by:
removeTransportListener in interface Transport

stop

public void stop()
Description copied from interface: Transport
Stop the transport layer.

Specified by:
stop in interface Transport

start

private void start()
            throws java.lang.Exception
Start the UDP transport.

java.lang.Exception

notifyDataReceived

private void notifyDataReceived(Adu adu,
                                Header header)
Notify transport listeners about received message.


run

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