JXTA

net.jxta.impl.endpoint.router
Class RouteCM

java.lang.Object
  extended by net.jxta.impl.endpoint.router.RouteCM
All Implemented Interfaces:
Module

 class RouteCM
extends Object
implements Module


Field Summary
static long DEFAULT_EXPIRATION
          Default expiration time for Route advertisements.
static boolean USE_CM_DEFAULT
          If true then the CM is used to persistently store route advertisements.
 
Fields inherited from interface net.jxta.platform.Module
START_AGAIN_PROGRESS, START_AGAIN_STALLED, START_DISABLED, START_OK
 
Constructor Summary
RouteCM()
           
 
Method Summary
protected  void createRoute(RouteAdvertisement route)
          Create a new persistent route to the cache only if we can find set of endpoint addresses
(package private)  void enableRouteCM(boolean enable)
          toggles whether to use the RouteCM
protected  void flushRoute(ID peerID)
          flush route adv from CM
protected  Iterator<RouteAdvertisement> getRouteAdv(ID peerID)
          Get route advertisements from the local discovery cache.
 void init(PeerGroup group, ID assignedID, Advertisement impl)
          Initialize the module, passing it its peer group and advertisement.
protected  void publishRoute(RouteAdvertisement route)
          Publish a route advertisement to the CM
 int startApp(String[] arg)
          Complete any remaining initialization of the module.
 void stopApp()
          Stop a module.
protected  boolean updateRoute(RouteAdvertisement route)
          publish or update new route from the advertisement cache
(package private)  boolean useRouteCM()
          return routeCM usage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EXPIRATION

public static final long DEFAULT_EXPIRATION
Default expiration time for Route advertisements. This is the amount of time which advertisements will live in caches. After this time, the advertisement should be refreshed from the source.

See Also:
Constant Field Values

USE_CM_DEFAULT

public static final boolean USE_CM_DEFAULT
If true then the CM is used to persistently store route advertisements. If false then only the in-memory route table is used.

See Also:
Constant Field Values
Constructor Detail

RouteCM

RouteCM()
Method Detail

init

public void init(PeerGroup group,
                 ID assignedID,
                 Advertisement impl)
          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.
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.

Specified by:
stopApp in interface Module

useRouteCM

boolean useRouteCM()
return routeCM usage

Returns:
true if enabled

enableRouteCM

void enableRouteCM(boolean enable)
toggles whether to use the RouteCM

Parameters:
enable - if true it enables use of persistent store

getRouteAdv

protected Iterator<RouteAdvertisement> getRouteAdv(ID peerID)
Get route advertisements from the local discovery cache. We collect straight RouteAdvertisements as well as what can be found in PeerAdvertisements.

We can find both, and there's no way to know which is most relevant, so we have to return all and let the invoker try its luck with each.

Parameters:
peerID - the target peer's ID.
Returns:
Route Advertisements for the specified peer.

createRoute

protected void createRoute(RouteAdvertisement route)
Create a new persistent route to the cache only if we can find set of endpoint addresses

Parameters:
route - to be published

publishRoute

protected void publishRoute(RouteAdvertisement route)
Publish a route advertisement to the CM

Parameters:
route - advertisement to be published

flushRoute

protected void flushRoute(ID peerID)
flush route adv from CM

Parameters:
peerID - the PeerID

updateRoute

protected boolean updateRoute(RouteAdvertisement route)
publish or update new route from the advertisement cache

Parameters:
route - to be published or updated
Returns:
boolean true or false if adv cache was updated

JXSE