Project JXTA

net.jxta.impl.peergroup
Class GenericPeerGroup

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

public abstract class GenericPeerGroup
extends Object
implements PeerGroup

Provides common services for most peer group implementations.


Nested Class Summary
 
Nested classes/interfaces inherited from interface net.jxta.peergroup.PeerGroup
PeerGroup.GlobalRegistry
 
Field Summary
protected  PlatformConfig configAdvertisement
          This peer's config advertisement.
protected  Configurator configurator
          The configurator for this peer group.
protected  PeerGroup parentGroup
          This service implements a group but, being a Service, it runs inside of some group.
 
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, refStartNetPeerGroupSpecID, 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_OK
 
Constructor Summary
GenericPeerGroup()
           
 
Method Summary
protected  void addService(ID name, Service service)
          Adds a service to the set.
protected  void checkServices()
          check that all required services are registered
abstract  boolean compatible(Element compat)
          Evaluates if the given compatibility statement makes the module that bears it is lodable by this group.
protected  void decRefCount()
          Called everytime an interface object that refers to this group goes away, either by being finalized or by its unref method being invoked explicitly.
 boolean equals(Object target)
          
 AccessService getAccessService()
          
abstract  ModuleImplAdvertisement getAllPurposePeerGroupImplAdvertisement()
          
 ConfigParams getConfigAdvertisement()
          
 DiscoveryService getDiscoveryService()
          
 EndpointService getEndpointService()
          
 ThreadGroup getHomeThreadGroup()
          Returns the Thread Group in which threads for this peer group will live.
 Advertisement getImplAdvertisement()
          
 Service getInterface()
          
static JxtaLoader getJxtaLoader()
          Get a modified version of the Jxta ClassLoader
 JxtaLoader getLoader()
          
 MembershipService getMembershipService()
          
 PeerGroup getParentGroup()
          Get this group's parent group.
 PeerAdvertisement getPeerAdvertisement()
          
 PeerGroupAdvertisement getPeerGroupAdvertisement()
          
 PeerGroupID getPeerGroupID()
          
 String getPeerGroupName()
          
 PeerID getPeerID()
          
 PeerInfoService getPeerInfoService()
          
 String getPeerName()
          
 PipeService getPipeService()
          
 RendezVousService getRendezVousService()
          
 ResolverService getResolverService()
          
 Iterator getRoleMap(ID name)
          
 PeerGroup getWeakInterface()
          
 int hashCode()
          
 void init(PeerGroup homeGroup, ID assignedID, Advertisement impl)
          

It is not recommended to overload this method.

protected  void initFirst(PeerGroup homeGroup, 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.
 boolean isRendezvous()
          
 Module loadModule(ID assigned, Advertisement impl)
          Load a module from a ModuleImplAdv.
protected  Module loadModule(ID assigned, Advertisement impl, boolean privileged)
          Internal version, allows one to make a privileged module (has a ref to the true group obj instead of just an interface.
 Module loadModule(ID assigned, ModuleSpecID specID, int where)
          Load a module from a spec id.
protected  Module loadModule(ID assigned, ModuleSpecID specID, int where, boolean privileged)
          Load a module from a spec id.
 Service lookupService(ID name)
          Call a service by name.
 Service lookupService(ID name, int roleIndex)
           Group implementations do not have to support mapping.
 PeerGroup newGroup(Advertisement pgAdv)
          
 PeerGroup newGroup(PeerGroupID gid)
          
 PeerGroup newGroup(PeerGroupID gid, Advertisement impl, String name, String description)
          
 void publishGroup(String name, String description)
          
protected  void removeService(ModuleClassID name, Service service)
          Ask a group to unregister and unload a service
protected  void setConfigAdvertisement(ConfigParams config)
          
static void setJxtaLoader(JxtaLoader newLoader)
          Set a modified version of the Jxta ClassLoader
 int startApp(String[] arg)
          Start the peergroup.
 void stopApp()
          Stops the group and all its services.
 void unref()
          May be called by a module which has a direct reference to the group object and wants to notify its abandoning it.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configurator

protected Configurator configurator
The configurator for this peer group.


configAdvertisement

protected PlatformConfig configAdvertisement
This peer's config advertisement.


parentGroup

protected PeerGroup parentGroup
This service implements a group but, being a Service, it runs inside of some group. That's its home group.

Exception: The platform itself does not have one. It has to be self sufficient.

Constructor Detail

GenericPeerGroup

public GenericPeerGroup()
Method Detail

getJxtaLoader

public static JxtaLoader getJxtaLoader()
Get a modified version of the Jxta ClassLoader


setJxtaLoader

public static void setJxtaLoader(JxtaLoader newLoader)
Set a modified version of the Jxta ClassLoader


equals

public boolean equals(Object target)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

getHomeThreadGroup

public ThreadGroup getHomeThreadGroup()
Returns the Thread Group in which threads for this peer group will live.

Specified by:
getHomeThreadGroup in interface PeerGroup
Returns:
ThreadGroup

addService

protected void addService(ID name,
                          Service service)
Adds a service to the set.

Removes any pre-existing one with the same name.


lookupService

public Service lookupService(ID name)
                      throws ServiceNotFoundException
Call a service by name.

Specified by:
lookupService in interface PeerGroup
Parameters:
name - the service name
Returns:
Service, the Service registered by that name
Throws:
ServiceNotFoundException

lookupService

public Service lookupService(ID name,
                             int roleIndex)
                      throws ServiceNotFoundException
Group implementations do not have to support mapping. it would be nice to separate better Interfaces, so that Interface Objects can do things that the real service does not have to implement.

Specified by:
lookupService in interface PeerGroup
Throws:
ServiceNotFoundException

getRoleMap

public Iterator getRoleMap(ID name)

Specified by:
getRoleMap in interface PeerGroup

checkServices

protected void checkServices()
                      throws ServiceNotFoundException
check that all required services are registered

Throws:
ServiceNotFoundException

removeService

protected void removeService(ModuleClassID name,
                             Service service)
                      throws ServiceNotFoundException,
                             ViolationException
Ask a group to unregister and unload a service

Parameters:
service - handle to the service to be removed
Throws:
ServiceNotFoundException
ViolationException

compatible

public abstract boolean compatible(Element compat)
Evaluates if the given compatibility statement makes the module that bears it is lodable by this group.

Specified by:
compatible in interface PeerGroup
Returns:
boolean True if the given statement is compatible.

loadModule

public Module loadModule(ID assigned,
                         Advertisement impl)
                  throws ProtocolNotSupportedException,
                         PeerGroupException
Load a module from a ModuleImplAdv. Compatibility is checked and load is attempted. If compatible and loaded successfuly, the resulting Module is init()ed and returned.

Specified by:
loadModule in interface PeerGroup
Throws:
ProtocolNotSupportedException
PeerGroupException

loadModule

protected Module loadModule(ID assigned,
                            Advertisement impl,
                            boolean privileged)
                     throws ProtocolNotSupportedException,
                            PeerGroupException
Internal version, allows one to make a privileged module (has a ref to the true group obj instead of just an interface. That's for group modules and main apps normally).

Throws:
ProtocolNotSupportedException
PeerGroupException

loadModule

public Module loadModule(ID assigned,
                         ModuleSpecID specID,
                         int where)
Load a module from a spec id. Advertisement is sought, compatibility is checked on all candidates and load is attempted. The first one that is compatible and loads successfuly is init()ed and returned.

Specified by:
loadModule in interface PeerGroup

loadModule

protected Module loadModule(ID assigned,
                            ModuleSpecID specID,
                            int where,
                            boolean privileged)
Load a module from a spec id. Advertisement is sought, compatibility is checked on all candidates and load is attempted. The first one that is compatible and loads successfuly is init()ed and returned.


getConfigAdvertisement

public ConfigParams getConfigAdvertisement()

Specified by:
getConfigAdvertisement in interface PeerGroup

setConfigAdvertisement

protected void setConfigAdvertisement(ConfigParams config)


init

public void init(PeerGroup homeGroup,
                 ID assignedID,
                 Advertisement impl)
          throws PeerGroupException

It is not recommended to overload this method. Instead, subclassers should overload either or both of initFirst(PeerGroup,ID,Advertisement) and initLast(). If this method is to be overloaded, the overloading method must invoke super.init.

This method invokes initFirst with identical parameters. initLast does not take parameters since the relevant information can be obtained from the group following completion of the initFirst phase. The resulting values may be different from the parameters to initFirst since initFirst may be overLoaded and the overloading method may modify these parameters when calling super.initFirst. (See net.jxta.impl.Platform for an example of such a case).

Upon completion, the group object is marked as completely initialized in all cases. Once a group object is completely initialized, it becomes sensitive to reference counting.

In the future this method may become final.

Specified by:
init in interface Module
Throws:
PeerGroupException

initFirst

protected void initFirst(PeerGroup homeGroup,
                         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.

Parameters:
homeGroup - 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 choses a new group ID.
impl - The ModuleImplAdvertisement which defines this group's implementation.
Throws:
PeerGroupException

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.

Throws:
PeerGroupException

startApp

public int startApp(String[] arg)
Start the peergroup.

In practice, it means starting its main application. But that's for subclasses. GenericPeerGroup does not implement the concept of initial app anylonger. See subclasses.

Specified by:
startApp in interface Module
Returns:
int Status.

stopApp

public void stopApp()
Stops the group and all its services.

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

unref

public void unref()
May be called by a module which has a direct reference to the group object and wants to notify its abandoning it. Has no effect on the real group object.

Specified by:
unref in interface PeerGroup

decRefCount

protected void decRefCount()
Called everytime an interface object that refers to this group goes away, either by being finalized or by its unref method being invoked explicitly.


getInterface

public Service getInterface()

Specified by:
getInterface in interface Service

getWeakInterface

public PeerGroup getWeakInterface()

Specified by:
getWeakInterface in interface PeerGroup

getImplAdvertisement

public Advertisement getImplAdvertisement()

Specified by:
getImplAdvertisement in interface Service

publishGroup

public void publishGroup(String name,
                         String description)
                  throws IOException

Specified by:
publishGroup in interface PeerGroup
Throws:
IOException

newGroup

public PeerGroup newGroup(Advertisement pgAdv)
                   throws PeerGroupException

Specified by:
newGroup in interface PeerGroup
Throws:
PeerGroupException

newGroup

public PeerGroup newGroup(PeerGroupID gid,
                          Advertisement impl,
                          String name,
                          String description)
                   throws PeerGroupException

Specified by:
newGroup in interface PeerGroup
Throws:
PeerGroupException

newGroup

public PeerGroup newGroup(PeerGroupID gid)
                   throws PeerGroupException

Specified by:
newGroup in interface PeerGroup
Throws:
PeerGroupException

getLoader

public JxtaLoader getLoader()

Specified by:
getLoader in interface PeerGroup

getPeerName

public String getPeerName()

Specified by:
getPeerName in interface PeerGroup

getPeerGroupName

public String getPeerGroupName()

Specified by:
getPeerGroupName in interface PeerGroup

getPeerGroupID

public PeerGroupID getPeerGroupID()

Specified by:
getPeerGroupID in interface PeerGroup

getPeerID

public PeerID getPeerID()

Specified by:
getPeerID in interface PeerGroup

getPeerAdvertisement

public PeerAdvertisement getPeerAdvertisement()

Specified by:
getPeerAdvertisement in interface PeerGroup

getPeerGroupAdvertisement

public PeerGroupAdvertisement getPeerGroupAdvertisement()

Specified by:
getPeerGroupAdvertisement in interface PeerGroup

isRendezvous

public boolean isRendezvous()

Specified by:
isRendezvous in interface PeerGroup

getEndpointService

public EndpointService getEndpointService()

Specified by:
getEndpointService in interface PeerGroup

getResolverService

public ResolverService getResolverService()

Specified by:
getResolverService in interface PeerGroup

getDiscoveryService

public DiscoveryService getDiscoveryService()

Specified by:
getDiscoveryService in interface PeerGroup

getPeerInfoService

public PeerInfoService getPeerInfoService()

Specified by:
getPeerInfoService in interface PeerGroup

getMembershipService

public MembershipService getMembershipService()

Specified by:
getMembershipService in interface PeerGroup

getPipeService

public PipeService getPipeService()

Specified by:
getPipeService in interface PeerGroup

getRendezVousService

public RendezVousService getRendezVousService()

Specified by:
getRendezVousService in interface PeerGroup

getAccessService

public AccessService getAccessService()

Specified by:
getAccessService in interface PeerGroup

getAllPurposePeerGroupImplAdvertisement

public abstract ModuleImplAdvertisement getAllPurposePeerGroupImplAdvertisement()
                                                                         throws Exception

Specified by:
getAllPurposePeerGroupImplAdvertisement in interface PeerGroup
Throws:
Exception

getParentGroup

public PeerGroup getParentGroup()
Get this group's parent group.

We do not want to count on the invoker to properly unreference the group object that we return; this call is often used in a loop and it is silly to increment and decrement ref-counts for references that are sure to live shorter than the referee. On the other hand it is dangerous for us to share our reference object to the parent group. That's where weak interface objects come in handy. We can safely make one and give it away.

Specified by:
getParentGroup in interface PeerGroup

JXTA J2SE