JXTA

net.jxta.impl.endpoint.router
Class RouteResolver

java.lang.Object
  extended by net.jxta.impl.endpoint.router.RouteResolver
All Implemented Interfaces:
Srdi.SrdiInterface, Module, QueryHandler, SrdiHandler

 class RouteResolver
extends Object
implements Module, QueryHandler, SrdiHandler, Srdi.SrdiInterface

Handles dynamic route resolution.


Nested Class Summary
(package private) static class RouteResolver.CurrentCredential
          Encapsulates current Membership Service credential.
 
Field Summary
(package private)  RouteResolver.CurrentCredential currentCredential
          The current Membership service default credential.
(package private)  net.jxta.impl.endpoint.router.RouteResolver.CredentialListener membershipCredListener
           
static String routerSName
          Router Service Name
 
Fields inherited from interface net.jxta.platform.Module
START_AGAIN_PROGRESS, START_AGAIN_STALLED, START_DISABLED, START_OK
 
Constructor Summary
RouteResolver(EndpointRouter router)
           
 
Method Summary
protected  List<PeerID> cleanupAnyEdges(ID src, List<PeerID> results)
          cleanup any edge peers when trying to forward an SRDI query so we are guaranteed to the best of our knowledge that the peer is a rendezvous.
(package private)  void enableRouteResolver(boolean enable)
          enable routeResolver usage
protected  void findRoute(EndpointAddress peer)
          issue a new route discovery resolver request
protected  void generateNACKRoute(PeerID src, PeerID dest, Vector<AccessPointAdvertisement> origHops)
          Return a route error in case a route was found to be invalid as the current hop cannot find a way to forward the message to the destination or any other hops in the forward part of the route.
 void init(PeerGroup group, ID assignedID, Advertisement impl)
          initialize routeResolver
 void messageSendFailed(PeerID peerid, OutgoingMessageEvent e)
          Resolver calls this method when a failure to send a message to specified peer occurs
 int processQuery(ResolverQueryMsg query)
          Process the Query, and generate response
 void processResponse(ResolverResponseMsg response)
          Called when messages are received by the ResolverService it calls back this method to deal with received responses
 boolean processSrdi(ResolverSrdiMsg message)
          process an SRDI message request
 void pushEntries(boolean all)
          Pushe SRDI entries.
protected  void pushSrdi(ID peer, PeerID id)
           
protected  void pushSrdi(String peer, boolean all)
           
protected  void removeSrdi(String peer, PeerID id)
          remove a SRDI cache entry
protected  void removeSrdiIndex(PeerID pid)
          remove SRDI index
 int startApp(String[] arg)
          Complete any remaining initialization of the module.
 void stopApp()
          Stop a module.
(package private)  boolean useRouteResolver()
          return routeResolver usage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

routerSName

public static final String routerSName
Router Service Name

See Also:
Constant Field Values

currentCredential

RouteResolver.CurrentCredential currentCredential
The current Membership service default credential.


membershipCredListener

final net.jxta.impl.endpoint.router.RouteResolver.CredentialListener membershipCredListener
Constructor Detail

RouteResolver

RouteResolver(EndpointRouter router)
Parameters:
router - the router
Method Detail

init

public void init(PeerGroup group,
                 ID assignedID,
                 Advertisement impl)
          throws PeerGroupException
initialize routeResolver

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.
impl - 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[] arg)
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:
arg - 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.

Careful that stopApp() could in theory be called before startApp().

Specified by:
stopApp in interface Module

useRouteResolver

boolean useRouteResolver()
return routeResolver usage

Returns:
routeResolver usage

enableRouteResolver

void enableRouteResolver(boolean enable)
enable routeResolver usage

Parameters:
enable - if true, enables route resolver

findRoute

protected void findRoute(EndpointAddress peer)
issue a new route discovery resolver request

Parameters:
peer - the destination as a logical endpoint address

processResponse

public void processResponse(ResolverResponseMsg response)
Called when messages are received by the ResolverService it calls back this method to deal with received responses

This is called by the Generic ResolverServiceImpl when processing a response to a query.

Specified by:
processResponse in interface QueryHandler
Parameters:
response - ResolverQueryMsg response

processQuery

public int processQuery(ResolverQueryMsg query)
Process the Query, and generate response

Specified by:
processQuery in interface QueryHandler
Parameters:
query - the query to process
Returns:
int status, OK success, Repropagate to indicate a re-propagation is needed.

generateNACKRoute

protected void generateNACKRoute(PeerID src,
                                 PeerID dest,
                                 Vector<AccessPointAdvertisement> origHops)
Return a route error in case a route was found to be invalid as the current hop cannot find a way to forward the message to the destination or any other hops in the forward part of the route. In that case a negative route response is forwarded to the original source of the message. Now of course we do not have any way to guarantee that the NACK message will be received by the sender, but the best we can do is to try :-)

we send a query ID to NACKROUTE_QUERYID to indicate this is a bad Route

Parameters:
src - original source of the message
dest - original destination of the message
origHops - original hops

processSrdi

public boolean processSrdi(ResolverSrdiMsg message)
process an SRDI message request

Specified by:
processSrdi in interface SrdiHandler
Parameters:
message - SRDI resolver message
Returns:
true if the message was processed properly

pushEntries

public void pushEntries(boolean all)
Pushe SRDI entries.

Specified by:
pushEntries in interface Srdi.SrdiInterface
Parameters:
all - if true then push all entries otherwise just push those which have changed since the last push.

pushSrdi

protected void pushSrdi(String peer,
                        boolean all)

pushSrdi

protected void pushSrdi(ID peer,
                        PeerID id)

removeSrdi

protected void removeSrdi(String peer,
                          PeerID id)
remove a SRDI cache entry

Parameters:
peer - peer id we send the request, null for sending to all
id - peer id of the SRDI route that we want to remove from the cache

messageSendFailed

public void messageSendFailed(PeerID peerid,
                              OutgoingMessageEvent e)
Resolver calls this method when a failure to send a message to specified peer occurs

Specified by:
messageSendFailed in interface SrdiHandler
Parameters:
peerid - peerid failure occured on

cleanupAnyEdges

protected List<PeerID> cleanupAnyEdges(ID src,
                                       List<PeerID> results)
cleanup any edge peers when trying to forward an SRDI query so we are guaranteed to the best of our knowledge that the peer is a rendezvous. This is not perfect, as it may take time for the peerview to converge but at least we can remove any peers that is not a rendezvous.

Parameters:
src - source
results - vector of PeerIDs
Returns:
cleaned up vector of PeerIDs

removeSrdiIndex

protected void removeSrdiIndex(PeerID pid)
remove SRDI index

Parameters:
pid - of the index to be removed

JXSE