Project JXTA

net.jxta.impl.peergroup
Class RefCountPeerGroupInterface

java.lang.Object
  extended bynet.jxta.impl.peergroup.PeerGroupInterface
      extended bynet.jxta.impl.peergroup.RefCountPeerGroupInterface
All Implemented Interfaces:
Module, PeerGroup, Service

class RefCountPeerGroupInterface
extends PeerGroupInterface

RefCountPeerGroupInterface is a PeerGroupInterface object that also serves as a peergroup very-strong reference. When the last such goes away, the peergroup terminates itself despite the existence of aeternal strong references from the various service's threads that would prevent it from ever being finalized. The alternative: to give only weak references to threads seems impractical.


Nested Class Summary
 
Nested classes inherited from class net.jxta.peergroup.PeerGroup
PeerGroup.GlobalRegistry
 
Field Summary
protected  PeerGroup groupImpl
          The peer group instance which backs this interface object.
 
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
(package private) RefCountPeerGroupInterface(GenericPeerGroup theRealThing)
          Constructs an interface object that front-ends a given PeerGroup object.
(package private) RefCountPeerGroupInterface(GenericPeerGroup theRealThing, Map roleMap)
           
 
Method Summary
 boolean compatible(Element compat)
          
 void finalize()
          stopApp used to be the standard way of giving up on a group instance, but now that goup instance can be shared, the standard of letting go of a peer group is to stop referencing it.
 AccessService getAccessService()
          
 ModuleImplAdvertisement getAllPurposePeerGroupImplAdvertisement()
          
 ConfigParams getConfigAdvertisement()
          
 DiscoveryService getDiscoveryService()
          
 EndpointService getEndpointService()
          
 ThreadGroup getHomeThreadGroup()
          
 Advertisement getImplAdvertisement()
          
 Service getInterface()
          

Since THIS is already such an object, it could return itself.

 JxtaLoader getLoader()
          
 MembershipService getMembershipService()
          
 PeerGroup getParentGroup()
           
 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()
           Returns a weak interface object that refers to this interface object rather than to the group directly.
 void init(PeerGroup pg, ID assignedID, Advertisement impl)
          This is here for class hierarchy reasons.
 boolean isRendezvous()
          
 Module loadModule(ID assignedID, Advertisement impl)
           FIXME: jice@jxta.org 20031103 Idealy, we'd need the groupAPI to offer a means to loadModule() without making a counted reference, so that group services can loadModule() things without preventing group termination.
 Module loadModule(ID assignedID, ModuleSpecID specID, int where)
          
 Service lookupService(ID name)
          
 Service lookupService(ID name, int roleIndex)
          
 PeerGroup newGroup(Advertisement pgAdv)
          
 PeerGroup newGroup(PeerGroupID gid)
          
 PeerGroup newGroup(PeerGroupID gid, Advertisement impl, String name, String description)
          
 void publishGroup(String name, String description)
          
 int startApp(String[] arg)
          Normaly it is ignored.
 void stopApp()
          This is here for temporary class hierarchy reasons.
 void unref()
          Can only be called once.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.jxta.peergroup.PeerGroup
 

Field Detail

groupImpl

protected PeerGroup groupImpl
The peer group instance which backs this interface object.

Constructor Detail

RefCountPeerGroupInterface

RefCountPeerGroupInterface(GenericPeerGroup theRealThing)
Constructs an interface object that front-ends a given PeerGroup object.


RefCountPeerGroupInterface

RefCountPeerGroupInterface(GenericPeerGroup theRealThing,
                           Map roleMap)
Method Detail

startApp

public int startApp(String[] arg)
Normaly it is ignored. By definition, the interface object protects the real object's start/stop methods from being called However we have to make an exception for groups: even the creator of a group does not have access to the real object. So the interface has to forward startApp to the group, which is responsible for ensuring that it is executed only once (if needed).

Specified by:
startApp in interface Module
Overrides:
startApp in class PeerGroupInterface
Parameters:
arg - A table of strings arguments.
Returns:
int status indication.

stopApp

public void stopApp()
This is here for temporary class hierarchy reasons. it is normaly ignored. By definition, the interface object protects the real object's start/stop methods from being called In that case we have to make an exception. Most applications currently assume that they do not share the group object and that they do refer to the real object directly. They call stopApp to signify their intention of no-longer using the group. Now that groups are shared, we convert stopApp to unref for compatibility. We could also just do nothing and let the interface be GC'd but calling unref makes the group go away immediately if not shared, which is what applications that call stopApp expect.

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

getInterface

public Service getInterface()

Since THIS is already such an object, it could return itself. However, we want the group to know about the number of interfaces objects floating around, so, we'll have the group make a new one. That way, applications which want to use unref() on interfaces can avoid sharing interface objects by using getInterface() as a sort of clone with the additional ref-counting semantics.

Specified by:
getInterface in interface Service
Overrides:
getInterface in class PeerGroupInterface
Returns:
Service An interface object that implements this service and nothing more.

getWeakInterface

public PeerGroup getWeakInterface()
Returns a weak interface object that refers to this interface object rather than to the group directly. The reason for that is that we want the owner of this interface object to be able to invalidate all weak interface objects made out of this interface object, without them keeping a reference to the group object, and without necessarily having to terminate the group.

Specified by:
getWeakInterface in interface PeerGroup
Overrides:
getWeakInterface in class PeerGroupInterface
Returns:
PeerGroup A weak interface object that implements this group and nothing more.

finalize

public void finalize()
stopApp used to be the standard way of giving up on a group instance, but now that goup instance can be shared, the standard of letting go of a peer group is to stop referencing it. Since the peergroup has permanent referers: the threads of the services we need to use the interface object as a super-strong reference. When an interface is finalized, it calls the group's unref method. The unref method stopApps the group when the last reference is gone. To accelerate the un-referencing of groups, applications may call the interface's unref method, but that takes some dicipline since the interface object becomes unusable after that. So, aware applications that use it must also take care of always cloning the interface object instead of sharing it. For compatibility with current apps which call stopApp, we have the interface's stopApp() do nothing as with all other interface objects. An invoker that has a reference to the true group object can still call its stopApp method with the usual result.


unref

public void unref()
Can only be called once. After that the reference is no-longer usuable.

Specified by:
unref in interface PeerGroup
Overrides:
unref in class PeerGroupInterface

lookupService

public Service lookupService(ID name)
                      throws ServiceNotFoundException

Specified by:
lookupService in interface PeerGroup
Overrides:
lookupService in class PeerGroupInterface
Throws:
ServiceNotFoundException

lookupService

public Service lookupService(ID name,
                             int roleIndex)
                      throws ServiceNotFoundException

Specified by:
lookupService in interface PeerGroup
Overrides:
lookupService in class PeerGroupInterface
Throws:
ServiceNotFoundException

getRoleMap

public Iterator getRoleMap(ID name)

Specified by:
getRoleMap in interface PeerGroup
Overrides:
getRoleMap in class PeerGroupInterface

init

public void init(PeerGroup pg,
                 ID assignedID,
                 Advertisement impl)
This is here for class hierarchy reasons. it is normaly ignored. By definition, the interface object protects the real object's start/stop methods from being called

Specified by:
init in interface Module

getImplAdvertisement

public Advertisement getImplAdvertisement()

Specified by:
getImplAdvertisement in interface Service

getHomeThreadGroup

public ThreadGroup getHomeThreadGroup()

Specified by:
getHomeThreadGroup in interface PeerGroup

getLoader

public JxtaLoader getLoader()

Specified by:
getLoader in interface PeerGroup

isRendezvous

public boolean isRendezvous()

Specified by:
isRendezvous in interface PeerGroup

getPeerGroupAdvertisement

public PeerGroupAdvertisement getPeerGroupAdvertisement()

Specified by:
getPeerGroupAdvertisement in interface PeerGroup

getPeerAdvertisement

public PeerAdvertisement getPeerAdvertisement()

Specified by:
getPeerAdvertisement in interface PeerGroup

compatible

public boolean compatible(Element compat)

Specified by:
compatible in interface PeerGroup

loadModule

public Module loadModule(ID assignedID,
                         Advertisement impl)
                  throws ProtocolNotSupportedException,
                         PeerGroupException
FIXME: jice@jxta.org 20031103 Idealy, we'd need the groupAPI to offer a means to loadModule() without making a counted reference, so that group services can loadModule() things without preventing group termination. This could be achieved elegantly by making this the only behaviour available through a weak GroupInterface. So it would be enough to obtain a weak interface from one's group and then use its loadmodule method rather than that of the strong group reference. However that's a bit too big a change to be decided without more carefull consideration.

Specified by:
loadModule in interface PeerGroup
Throws:
ProtocolNotSupportedException
PeerGroupException

loadModule

public Module loadModule(ID assignedID,
                         ModuleSpecID specID,
                         int where)

Specified by:
loadModule in interface PeerGroup

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

getRendezVousService

public RendezVousService getRendezVousService()

Specified by:
getRendezVousService 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

getAccessService

public AccessService getAccessService()

Specified by:
getAccessService in interface PeerGroup

getPeerGroupID

public PeerGroupID getPeerGroupID()

Specified by:
getPeerGroupID in interface PeerGroup

getPeerID

public PeerID getPeerID()

Specified by:
getPeerID in interface PeerGroup

getPeerGroupName

public String getPeerGroupName()

Specified by:
getPeerGroupName in interface PeerGroup

getPeerName

public String getPeerName()

Specified by:
getPeerName in interface PeerGroup

getConfigAdvertisement

public ConfigParams getConfigAdvertisement()

Specified by:
getConfigAdvertisement in interface PeerGroup

getAllPurposePeerGroupImplAdvertisement

public ModuleImplAdvertisement getAllPurposePeerGroupImplAdvertisement()
                                                                throws Exception

Specified by:
getAllPurposePeerGroupImplAdvertisement in interface PeerGroup
Throws:
Exception

getParentGroup

public PeerGroup getParentGroup()
Specified by:
getParentGroup in interface PeerGroup

JXTA J2SE