Project JXTA

net.jxta.impl.endpoint.tcp
Class TcpTransport

java.lang.Object
  extended by net.jxta.impl.endpoint.tcp.TcpTransport
All Implemented Interfaces:
Runnable, MessageReceiver, MessageSender, MessageTransport, Module

public class TcpTransport
extends Object
implements Runnable, Module, MessageSender, MessageReceiver

This class implements the TCP Transport Protocol

See Also:
MessageTransport, MessageSender, MessageReceiver, EndpointService, JXTA Protocols Specification : Standard JXTA Transport Bindings

Nested Class Summary
(package private) static class TcpTransport.Watcher
          TimerTask used to watch over connections.
 
Field Summary
(package private) static int ChunkSize
          The number of bytes that we write to/read from a socket in a single write/read call.
(package private) static int connectionTimeOut
          The amount of time we wait for a connection to be established (effective with jdk 1.4 only).
(package private)  Timer connectionWatchTimer
           
(package private)  EndpointService endpoint
           
(package private)  PeerGroup group
           
(package private) static int LingerDelay
          The amount of time the socket "lingers" after we close it locally.
(package private)  List LongCycle
           
(package private) static int LongTimeout
          Amount of time our input stream will wait for any kind of progress on input before declaring that input has stalled.
(package private) static int MaxAcceptCnxBacklog
           
(package private)  ThreadGroup myThreadGroup
          This is the thread group into which we will place all of the threads we create.
(package private) static int RecvBufferSize
          The buffer size that we instruct TCP to use for incoming data.
(package private) static int SendBufferSize
          The size of the buffer that we use to store message data being sent.
(package private)  List ShortCycle
           
(package private) static int ShortTimeout
          Amount of time our input stream will wait for any kind of progress on input before declaring that input has stalled.
(package private)  InetAddress usingInterface
           
 
Fields inherited from interface net.jxta.platform.Module
START_AGAIN_PROGRESS, START_AGAIN_STALLED, START_OK
 
Constructor Summary
TcpTransport()
          Construct a new TCPTransport instance
 
Method Summary
 boolean allowsRouting()
          
 boolean equals(Object target)
          
 EndpointService getEndpointService()
          
 Messenger getMessenger(EndpointAddress dst, Object hintIgnored)
          
(package private)  TransportBindingMeter getMulticastTransportBindingMeter(EndpointAddress destinationAddress)
           
 String getProtocolName()
          
 EndpointAddress getPublicAddress()
          
 Iterator getPublicAddresses()
          
(package private)  int getRestrictionPort()
           
(package private)  TransportBindingMeter getUnicastTransportBindingMeter(PeerID peerID, EndpointAddress destinationAddress)
           
 int hashCode()
          
 void init(PeerGroup g, ID assignedID, Advertisement impl)
          Initialization of the TcpTransport (called by Platform)
 boolean isConnectionOriented()
          
 boolean isPropagateEnabled()
          (@inheritdoc}
 boolean isPropagationSupported()
          (@inheritdoc}
(package private)  void messengerReadyEvent(Messenger newMessenger, EndpointAddress connAddr)
           
 boolean ping(EndpointAddress addr)
          Ping a remote host.
 void processMulticast(byte[] buffer, int size)
          Handle a byte buffer from a multi-cast.
 void propagate(Message message, String pName, String pParams, String prunePeer)
          Propagates a TransportMessage on this EndpointProtocol

Synchronizing to not allow concurrent IP multicast: this naturally bounds the usage of ip-multicast boolean be linear and not exponantial.

 void run()
          Handles incoming multicasts.
 int startApp(String[] arg)
          
 void stopApp()
          
 Object transportControl(Object operation, Object Value)
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SendBufferSize

static final int SendBufferSize
The size of the buffer that we use to store message data being sent. Make it the maximum size of a message. (smaller is permitted, though).

See Also:
Constant Field Values

ChunkSize

static final int ChunkSize
The number of bytes that we write to/read from a socket in a single write/read call. Keep this reasonably small since it defines the precision at which we monitor progress. With 8K, any write/read will complete in at most 1 second on a 64Kbit/s connection. Watched Stream start worrying after 10 seconds, so this will still work for connections as slow as 6Kbit/s. Note that we monitor progress of read only when we know data is expected.

See Also:
Constant Field Values

RecvBufferSize

static final int RecvBufferSize
The buffer size that we instruct TCP to use for incoming data. One full message.

See Also:
Constant Field Values

LongTimeout

static final int LongTimeout
Amount of time our input stream will wait for any kind of progress on input before declaring that input has stalled. This one is for when we're just waiting for a message to come in. So we'll close the connection if it seems to be unused for quite a long time. WatchedOutputStream breaks writes in small enough chunks that progress can be reliably measured with a resolution of a few seconds.

See Also:
Constant Field Values

ShortTimeout

static final int ShortTimeout
Amount of time our input stream will wait for any kind of progress on input before declaring that input has stalled. This one is for when we know data should be comming. Amount of time our output stream will wait for any kind of progress during a write() before declaring that the output has stalled.

See Also:
Constant Field Values

LingerDelay

static final int LingerDelay
The amount of time the socket "lingers" after we close it locally. Linger enables the remote socket to finish receiving any pending data at its own rate.

See Also:
Constant Field Values

connectionTimeOut

static int connectionTimeOut
The amount of time we wait for a connection to be established (effective with jdk 1.4 only). We go get the same system property than URLconnection and default to 20 seconds.


MaxAcceptCnxBacklog

static final int MaxAcceptCnxBacklog
See Also:
Constant Field Values

ShortCycle

List ShortCycle

LongCycle

List LongCycle

usingInterface

InetAddress usingInterface

group

PeerGroup group

endpoint

EndpointService endpoint

myThreadGroup

ThreadGroup myThreadGroup
This is the thread group into which we will place all of the threads we create. THIS HAS NO EFFECT ON SCHEDULING. Java thread groups are only for organization and naming.


connectionWatchTimer

final Timer connectionWatchTimer
Constructor Detail

TcpTransport

public TcpTransport()
Construct a new TCPTransport instance

Method Detail

equals

public boolean equals(Object target)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

init

public void init(PeerGroup g,
                 ID assignedID,
                 Advertisement impl)
          throws PeerGroupException
Initialization of the TcpTransport (called by Platform)

Specified by:
init in interface Module
Throws:
PeerGroupException

startApp

public int startApp(String[] arg)

Specified by:
startApp in interface Module

stopApp

public void stopApp()

Specified by:
stopApp in interface Module

getProtocolName

public String getProtocolName()

Specified by:
getProtocolName in interface MessageTransport

getPublicAddress

public EndpointAddress getPublicAddress()

Specified by:
getPublicAddress in interface MessageSender

getEndpointService

public EndpointService getEndpointService()

Specified by:
getEndpointService in interface MessageTransport

transportControl

public Object transportControl(Object operation,
                               Object Value)

Specified by:
transportControl in interface MessageTransport

getPublicAddresses

public Iterator getPublicAddresses()

Specified by:
getPublicAddresses in interface MessageReceiver

isConnectionOriented

public boolean isConnectionOriented()

Specified by:
isConnectionOriented in interface MessageSender

allowsRouting

public boolean allowsRouting()

Specified by:
allowsRouting in interface MessageSender

getMessenger

public Messenger getMessenger(EndpointAddress dst,
                              Object hintIgnored)

Specified by:
getMessenger in interface MessageSender

run

public void run()
Handles incoming multicasts.

Specified by:
run in interface Runnable

processMulticast

public void processMulticast(byte[] buffer,
                             int size)
Handle a byte buffer from a multi-cast. This assumes that processing of the buffer is lightweight. Formerly there used to be a delegation to worker threads. The way queuing works has changed though and it should be ok to do the receiver right on the server thread.

Parameters:
buffer - the buffer to process.

isPropagateEnabled

public boolean isPropagateEnabled()
(@inheritdoc}

Specified by:
isPropagateEnabled in interface MessageSender

isPropagationSupported

public boolean isPropagationSupported()
(@inheritdoc}

Specified by:
isPropagationSupported in interface MessageSender

propagate

public void propagate(Message message,
                      String pName,
                      String pParams,
                      String prunePeer)
               throws IOException
Propagates a TransportMessage on this EndpointProtocol

Synchronizing to not allow concurrent IP multicast: this naturally bounds the usage of ip-multicast boolean be linear and not exponantial.

Specified by:
propagate in interface MessageSender
Parameters:
message - the TransportMessage to be propagated
pName - the name of a service
pParams - parameters for this message.
prunePeer - (ignored)
Throws:
IOException - thrown if the message could not be sent for some reason.

ping

public boolean ping(EndpointAddress addr)
Ping a remote host. This implementation tries to open a connection, and after tests the result. Note if there is already an open connection, no new connection is actually created.

Specified by:
ping in interface MessageSender
Parameters:
addr - the endpoint addresss to ping
Returns:
true if the address is reachable, otherwise false.

getRestrictionPort

int getRestrictionPort()

getUnicastTransportBindingMeter

TransportBindingMeter getUnicastTransportBindingMeter(PeerID peerID,
                                                      EndpointAddress destinationAddress)

getMulticastTransportBindingMeter

TransportBindingMeter getMulticastTransportBindingMeter(EndpointAddress destinationAddress)

messengerReadyEvent

void messengerReadyEvent(Messenger newMessenger,
                         EndpointAddress connAddr)

JXTA J2SE