Project 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)


Field Summary
protected  net.jxta.impl.endpoint.relay.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(net.jxta.impl.endpoint.relay.RelayClient.RelayServerConnection server)
           
 Vector getActiveRelays(PeerGroup pg)
          return the list of connected relays
 EndpointService getEndpointService()
          
 String getProtocolName()
          
 Iterator getPublicAddresses()
          
protected  void handleResponse(Message message, EndpointAddress dstAddr)
           
protected  boolean isRelayConnectDone()
           
(package private) static EndpointAddress[] loadSeeds(URI seedingURI)
           
protected  RdvAdvertisement maintainRelayConnection(net.jxta.impl.endpoint.relay.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)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentServer

protected net.jxta.impl.endpoint.relay.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 getPublicAddresses()

Specified by:
getPublicAddresses in interface MessageReceiver

getProtocolName

public String getProtocolName()

Specified by:
getProtocolName in interface MessageTransport

getEndpointService

public EndpointService getEndpointService()

Specified by:
getEndpointService in interface MessageTransport

transportControl

public Object transportControl(Object operation,
                               Object Value)

Specified by:
transportControl in interface MessageTransport

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(net.jxta.impl.endpoint.relay.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(net.jxta.impl.endpoint.relay.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 getActiveRelays(PeerGroup pg)
return the list of connected relays


loadSeeds

static EndpointAddress[] loadSeeds(URI seedingURI)
                            throws IOException
Throws:
IOException

JXTA J2SE