JXTA

net.jxta.impl.endpoint.relay
Class RelayClient

java.lang.Object
  extended by net.jxta.impl.endpoint.relay.RelayClient
All Implemented Interfaces:
Runnable, MessageReceiver, MessageTransport

public class RelayClient
extends Object
implements MessageReceiver, Runnable

RelayClient manages the relationship with the RelayServer(s)


Nested Class Summary
(package private) static class RelayClient.RelayServerConnection
           
 
Field Summary
(package private)  RelayClient.RelayServerConnection currentServer
           
 
Constructor Summary
RelayClient(PeerGroup group, String serviceName, RelayConfigAdv relayConfig)
           
 
Method Summary
 boolean addActiveRelay(EndpointAddress address, RouteAdvertisement relayRoute)
          Notify of a new relay connection
 boolean addActiveRelayListener(Object service)
          Register an active Relay to the endpoint.
(package private)  RdvAdvertisement connectToRelay(RelayClient.RelayServerConnection server)
           
 Vector<AccessPointAdvertisement> getActiveRelays(PeerGroup pg)
          return the list of connected relays
 EndpointService getEndpointService()
          Returns the endpoint service with which this MessageTransport is registered.
 String getProtocolName()
          Returns a String containing the name of the protocol used by this MessageTransport.
 Iterator<EndpointAddress> getPublicAddresses()
          Returns an Iterator of all of the EndpointAddresses by which this MessageReceiver is reachable.
protected  void handleResponse(Message message, EndpointAddress dstAddr)
           
protected  boolean isRelayConnectDone()
           
protected  RdvAdvertisement maintainRelayConnection(RelayClient.RelayServerConnection server)
           
 boolean removeActiveRelay(EndpointAddress address, RouteAdvertisement relayRoute)
          Notify of a relay connection removal
 boolean removeActiveRelayListener(Object service)
          Unregister an active Relay to the endpoint.
 void run()
          Logic for the relay client Pick a relay server to try try getting a messenger to relay server, if can not get messenger, start over use the messenger to send a connect message wait for a response, if there is no response or a disconnect response, start over while still connected renew the lease as needed and keep the messenger connected

FIXME 20041102 bondolo The approach used here is really, really stupid.

 boolean startClient()
           
 void stopClient()
           
 Object transportControl(Object operation, Object Value)
          Pass a transport control object to a message transport.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentServer

RelayClient.RelayServerConnection currentServer
Constructor Detail

RelayClient

public RelayClient(PeerGroup group,
                   String serviceName,
                   RelayConfigAdv relayConfig)
Method Detail

startClient

public boolean startClient()

stopClient

public void stopClient()

getPublicAddresses

public Iterator<EndpointAddress> getPublicAddresses()
Returns an Iterator of all of the EndpointAddresses by which this MessageReceiver is reachable. The list is in order of "preference" with the most "preferred" EndpointAddress being at the beginning of the list.

Specified by:
getPublicAddresses in interface MessageReceiver
Returns:
an Iterator of EndpointAddresses.

getProtocolName

public String getProtocolName()
Returns a String containing the name of the protocol used by this MessageTransport. The value will match the "protocol" portion of all EndpointAddress.

Specified by:
getProtocolName in interface MessageTransport
Returns:
a String containing the name of the protocol used by this MessageTransport.

getEndpointService

public EndpointService getEndpointService()
Returns the endpoint service with which this MessageTransport is registered. If it is unregistered then null will be returned.

Specified by:
getEndpointService in interface MessageTransport
Returns:
the EndpointService with which this MessageTransport is registered.

transportControl

public Object transportControl(Object operation,
                               Object Value)
Pass a transport control object to a message transport.

Specified by:
transportControl in interface MessageTransport
Parameters:
operation - Object that specifies the type of control operation to be performed
Value - Object that specifies a value object associated with the control operation
Returns:
returned object

run

public void run()
Logic for the relay client
  1. Pick a relay server to try
  2. try getting a messenger to relay server, if can not get messenger, start over
  3. use the messenger to send a connect message
  4. wait for a response, if there is no response or a disconnect response, start over
  5. while still connected
    1. renew the lease as needed and keep the messenger connected

      FIXME 20041102 bondolo The approach used here is really, really stupid. The calls to connectToRelay() will not return if a connection to a relay is achieved. This makes continued iteration over seeds after return incredibly silly. connectToRelay() only returns when it can NO LONGER CONNECT to the relay. The only hack I can think of to subvert this is to stop iteration of advs/seeds if connectToRelay() takes a long time. bizarre.

      Specified by:
      run in interface Runnable

isRelayConnectDone

protected boolean isRelayConnectDone()

connectToRelay

RdvAdvertisement connectToRelay(RelayClient.RelayServerConnection server)
Parameters:
server - The relay server to connect to
Returns:
The advertisement of an alternate relay server to try.

maintainRelayConnection

protected RdvAdvertisement maintainRelayConnection(RelayClient.RelayServerConnection server)

handleResponse

protected void handleResponse(Message message,
                              EndpointAddress dstAddr)

addActiveRelayListener

public boolean addActiveRelayListener(Object service)
Register an active Relay to the endpoint. This is done so the Route Advertisement of the PeerAdvertisement is updated


removeActiveRelayListener

public boolean removeActiveRelayListener(Object service)
Unregister an active Relay to the endpoint. This is done so the Route Advertisement of the PeerAdvertisement is updated


addActiveRelay

public boolean addActiveRelay(EndpointAddress address,
                              RouteAdvertisement relayRoute)
Notify of a new relay connection


removeActiveRelay

public boolean removeActiveRelay(EndpointAddress address,
                                 RouteAdvertisement relayRoute)
Notify of a relay connection removal


getActiveRelays

public Vector<AccessPointAdvertisement> getActiveRelays(PeerGroup pg)
return the list of connected relays


JXSE