JXTA

net.jxta.impl.peergroup
Class StdPeerGroup

java.lang.Object
  extended by net.jxta.impl.peergroup.GenericPeerGroup
      extended by net.jxta.impl.peergroup.StdPeerGroup
All Implemented Interfaces:
PeerGroup, Module, Service
Direct Known Subclasses:
Platform, ShadowPeerGroup

public class StdPeerGroup
extends GenericPeerGroup

A subclass of GenericPeerGroup that makes a peer group out of independent plugin services listed in its impl advertisement.


Nested Class Summary
 
Nested classes/interfaces inherited from class net.jxta.impl.peergroup.GenericPeerGroup
GenericPeerGroup.PeerGroupThreadFactory
 
Nested classes/interfaces inherited from interface net.jxta.peergroup.PeerGroup
PeerGroup.GlobalRegistry
 
Field Summary
static String MODULE_IMPL_STD_PROVIDER
           
static String MODULE_IMPL_STD_URI
           
static XMLDocument STD_COMPAT
           
protected static String STD_COMPAT_BINDING
           
protected static String STD_COMPAT_BINDING_VALUE
           
protected static String STD_COMPAT_FORMAT
           
protected static String STD_COMPAT_FORMAT_VALUE
          The Specification title and Specification version we require.
 
Fields inherited from class net.jxta.impl.peergroup.GenericPeerGroup
configAdvertisement, implAdvertisement, initComplete, jxtaHome, parentGroup
 
Fields inherited from interface net.jxta.peergroup.PeerGroup
accessClassID, allPurposePeerGroupSpecID, applicationClassID, Both, DEFAULT_EXPIRATION, DEFAULT_LIFETIME, discoveryClassID, endpointClassID, FromParent, globalRegistry, Here, httpProtoClassID, membershipClassID, peerGroupClassID, peerinfoClassID, pipeClassID, proxyClassID, refAccessSpecID, refDiscoverySpecID, refEndpointSpecID, refHttpProtoSpecID, refMembershipSpecID, refNetPeerGroupSpecID, refPeerinfoSpecID, refPipeSpecID, refPlatformSpecID, refProxySpecID, refRelayProtoSpecID, refRendezvousSpecID, refResolverSpecID, refRouterProtoSpecID, refShellSpecID, refTcpProtoSpecID, refTlsProtoSpecID, relayProtoClassID, rendezvousClassID, resolverClassID, routerProtoClassID, tcpProtoClassID, tlsProtoClassID, WK_ID_PREFIX
 
Fields inherited from interface net.jxta.platform.Module
START_AGAIN_PROGRESS, START_AGAIN_STALLED, START_DISABLED, START_OK
 
Constructor Summary
StdPeerGroup()
          constructor
 
Method Summary
 boolean compatible(Element compat)
          Return true if the provided compatibility statement is compatible with this group.
 ModuleImplAdvertisement getAllPurposePeerGroupImplAdvertisement()
          Get an all purpose peerGroup ModuleImplAdvertisement that is compatible with this group.
 Map<ModuleClassID,Object> getApplications()
          Return a map of the applications for this group.
 Cm getCacheManager()
          Returns the cache manager associated with this group.
protected  void initFirst(PeerGroup parent, ID assignedID, Advertisement impl)
          Performs all initialization steps that need to be performed before any subclass initialization is performed.
protected  void initLast()
          Perform all initialization steps that need to be performed after any subclass initialization is performed.
(package private) static boolean isCompatible(Element compat)
          Evaluates if the given compatibility statement makes the module that bears it is loadable by this group.
protected  void loadAllModules(Map<ModuleClassID,Object> modules, boolean privileged)
          Builds a table of modules indexed by their class ID.
(package private) static ModuleImplAdvertisement mkImplAdvBuiltin(ModuleSpecID specID, String code, String descr)
          An internal convenience method essentially for bootstrapping.
 int startApp(String[] arg)
          The group does not care for start args, and does not come-up with args to pass to its main app.
 void stopApp()
          Stop a module.
 
Methods inherited from class net.jxta.impl.peergroup.GenericPeerGroup
addService, checkServices, decRefCount, equals, getAccessService, getConfigAdvertisement, getDiscoveryService, getEndpointService, getExecutor, getHomeThreadGroup, getImplAdvertisement, getInterface, getJxtaLoader, getLoader, getMembershipService, getParentGroup, getPeerAdvertisement, getPeerGroupAdvertisement, getPeerGroupID, getPeerGroupName, getPeerID, getPeerInfoService, getPeerName, getPipeService, getRendezVousService, getResolverService, getRoleMap, getScheduledExecutor, getStoreHome, getWeakInterface, hashCode, init, isRendezvous, loadModule, loadModule, loadModule, loadModule, lookupService, lookupService, newGroup, newGroup, newGroup, publishGroup, removeService, setConfigAdvertisement, setGroupConfigAdvertisement, setStoreHome, toString, unref
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

STD_COMPAT

public static final XMLDocument STD_COMPAT

MODULE_IMPL_STD_URI

public static final String MODULE_IMPL_STD_URI
See Also:
Constant Field Values

MODULE_IMPL_STD_PROVIDER

public static final String MODULE_IMPL_STD_PROVIDER
See Also:
Constant Field Values

STD_COMPAT_FORMAT

protected static final String STD_COMPAT_FORMAT
See Also:
Constant Field Values

STD_COMPAT_FORMAT_VALUE

protected static final String STD_COMPAT_FORMAT_VALUE
The Specification title and Specification version we require.

See Also:
Constant Field Values

STD_COMPAT_BINDING

protected static final String STD_COMPAT_BINDING
See Also:
Constant Field Values

STD_COMPAT_BINDING_VALUE

protected static final String STD_COMPAT_BINDING_VALUE
See Also:
Constant Field Values
Constructor Detail

StdPeerGroup

public StdPeerGroup()
constructor

Method Detail

mkImplAdvBuiltin

static ModuleImplAdvertisement mkImplAdvBuiltin(ModuleSpecID specID,
                                                String code,
                                                String descr)
An internal convenience method essentially for bootstrapping. Make a standard ModuleImplAdv for any service that comes builtin this reference implementation. In most cases there are no params, so we do not take that argument. The invoker may add params afterwards.

Parameters:
specID - spec ID
code - code uri
descr - description
Returns:
a ModuleImplAdvertisement

compatible

public boolean compatible(Element compat)
Return true if the provided compatibility statement is compatible with this group.

Parameters:
compat - compatibility element
Returns:
boolean True if the statement is compatible.

isCompatible

static boolean isCompatible(Element compat)
Evaluates if the given compatibility statement makes the module that bears it is loadable by this group.

Parameters:
compat - The compatibility statement being tested.
Returns:
true if we are compatible with the provided statement otherwise false.

loadAllModules

protected void loadAllModules(Map<ModuleClassID,Object> modules,
                              boolean privileged)
Builds a table of modules indexed by their class ID. The values are the loaded modules, the keys are their classId. This routine interprets the parameter list in the advertisement.

Parameters:
modules - The modules to load
privileged - if true then modules will get a real reference to the group loading them, otherwise its an interface object.

startApp

public int startApp(String[] arg)
The group does not care for start args, and does not come-up with args to pass to its main app. So, until we decide on something more useful, the args of the group's startApp are passed-on to the group's main app. NB: both the apps init and startApp methods are invoked.

Specified by:
startApp in interface Module
Overrides:
startApp in class GenericPeerGroup
Parameters:
arg - An array of Strings forming the parameters for this Module.
Returns:
int Status.

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.

PeerGroupInterface's stopApp() does nothing. Only a real reference to the group object permits to stop it without going through ref counting.

Specified by:
stopApp in interface Module
Overrides:
stopApp in class GenericPeerGroup

initFirst

protected void initFirst(PeerGroup parent,
                         ID assignedID,
                         Advertisement impl)
                  throws PeerGroupException
Performs all initialization steps that need to be performed before any subclass initialization is performed.

Classes that override this method should always call super.initFirst() before doing any of their own work.

This method loads and initializes all of the peer group modules described in the provided implementation advertisement. Then, all modules are placed in a list and the list is processed iteratively. During each iteration, the Module.startApp(String[]) method of each module is invoked once. Iterations continue until no progress is being made or the list is empty.

The status returned by the Module.startApp(String[]) method of each module is considered as follows:

Iterations through the list stop when:

Overrides:
initFirst in class GenericPeerGroup
Parameters:
parent - The group that serves as a parent to this group.
assignedID - The unique ID assigned to this module. For group this is the group ID or null if a group ID has not yet been assigned. If null is passed, GenericPeerGroup will generate a new group ID.
impl - The ModuleImplAdvertisement which defines this group's implementation.
Throws:
PeerGroupException - if a group initialization error occurs

initLast

protected void initLast()
                 throws PeerGroupException
Perform all initialization steps that need to be performed after any subclass initialization is performed.

Classes that override this method should always call super.initLast after doing any of their own work.

Nothing special for now, but we might want to move some steps from initFirst() in the future.

Overrides:
initLast in class GenericPeerGroup
Throws:
PeerGroupException - if a group initialization error occurs

getAllPurposePeerGroupImplAdvertisement

public ModuleImplAdvertisement getAllPurposePeerGroupImplAdvertisement()
Get an all purpose peerGroup ModuleImplAdvertisement that is compatible with this group. This impl adv can be used to create any group that relies only on the standard services. Or to derive other impl advs, using this impl advertisement as a basis.

This defines a peergroup implementation that can be used for many purposes, and from which one may derive slightly different peergroup implementations.

This definition is always the same and has a well known ModuleSpecID. It includes the basic service, no protocols and the shell for main application.

The user must remember to change the specID if the set of services protocols or applications is altered before use.

FIXME 20070801 bondolo To improve compatibility with existing applications the returned ModuleImplAdvertisement will contain embedded ModuleImplAdvertisements for the referenced services as opposed to ModuleSpecIDs. This is because JXSE 2.4.1 and earlier do not handle load failures of modules loaded by spec id correctly. After JXSE 2.5 is released this should be changed to use the better ModuleSpecID based peer group module specification.

Returns:
ModuleImplAdvertisement The new peergroup impl adv.

getCacheManager

public Cm getCacheManager()
Returns the cache manager associated with this group.

Returns:
the cache manager associated with this group.

getApplications

public Map<ModuleClassID,Object> getApplications()
Return a map of the applications for this group.

Returns:
a map of the applications for this group.

JXSE