2 * Copyright (c) 2001-2007 Sun Microsystems, Inc. All rights reserved.
4 * The Sun Project JXTA(TM) Software License
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * 3. The end-user documentation included with the redistribution, if any, must
17 * include the following acknowledgment: "This product includes software
18 * developed by Sun Microsystems, Inc. for JXTA(TM) technology."
19 * Alternately, this acknowledgment may appear in the software itself, if
20 * and wherever such third-party acknowledgments normally appear.
22 * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must
23 * not be used to endorse or promote products derived from this software
24 * without prior written permission. For written permission, please contact
25 * Project JXTA at http://www.jxta.org.
27 * 5. Products derived from this software may not be called "JXTA", nor may
28 * "JXTA" appear in their name, without prior written permission of Sun.
30 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
32 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SUN
33 * MICROSYSTEMS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
36 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
39 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 * JXTA is a registered trademark of Sun Microsystems, Inc. in the United
42 * States and other countries.
44 * Please see the license information page at :
45 * <http://www.jxta.org/project/www/license.html> for instructions on use of
46 * the license in source files.
48 * ====================================================================
50 * This software consists of voluntary contributions made by many individuals
51 * on behalf of Project JXTA. For more information on Project JXTA, please see
52 * http://www.jxta.org.
54 * This license is based on the BSD license adopted by the Apache Foundation.
57 package net.jxta.peergroup;
60 import net.jxta.access.AccessService;
61 import net.jxta.discovery.DiscoveryService;
62 import net.jxta.document.Advertisement;
63 import net.jxta.document.Element;
64 import net.jxta.endpoint.EndpointService;
65 import net.jxta.exception.PeerGroupException;
66 import net.jxta.exception.ProtocolNotSupportedException;
67 import net.jxta.exception.ServiceNotFoundException;
68 import net.jxta.id.ID;
69 import net.jxta.membership.MembershipService;
70 import net.jxta.peer.PeerID;
71 import net.jxta.peer.PeerInfoService;
72 import net.jxta.pipe.PipeService;
73 import net.jxta.platform.JxtaLoader;
74 import net.jxta.platform.Module;
75 import net.jxta.platform.ModuleClassID;
76 import net.jxta.platform.ModuleSpecID;
77 import net.jxta.protocol.ConfigParams;
78 import net.jxta.protocol.ModuleImplAdvertisement;
79 import net.jxta.protocol.PeerAdvertisement;
80 import net.jxta.protocol.PeerGroupAdvertisement;
81 import net.jxta.rendezvous.RendezVousService;
82 import net.jxta.resolver.ResolverService;
83 import net.jxta.service.Service;
85 import java.io.IOException;
86 import java.lang.ref.Reference;
87 import java.lang.ref.WeakReference;
89 import java.util.HashMap;
90 import java.util.Iterator;
95 * Peer groups are formed as a collection of peers that have agreed upon a
96 * common set of services. Each peer group is assigned a unique peer group ID
97 * and a peer group advertisement. The peer group advertisement contains a
98 * ModuleSpecID which refers to a module specification for this peer group.
100 * The peer group specification mandates each of the group services (membership,
101 * discovery, resolver, etc). Implementations of that specification are
102 * described by ModuleImplAdvertisements which are identified by the group's
103 * ModuleSpecID. Implementations are responsible for providing the services mandated
104 * by the specification.
106 * The java reference implementation achieves this by loading additional Modules
107 * which ModuleSpecIDs are listed by the group implementation advertisement.
109 * In order to fully participate in a group, a peer may need to authenticate
110 * with the group using the peer group membership service.
112 * @see net.jxta.peergroup.PeerGroupID
113 * @see net.jxta.service.Service
114 * @see net.jxta.peergroup.PeerGroupFactory
115 * @see net.jxta.protocol.PeerGroupAdvertisement
116 * @see net.jxta.protocol.ModuleImplAdvertisement
117 * @see net.jxta.platform.ModuleSpecID
118 * @see net.jxta.platform.ModuleClassID
120 public interface PeerGroup extends Service {
123 * Look for needed ModuleImplAdvertisement in this group.
125 public final static int Here = 0;
128 * Look for needed ModuleImplAdvertisement in the parent group of this group.
130 public final static int FromParent = 1;
133 * Look for needed ModuleImplAdvertisement in both this group and its parent.
135 public final static int Both = 2;
138 * Default life time for group advertisements in the publisher's cache.
141 // without casting to long we lose precision
142 public final static long DEFAULT_LIFETIME = (long) 1000 * (long) 3600 * (long) 24 * 365L;
145 * Default expiration time for discovered group advertisements. (2 weeks)
147 // without casting to long we lose precision
148 public final static long DEFAULT_EXPIRATION = (long) 1000 * (long) 3600 * (long) 24 * 14L;
151 * Global registry of instantiated peer groups. We allow only a single
152 * PeerGroup instance for a specific PeerGroupID within the context of the
153 * classloader JXTA is loaded into.
155 static class GlobalRegistry {
157 private final Map<ID, Reference<PeerGroup>> registry = new HashMap<ID, Reference<PeerGroup>>(8);
160 * Registers a new instance.
162 * @param gid the ID of the group of which an instance is being registered.
163 * @param pg the group instance being registered.
164 * @return false if the instance could not be registered because there
165 * was already such an instance registered.
167 public synchronized boolean registerInstance(PeerGroupID gid, PeerGroup pg) {
169 Reference<PeerGroup> ref = registry.get(gid);
171 if ((ref != null) && (ref.get() != null)) {
175 // If the ref is a dead instance, we can also replace it.
176 registry.put(gid, new WeakReference<PeerGroup>(pg));
181 * Unregisters a group instance (normally because the group is being
184 * @param gid the ID of the group of which an instance is unregistered.
185 * @param pg the group instance itself (serves as a credential).
186 * @return false if the group could not be unregistered because no such
187 * registration (exact ID, exact object) was not found.
189 public synchronized boolean unRegisterInstance(PeerGroupID gid, PeerGroup pg) {
191 Reference<PeerGroup> ref = registry.get(gid);
197 PeerGroup found = ref.get();
200 // Dead instance. Remove from table.
201 registry.remove(gid);
205 // Note the use of "!=", not "!equals()"
210 registry.remove(gid);
215 * Returns a running instance of the peergroup with given ID if any
216 * exists. The instance should be {@link PeerGroup#unref()}ed when it is
219 * @param gid the id of the group of which an instance is wanted.
220 * @return the group, or {@code null} if no instance exists.
222 public synchronized PeerGroup lookupInstance(PeerGroupID gid) {
224 Reference<PeerGroup> ref = registry.get(gid);
230 PeerGroup pg = ref.get();
233 // Dead instance. remove from table.
234 registry.remove(gid);
238 // Returns an interface object. Therefore a module that got the
239 // peergroup through lookup cannot unregister it if the group
240 // protects itself by returning an interface object different from
241 // the group object. In general only the group itself can
242 // unregister when being torn down. Unregistration will also be
243 // automatic if the grp object is GC'ed (the references are weak
245 return (PeerGroup) pg.getInterface();
249 * Returns a running instance of the peergroup with given ID if any
252 * @param gid The id of the group of which an instance is wanted.
253 * @return The group, or {@code null} if no instance exists.
255 synchronized PeerGroup getInstance(PeerGroupID gid) {
257 Reference<PeerGroup> ref = registry.get(gid);
263 PeerGroup pg = ref.get();
266 // Dead instance. remove from table.
267 registry.remove(gid);
275 * Returns {@code true} if there is a registered peergroup of the
278 * @param gid the id of the group of which an instance is wanted.
279 * @return {@code} true if the peergroup is currently registered
282 public synchronized boolean registeredInstance(PeerGroupID gid) {
284 Reference<PeerGroup> ref = registry.get(gid);
290 PeerGroup pg = ref.get();
293 // Dead instance. remove from table.
294 registry.remove(gid);
303 * Well known classes for the basic services.
305 * <p/>FIXME: we should make a "well-known ID" encoding implementation that
306 * has its own little name space of human readable names...later.
307 * To keep their string representation shorter, we put our small spec
308 * or role pseudo unique ID at the front of the second UUID string.
309 * Base classes do not need an explicit second UUID string because it is
312 * <p/>The type is always the last two characters, no-matter the total length.
316 * Prefix string for all of the Well Known IDs declared in this interface.
318 static final String WK_ID_PREFIX = ID.URIEncodingName + ":" + ID.URNNamespace + ":uuid-DeadBeefDeafBabaFeedBabe";
321 * Well known module class identifier: peer group
323 public final static ModuleClassID peerGroupClassID =
324 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000105"));
327 * Well known module class identifier: resolver service
329 public final static ModuleClassID resolverClassID =
330 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000205"));
333 * Well known module class identifier: discovery service
335 public final static ModuleClassID discoveryClassID =
336 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000305"));
339 * Well known module class identifier: pipe service
341 public final static ModuleClassID pipeClassID =
342 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000405"));
345 * Well known module class identifier: membership service
347 public final static ModuleClassID membershipClassID =
348 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000505"));
351 * Well known module class identifier: rendezvous service
353 public final static ModuleClassID rendezvousClassID =
354 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000605"));
357 * Well known module class identifier: peerinfo service
359 public final static ModuleClassID peerinfoClassID =
360 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000705"));
363 * Well known module class identifier: endpoint service
365 public final static ModuleClassID endpointClassID =
366 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000805"));
368 // FIXME: EndpointProtocols should probably all be of the same class
369 // and of different specs and roles... But we'll take a shortcut for now.
372 * Well known module class identifier: tcp protocol
374 public final static ModuleClassID tcpProtoClassID =
375 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000905"));
378 * Well known module class identifier: http protocol
380 public final static ModuleClassID httpProtoClassID =
381 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000A05"));
384 * Well known module class identifier: router protocol
386 public final static ModuleClassID routerProtoClassID =
387 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000B05"));
390 * Well known module class identifier: application
392 public final static ModuleClassID applicationClassID =
393 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000C05"));
396 * Well known module class identifier: tlsProtocol
398 public final static ModuleClassID tlsProtoClassID =
399 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000D05"));
402 * Well known module class identifier: ProxyService
404 public final static ModuleClassID proxyClassID =
405 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000E05"));
408 * Well known module class identifier: RelayProtocol
410 public final static ModuleClassID relayProtoClassID =
411 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000000F05"));
414 * Well known module class identifier: AccessService
416 public final static ModuleClassID accessClassID =
417 ModuleClassID.create(URI.create(WK_ID_PREFIX + "0000001005"));
420 * Well known group specification identifier: the platform
422 public final static ModuleSpecID refPlatformSpecID =
423 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000010106"));
426 * Well known group specification identifier: the Network Peer Group
428 public final static ModuleSpecID refNetPeerGroupSpecID =
429 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000010206"));
432 * Well known service specification identifier: the standard resolver
434 public final static ModuleSpecID refResolverSpecID =
435 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000020106"));
438 * Well known service specification identifier: the standard discovery
440 public final static ModuleSpecID refDiscoverySpecID =
441 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000030106"));
444 * Well known service specification identifier: the standard pipe service
446 public final static ModuleSpecID refPipeSpecID =
447 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000040106"));
450 * Well known service specification identifier: the standard membership
452 public final static ModuleSpecID refMembershipSpecID =
453 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000050106"));
456 * Well known service specification identifier: the standard rendezvous
458 public final static ModuleSpecID refRendezvousSpecID =
459 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000060106"));
462 * Well known service specification identifier: the standard peerinfo
464 public final static ModuleSpecID refPeerinfoSpecID =
465 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000070106"));
468 * Well known service specification identifier: the standard endpoint
470 public final static ModuleSpecID refEndpointSpecID =
471 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000080106"));
474 * Well known endpoint protocol specification identifier: the standard
475 * tcp endpoint protocol
477 public final static ModuleSpecID refTcpProtoSpecID =
478 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000090106"));
481 * Well known endpoint protocol specification identifier: the standard
482 * http endpoint protocol
484 public final static ModuleSpecID refHttpProtoSpecID =
485 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "0000000A0106"));
488 * Well known endpoint protocol specification identifier: the standard
491 public final static ModuleSpecID refRouterProtoSpecID =
492 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "0000000B0106"));
495 * Well known endpoint protocol specification identifier: the standard
496 * tls endpoint protocol
498 public final static ModuleSpecID refTlsProtoSpecID =
499 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "0000000D0106"));
502 * Well known group specification identifier: an all purpose peer group
503 * specification. The java reference implementation implements it with
504 * the StdPeerGroup class and all the standard platform services and no
505 * endpoint protocols.
507 public final static ModuleSpecID allPurposePeerGroupSpecID =
508 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000010306"));
511 * Well known application: the shell
513 public final static ModuleSpecID refShellSpecID =
514 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "0000000C0206"));
517 * Well known application: the Proxy
519 public final static ModuleSpecID refProxySpecID =
520 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "0000000E0106"));
523 * Well known endpoint protocol specification identifier: the standard
524 * relay endpoint protocol
526 public final static ModuleSpecID refRelayProtoSpecID =
527 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "0000000F0106"));
530 * Well known access specification identifier: the standard
533 public final static ModuleSpecID refAccessSpecID =
534 ModuleSpecID.create(URI.create(WK_ID_PREFIX + "000000100106"));
537 * The global registry of Peer Group instances. Operations involving the
538 * instantiation or orderly shutdown of Peer Groups should synchronize upon
541 final static GlobalRegistry globalRegistry = new GlobalRegistry();
544 * Returns the Thread Group in which threads for this peer group will live.
545 * This is currently used only for debugging purposes so that the source of
546 * a thread can be determined.
548 * @return ThreadGroup
550 public ThreadGroup getHomeThreadGroup();
553 * Returns the class loader for this group.
555 * @return JxtaLoader The JXTA Class loader used by this group.
557 public JxtaLoader getLoader();
560 * Returns the whether the group member is a Rendezvous peer for the group.
562 * @return boolean true if the peer is a rendezvous for the group.
564 public boolean isRendezvous();
567 * Return the PeerGroupAdvertisement for this group.
569 * @return PeerGroupAdvertisement this Group's advertisement.
571 public PeerGroupAdvertisement getPeerGroupAdvertisement();
574 * Return the PeerAdvertisement of the local Peer within this Peer Group.
576 * @return the PeerAdvertisement of the local Peer within this Peer Group.
578 public PeerAdvertisement getPeerAdvertisement();
581 * Lookup for a service by name.
583 * @param name the service identifier.
584 * @return Service, the Service registered by that name
585 * @throws ServiceNotFoundException could not find the service requested
587 public Service lookupService(ID name) throws ServiceNotFoundException;
590 * Lookup for a service by class ID and index in a map.
592 * More than one service in a group may be of a given ModuleClass.
593 * However each of them has a unique assigned ID which serves as the
594 * index in the map of services. In most cases, there is only one
595 * service of each given Module Class, and the ID of that Module Class
596 * is the assigned ID. Otherwise, the group may have a list of existing
597 * assigned ID per base class. This routine may be used to retrieve
598 * services of the given Module Class and index in that list.
599 * In the absence of a mapping, index 0 is still valid and
600 * corresponds to the service which assigned ID is exactly the
602 * Group objects with a map are normally wrappers tailored
603 * specially by the loader of a module (often the group itself) in order
604 * to provide a map appropriate for that module. Modules that do not use
605 * more than one service of a given base class normally never need to call
606 * this method; lookupService(ID) is equivalent to lookupService(ID, 0)
607 * and will transparently remap index 0 to whatever the group's
608 * structure defines as the default for the invoking service.
610 * Note: traditionally, the given ID is expected to be a base Module
611 * Class ID, and the assigned ID of a Module is a Class ID of the
612 * same base class with a role suffix to make it unique. If the given
613 * ID already contains a role suffix, there may exist an entry for
614 * it in the map anyway, if not (which is the expected use pattern),
615 * then only index 0 exists and the given ID is used whole and
618 * @param name the service identifier
619 * @param roleIndex the index in the list of assigned IDs that match
621 * @return Service, the corresponding Service
622 * @throws ServiceNotFoundException Could not find the service requested.
625 public Service lookupService(ID name, int roleIndex) throws ServiceNotFoundException;
628 * Returns the map of the assigned IDs currently associated with the given
629 * ModuleClassID by this PeerGroup object. The IDs are returned in the order
630 * of their index in the map. So the first ID returned will be identical to
631 * what would be returned by the lookup method for the given ID and index 0.
632 * If there is no explicit such map, this method will return a singleton
633 * containing the given ID as this is the default mapping. There is no
634 * guarantee that any of the returned IDs correspond to an actually
635 * registered service. This method only maps IDs.
637 * @param name The ModuleClassID for which the map is desired.
638 * @return Iterator An iterator on a collection of the IDs to which the given ID maps.
641 public Iterator getRoleMap(ID name);
644 * Return true if the provided compatibility statement is compatible with this group.
646 * @param compat compatibility element
647 * @return boolean True if the statement is compatible.
649 public boolean compatible(Element compat);
652 * Load a Module from a ModuleImplAdv.
654 * Compatibility is checked and load is attempted. If compatible and
655 * loaded successfully, the resulting Module is initialized and returned.
656 * In most cases the other loadModule() method should be preferred, since
657 * unlike this one, it will seek many compatible implementation
658 * advertisements and try them all until one works. The home group of the new
659 * module (its' parent group if the new Module is a group) will be this group.
661 * @param assignedID Id to be assigned to that module (usually its ClassID).
662 * @param impl An implementation advertisement for that module.
663 * @return Module the module loaded and initialized.
664 * @throws ProtocolNotSupportedException The implementation described by the
665 * advertisement is incompatible with this peer. The module cannot be loaded.
666 * @throws PeerGroupException The module could not be loaded or initialized
668 public Module loadModule(ID assignedID, Advertisement impl) throws ProtocolNotSupportedException, PeerGroupException;
671 * Load a module from a ModuleSpecID
673 * Advertisement is sought, compatibility is checked on all candidates
674 * and load is attempted. The first one that is compatible and loads
675 * successfully is initialized and returned.
677 * @param assignedID Id to be assigned to that module (usually its ClassID).
678 * @param specID The specID of this module.
679 * @param where May be one of: {@code Here}, {@code FromParent}, or
680 * {@code Both}, meaning that the implementation advertisement will be
681 * searched in this group, its parent or both. As a general guideline, the
682 * implementation advertisements of a group should be searched in its
683 * prospective parent (that is {@code Here}), the implementation
684 * advertisements of a group standard service should be searched in the same
685 * group than where this group's advertisement was found (that is,
686 * {@code FromParent}), while applications may be sought more freely
688 * @return Module the new module, or null if no usable implementation was
691 public Module loadModule(ID assignedID, ModuleSpecID specID, int where);
694 * Publish this group's Peer Group Advertisement. The Advertisement will be
695 * published using the parent peer group's Discovery service.
697 * Calling this method is only useful if the group is being created
698 * from scratch and the PeerGroup advertisement has not been
699 * created beforehand. In such a case, the group has never been named or
700 * described. Therefore this information has to be supplied here.
702 * @param name The name of this group.
703 * @param description The description of this group.
704 * @throws IOException The publication could not be accomplished
705 * because of a network or storage failure.
707 public void publishGroup(String name, String description) throws IOException;
710 * Valuable application helpers: Various methods to instantiate
715 * Instantiate a peer group from the provided advertisement. This peer
716 * group will be the parent of the newly instantiated peer group.
718 * The pgAdv itself may be all new and unpublished. Therefore, the two
719 * typical uses of this routine are:
722 * <li>Creating an all new group with a new ID while using an existing
723 * and published implementation. (Possibly a new one published for
724 * that purpose). The information should first be gathered in a new
725 * PeerGroupAdvertisement which is then passed to this method.</li>
727 * <li>Instantiating a group which advertisement has already been
728 * discovered (therefore there is no need to find it by groupID
732 * @param pgAdv The advertisement for the group to be instantiated.
733 * @return PeerGroup the initialized (but not started) peergroup.
734 * @throws PeerGroupException For problems instantiating the peer group.
736 public PeerGroup newGroup(Advertisement pgAdv) throws PeerGroupException;
739 * Instantiates a peer group from its elementary pieces
740 * and publishes the corresponding PeerGroupAdvertisement.
741 * The pieces are: the groups implementation adv, the group id,
742 * the name and description.
744 * The typical use of this routine is creating a whole new group based
745 * on a newly created and possibly unpublished implementation adv.
747 * This is a convenience method equivalent to either:
750 * newGrp = thisGroup.loadModule(gid, impl);
751 * newGrp.publishGroup(name, description);
753 * or, but only if the implementation advertisement has been published:
756 * newPGAdv = AdvertisementFactory.newAdvertisement(
757 * PeerGroupAdvertisement.getAdvertisementType());
758 * newPGAdv.setPeerGroupID(gid);
759 * newPGAdv.setModuleSpecID(impl.getModuleSpecID());
760 * newPGAdv.setName(name);
761 * newPGAdv.setDescription(description);
762 * newGrp = thisGroup.newGroup(newPGAdv);
765 * @param gid The ID of that group. If <code>null</code> then a new group ID
767 * @param impl The advertisement of the implementation to be used.
768 * @param name The name of the group.
769 * @param description A description of this group.
770 * @return PeerGroup the initialized (but not started) peergroup.
771 * @throws PeerGroupException Thrown if the group could not be instantiated.
773 public PeerGroup newGroup(PeerGroupID gid, Advertisement impl, String name, String description) throws PeerGroupException;
776 * Instantiate a group from its Peer Group ID only. Use this when using a
777 * group that has already been published and discovered.
779 * The typical uses of this routine are therefore:
782 * <li>Instantiating a peer group which is assumed to exist and whose Peer
783 * Group ID is already known.</li>
785 * <li>Creating a new peer group instance using an already published
786 * Group advertisement, typically published for that purpose. All other
787 * referenced advertisements must also be available.</li>
790 * To create a group from a known implAdv, just use
791 * {@link #loadModule(ID,Advertisement)} or even:<p>
794 * grp = new GroupSubClass();
795 * grp.init(parentGroup, gid, impladv);
798 * then, <strong>REMEMBER TO PUBLISH THE GROUP IF IT IS ALL NEW.</strong>
800 * @param gid the groupID.
801 * @return PeerGroup the initialized (but not started) peergroup.
802 * @throws PeerGroupException Thrown if the group could not be instantiated.
804 public PeerGroup newGroup(PeerGroupID gid) throws PeerGroupException;
807 * Shortcuts to the well-known services, in order to avoid calls to
808 * {@link #lookupService(ID)}.
812 * Return the Rendezvous Service for this Peer Group. This service is
813 * optional and may not be present in all groups.
815 * @return The Rendezvous Service for this Peer Group or <code>null</code>
816 * if there is no Rendezvous Service in this Peer Group.
818 public RendezVousService getRendezVousService();
821 * Return the Endpoint Service for this Peer Group. This service is
822 * present in every Peer Group.
824 * @return EndpointService The Endpoint Service for this Peer Group.
826 public EndpointService getEndpointService();
829 * Return the Resolver Service for this Peer Group. This service is
830 * present in every Peer Group.
832 * @return ResolverService The Resolver Service for this Peer Group.
834 public ResolverService getResolverService();
837 * Return the Discovery Service for this Peer Group.
839 * @return The Discovery Service for this Peer Group or <code>null</code>
840 * if there is no PeerInfo Service in this Peer Group.
842 public DiscoveryService getDiscoveryService();
845 * Return the PeerInfo Service for this Peer Group.
847 * @return The PeerInfo Service for this Peer Group or <code>null</code>
848 * if there is no PeerInfo Service in this Peer Group.
850 public PeerInfoService getPeerInfoService();
853 * Return the Membership Service for this Peer Group. This service is
854 * present in every Peer Group.
856 * @return MembershipService The Membership Service for this Peer Group.
858 public MembershipService getMembershipService();
861 * Return the Pipe Service for this Peer Group.
863 * @return The Pipe Service for this Peer Group or <code>null</code> if
864 * there is no Pipe Service in this Peer Group.
866 public PipeService getPipeService();
869 * Return the Access Service for this Peer Group. This service is
870 * present in every Peer Group.
872 * @return AccessService The Access Service for this Peer Group.
875 public AccessService getAccessService();
877 // A few convenience methods. This information is available from the peer and peergroup advertisement.
880 * Return the Peer Group ID of this Peer Group.
882 * @return PeerGroupId The Peer Group ID of this Peer Group.
884 public PeerGroupID getPeerGroupID();
887 * Return the Peer ID by which this Peer is known within this Peer Group.
889 * @return the Peer ID by which this Peer is known within this Peer Group.
891 public PeerID getPeerID();
894 * Return the Name of this group. This name is not canonical, meaning that
895 * there may be other groups with the same name.
897 * @return String This groups's name or <code>null</code> if no name was
900 public String getPeerGroupName();
903 * Return the name of the local peer within this group. This name is not
904 * canonical, meaning that there may be other peers with the same name.
906 * @return String This peer's name or <code>null</code> if no name was
909 public String getPeerName();
912 * Returns the config advertisement for this peer in this group (if any).
914 * @return The advertisement or <code>null</code> if none is available.
916 public ConfigParams getConfigAdvertisement();
919 * Get an all purpose peerGroup ModuleImplAdvertisement that is compatible
920 * with this group. This impl adv can be used to create any group that
921 * relies only on the standard services. Or to derive other impl advs, using
922 * this impl advertisement as a basis.
924 * This defines a peergroup implementation that can be used for
925 * many purposes, and from which one may derive slightly different
926 * peergroup implementations.
928 * This definition is always the same and has a well known ModuleSpecID.
929 * It includes the basic service, no protocols and the shell for main
932 * The user must remember to change the specID if the set of services
933 * protocols or applications is altered before use.
935 * @return ModuleImplAdvertisement The new peergroup impl adv.
936 * @throws Exception if an error occurs while creating the implementation advertisement
938 public ModuleImplAdvertisement getAllPurposePeerGroupImplAdvertisement() throws Exception;
941 * Explicitly notifies a group interface that it will no-longer be
942 * used (similar to dispose). Does nothing to a real group object,
943 * only has an effect on a group interface.
948 * Returns a weak interface object that represents this
951 * A weak interface object has no life-cycle privileges over
952 * the group that it represents and therefore its users have
953 * no accountability. A weak interface object is safe to
954 * give away but holds no promise of sustained validity.
956 * Whatever code gave away a weak interface object retains
957 * the power of terminating the group object from which it
958 * was obtained, thereby making the weak interface
961 * A weak interface object is immutable; its unref and stopApp
962 * methods do nothing. Its validity is exactly that of the
963 * group or interface object from which it was obtained.
965 * A weak interface object can be obtained from an interface
966 * object, or from a real group object, or from a weak interface
967 * object. In the later case, the object returned may be
968 * the original weak interface object since such objects
971 * Whatever code obtains a weak interface object from a group object
972 * or regular interface object, remains entirely liable for invoking unref
973 * on the initial object before discarding it. Giving away a weak interface
974 * object is not equivalent to transferring ownership of the original.
976 * @return PeerGroup A weak interface object that represents this
980 public PeerGroup getWeakInterface();
983 * Returns the parent group of this group. Not all groups have parents and
984 * some implementations may not reveal their parents.
986 * @return PeerGroup the parent group or <code>null</code> if a parent group
990 public PeerGroup getParentGroup();
993 * Returns the location of the parent of all items that this peer group is
994 * using for persistently storing its preferences, cache, persistent store,
995 * properties, etc. May be {@code null} if the peergroup has no defined
996 * location for storing persistent data.
998 * @return The location of the parent of all persistent items stored by
1002 public URI getStoreHome();