JXTA

net.jxta.impl.endpoint.relay
Class RelayTransport

java.lang.Object
  extended by net.jxta.impl.endpoint.relay.RelayTransport
All Implemented Interfaces:
EndpointListener, Module

public final class RelayTransport
extends Object
implements EndpointListener, Module

The Relay Server supports the following commands: CONNECT - message contains PEERID, optional LEASE DISCONNECT - message contains PEERID. GETSERVER - message contains PEERID.


Field Summary
(package private) static String CONNECT_REQUEST
           
(package private) static MessageElement CONNECT_REQUEST_ELEMENT
           
(package private) static String CONNECTED_RESPONSE
           
(package private) static MessageElement CONNECTED_RESPONSE_ELEMENT
           
(package private) static long DEFAULT_BROADCAST_INTERVAL
           
(package private) static int DEFAULT_CLIENT_QUEUE_SIZE
           
(package private) static long DEFAULT_LEASE
           
(package private) static int DEFAULT_MAX_CLIENTS
           
(package private) static int DEFAULT_MAX_SERVERS
           
(package private) static long DEFAULT_POLL_INTERVAL
           
(package private) static long DEFAULT_STALL_TIMEOUT
           
(package private) static String DISCONNECT_REQUEST
           
(package private) static MessageElement DISCONNECT_REQUEST_ELEMENT
           
(package private) static String DISCONNECTED_RESPONSE
           
(package private) static MessageElement DISCONNECTED_RESPONSE_ELEMENT
           
(package private) static String LEASE_ELEMENT
           
(package private) static String PEERID_ELEMENT
           
(package private) static String PID_REQUEST
           
(package private) static MessageElement PID_REQUEST_ELEMENT
           
(package private) static String PID_RESPONSE
           
(package private) static MessageElement PID_RESPONSE_ELEMENT
           
(package private) static String protocolName
           
(package private) static String RELAY_ADV_ELEMENT
           
(package private) static String RELAY_NS
           
(package private) static String REQUEST_ELEMENT
           
(package private) static String RESPONSE_ELEMENT
           
 
Fields inherited from interface net.jxta.platform.Module
START_AGAIN_PROGRESS, START_AGAIN_STALLED, START_DISABLED, START_OK
 
Constructor Summary
RelayTransport()
           
 
Method Summary
(package private) static Message createConnectedMessage(long lease)
           
(package private) static Message createConnectMessage(long lease, boolean doReturnAdv, boolean doFlushQueue)
           
(package private) static String createConnectString(long lease, boolean doReturnAdv, boolean doFlushQueue)
           
(package private) static Message createDisconnectedMessage()
           
(package private) static Message createDisconnectMessage()
           
(package private) static Message createPIDRequestMessage()
           
(package private) static Message createPIDResponseMessage(String pidStr)
           
protected  PeerGroup getGroup()
           
protected  String getServiceName()
           
(package private) static String getString(Message message, String elementName)
          Convinence function for getting a String from the element with the given tag and relay namespace
 void init(PeerGroup group, ID assignedID, Advertisement implAdv)
          Initialize the module, passing it its peer group and advertisement.
 void processIncomingMessage(Message message, EndpointAddress srcAddr, EndpointAddress dstAddr)
          This method is invoked by the EndpointService for each incoming message which is addressed to this listener.
(package private) static void setString(Message message, String elementName, String value)
          Convinence function for setting a string element with the relay namespace
 int startApp(String[] args)
          Complete any remaining initialization of the module.
 void stopApp()
          Stop a module.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

protocolName

static final String protocolName
See Also:
Constant Field Values

RELAY_NS

static final String RELAY_NS
See Also:
Constant Field Values

REQUEST_ELEMENT

static final String REQUEST_ELEMENT
See Also:
Constant Field Values

RESPONSE_ELEMENT

static final String RESPONSE_ELEMENT
See Also:
Constant Field Values

PEERID_ELEMENT

static final String PEERID_ELEMENT
See Also:
Constant Field Values

LEASE_ELEMENT

static final String LEASE_ELEMENT
See Also:
Constant Field Values

RELAY_ADV_ELEMENT

static final String RELAY_ADV_ELEMENT
See Also:
Constant Field Values

CONNECT_REQUEST

static final String CONNECT_REQUEST
See Also:
Constant Field Values

CONNECT_REQUEST_ELEMENT

static final MessageElement CONNECT_REQUEST_ELEMENT

DISCONNECT_REQUEST

static final String DISCONNECT_REQUEST
See Also:
Constant Field Values

DISCONNECT_REQUEST_ELEMENT

static final MessageElement DISCONNECT_REQUEST_ELEMENT

PID_REQUEST

static final String PID_REQUEST
See Also:
Constant Field Values

PID_REQUEST_ELEMENT

static final MessageElement PID_REQUEST_ELEMENT

CONNECTED_RESPONSE

static final String CONNECTED_RESPONSE
See Also:
Constant Field Values

CONNECTED_RESPONSE_ELEMENT

static final MessageElement CONNECTED_RESPONSE_ELEMENT

DISCONNECTED_RESPONSE

static final String DISCONNECTED_RESPONSE
See Also:
Constant Field Values

DISCONNECTED_RESPONSE_ELEMENT

static final MessageElement DISCONNECTED_RESPONSE_ELEMENT

PID_RESPONSE

static final String PID_RESPONSE
See Also:
Constant Field Values

PID_RESPONSE_ELEMENT

static final MessageElement PID_RESPONSE_ELEMENT

DEFAULT_MAX_CLIENTS

static final int DEFAULT_MAX_CLIENTS
See Also:
Constant Field Values

DEFAULT_MAX_SERVERS

static final int DEFAULT_MAX_SERVERS
See Also:
Constant Field Values

DEFAULT_LEASE

static final long DEFAULT_LEASE
See Also:
Constant Field Values

DEFAULT_STALL_TIMEOUT

static final long DEFAULT_STALL_TIMEOUT
See Also:
Constant Field Values

DEFAULT_POLL_INTERVAL

static final long DEFAULT_POLL_INTERVAL
See Also:
Constant Field Values

DEFAULT_BROADCAST_INTERVAL

static final long DEFAULT_BROADCAST_INTERVAL
See Also:
Constant Field Values

DEFAULT_CLIENT_QUEUE_SIZE

static final int DEFAULT_CLIENT_QUEUE_SIZE
See Also:
Constant Field Values
Constructor Detail

RelayTransport

public RelayTransport()
Method Detail

init

public void init(PeerGroup group,
                 ID assignedID,
                 Advertisement implAdv)
          throws PeerGroupException
Initialize the module, passing it its peer group and advertisement.

Note: when subclassing one of the existing PeerGroup implementations (which implement Module), it may not be recommended to overload the init method. See the documentation of the PeerGroup class being subclassed.

Specified by:
init in interface Module
Parameters:
group - The PeerGroup from which this Module can obtain services. If this module is a Service, this is also the PeerGroup of which this module is a service.
assignedID - Identity of Module within group. modules can use it as a the root of their namespace to create names that are unique within the group but predictable by the same module on another peer. This is normally the ModuleClassID which is also the name under which the module is known by other modules. For a group it is the PeerGroupID itself. The parameters of a service, in the Peer configuration, are indexed by the assignedID of that service, and a Service must publish its run-time parameters in the Peer Advertisement under its assigned ID.
implAdv - The implementation advertisement for this Module. It is permissible to pass null if no implementation advertisement is available. This may happen if the implementation was selected by explicit class name rather than by following an implementation advertisement. Modules are not required to support that style of loading, but if they do, then their documentation should mention it.
Throws:
PeerGroupException - This module failed to initialize.

startApp

public int startApp(String[] args)
Complete any remaining initialization of the module. The module should be fully functional after startApp() is completed. That is also the opportunity to supply arbitrary arguments (mostly to applications).

If this module is a PeerGroup service, it may be invoked several times depending on its return value.

Specified by:
startApp in interface Module
Parameters:
args - An array of Strings forming the parameters for this Module.
Returns:
int A status indication which may be one of Module.START_OK, Module.START_AGAIN_PROGRESS, Module.START_AGAIN_STALLED, which indicates partial or complete success, or any other value (negative values are recommended for future compatibility), which indicates failure.

stopApp

public void stopApp()
Stop a module. This may be called any time after init() completes and should not assume that startApp() has been called or completed.

The Module cannot be forced to comply, but in the future we might be able to deny it access to anything after some timeout.

Specified by:
stopApp in interface Module

processIncomingMessage

public void processIncomingMessage(Message message,
                                   EndpointAddress srcAddr,
                                   EndpointAddress dstAddr)
This method is invoked by the EndpointService for each incoming message which is addressed to this listener.

Specified by:
processIncomingMessage in interface EndpointListener
Parameters:
message - Incoming message
srcAddr - Endpoint Address of the source of the message.
dstAddr - Endpoint Address of the destination of the message.

getGroup

protected PeerGroup getGroup()

getServiceName

protected String getServiceName()

createPIDRequestMessage

static Message createPIDRequestMessage()

createPIDResponseMessage

static Message createPIDResponseMessage(String pidStr)

createConnectMessage

static Message createConnectMessage(long lease,
                                    boolean doReturnAdv,
                                    boolean doFlushQueue)

createConnectString

static String createConnectString(long lease,
                                  boolean doReturnAdv,
                                  boolean doFlushQueue)

createConnectedMessage

static Message createConnectedMessage(long lease)

createDisconnectMessage

static Message createDisconnectMessage()

createDisconnectedMessage

static Message createDisconnectedMessage()

setString

static void setString(Message message,
                      String elementName,
                      String value)
Convinence function for setting a string element with the relay namespace

Parameters:
message - the message
elementName - message element name
value - the value of the string

getString

static String getString(Message message,
                        String elementName)
Convinence function for getting a String from the element with the given tag and relay namespace

Parameters:
message - the message
elementName - the value of the string
Returns:
the string value, null if the element does not exist

JXSE