📄 peergroup.java
字号:
/*
* Copyright (c) 2001 Sun Microsystems, Inc. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Sun Microsystems, Inc. for Project JXTA."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact Project JXTA at http://www.jxta.org.
*
* 5. Products derived from this software may not be called "JXTA",
* nor may "JXTA" appear in their name, without prior written
* permission of Sun.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL SUN MICROSYSTEMS OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of Project JXTA. For more
* information on Project JXTA, please see
* <http://www.jxta.org/>.
*
* This license is based on the BSD license adopted by the Apache Foundation.
*
* $Id: PeerGroup.java,v 1.2 2002/03/04 20:19:20 echtcherbina Exp $
*/
package net.jxta.peergroup;
import net.jxta.discovery.DiscoveryService;
import net.jxta.document.Advertisement;
import net.jxta.document.Element;
import net.jxta.endpoint.EndpointService;
import net.jxta.exception.ServiceNotFoundException;
import net.jxta.exception.PeerGroupException;
import net.jxta.exception.ProtocolNotSupportedException;
import net.jxta.exception.JxtaError;
import net.jxta.id.ID;
import net.jxta.id.IDFactory;
import net.jxta.membership.MembershipService;
import net.jxta.peer.PeerID;
import net.jxta.peer.PeerInfoService;
import net.jxta.peergroup.PeerGroupID;
import net.jxta.pipe.PipeService;
import net.jxta.platform.JxtaLoader;
import net.jxta.platform.Module;
import net.jxta.platform.ModuleClassID;
import net.jxta.platform.ModuleSpecID;
import net.jxta.protocol.PeerAdvertisement;
import net.jxta.protocol.PeerGroupAdvertisement;
import net.jxta.protocol.ModuleImplAdvertisement;
import net.jxta.rendezvous.RendezVousService;
import net.jxta.resolver.ResolverService;
import net.jxta.service.Service;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;
import java.net.UnknownServiceException;
import java.lang.ClassNotFoundException;
/**
* Peer groups are formed
* as a collection of peers that have agreed upon a common set of services.
* Each peer group is assigned a unique peer group ID and a peer group
* advertisement. The peer group advertisement contains a ModuleSpecID
* which refers to a module specification for this peer group.
*
* <p>The peer group specification mandates each of the group services (membership,
* discovery, resolver, etc). Implementations of that specification are
* described by ModuleImplAdvertisements which are identified by the group's
* ModuleSpecID. Implementations are responsible for providing the services mandated
* by the specification.
*
* The java reference implementation achieves
* this by loading additional Modules which ModuleSpecIDs are listed by the group
* implementation advertisement.
*
* <p>In order to participate in a group, a peer needs to join the group
* using the peer group membership service.
*
* <p> JXTA comes with two subclasses of peer groups:
*
* <ul type-disc>
*
* <li> <strong>Platform</strong>: this is used to represent the <em>World</em>
* group. Every peer, when booting, becomes part of this group. This group
* provides the minimum core services needed to find and instantiate other
* groups on a peer. <strong>Platform</strong> has the privilege of assigning
* a new ID to the peer, if it does not already have one. The <em>World</em>
* group's ID is invariant.</li>
*
* <li> <strong>StdPeergroup</strong>: this is currently used to implement
* all other kinds of peer groups.
* The first such group that is instantiated after booting is known as
* <em>The Net Peer Group</em>. When <strong>Platform</strong> starts it may
* optionaly search for <em>The Net Peer Group</em> on the local network and,
* if found, instantiate it. Otherwise a default configuration of
* <em>The Net Peer Group</em> is instanciated.
*
* A non-default configuration of <em>The Net Peer Group</em> may be set-up
* by the administrator in charge of the network domain inside which the peer
* is booting. <em>The Net Peer Group</em> is discovered via the DiscoveryService
* protocol. Many such groups may be configured by an administrator.<br>
*
* <strong>StdPeergroup</strong> may also be used to implement User-defined
* peer groups: Users can create new peer groups which use their own set of
* customized services.
*</li>
*</ul>
*
* @see net.jxta.peergroup.PeerGroupID
* @see net.jxta.service.Service
* @see net.jxta.peergroup.PeerGroupFactory
* @see net.jxta.protocol.PeerGroupAdvertisement
* @see net.jxta.protocol.ModuleImplAdvertisement
* @see net.jxta.platform.ModuleSpecID
* @see net.jxta.platform.ModuleClassID
*
* @version $Revision: 1.2 $
* @since JXTA 1.0 */
public interface PeerGroup extends Service {
/**
* Look for needed ModuleImplAdvertisement in this group.
*/
public static final int Here = 0;
/**
* Look for needed ModuleImplAdvertisement in the parent group of this group.
*/
public static final int FromParent = 1;
/**
* Look for needed ModuleImplAdvertisement in both this group and its parent.
*/
public static final int Both = 2;
/**
* Default life time for group advertisements in the publisher's cache.
* (a year)
*/
public static final long DEFAULT_LIFETIME = 1000 * 3600 * 24 * 365;
/**
* Default expiration time for discovered group advertisements. (2 weeks)
*/
public static final long DEFAULT_EXPIRATION = 1000 * 3600 * 24 * 14;
/**
* An inner class used to create static well-known identifiers.
*/
class IdMaker {
// This method serves to catch the MalformedURLException.
// Don't know how to catch it from the static init context.
static ID mkID( String s ) {
try {
return IDFactory.fromURL(new URL( "urn", "", "jxta:uuid-" + s));
} catch (MalformedURLException absurd) {
// Fall through.
} catch (UnknownServiceException absurd2) {
// Fall through.
}
throw new JxtaError("Hardcoded Spec and Class IDs are malformed.");
}
}
/**
* Well known classes for the basic services.
* FIXME: we should make a "well-known ID" encoding implementation that
* has its own little name space of human readable names...later.
* To keep their string representation shorter, we put our small spec
* or role pseudo unique ID at the front of the second UUID string.
* Base classes do not need an explicit second UUID string because it is
* all 0.
* The type is always the last two characters, nomatter the total length.
*/
/**
* Well known module class identifier: peer group
*/
public static final ModuleClassID peerGroupClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000001"
+ "05" );
/**
* Well known module class identifier: resolver service
*/
public static final ModuleClassID resolverClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000002"
+ "05" );
/**
* Well known module class identifier: discovery service
*/
public static final ModuleClassID discoveryClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000003"
+ "05" );
/**
* Well known module class identifier: pipe service
*/
public static final ModuleClassID pipeClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000004"
+ "05" );
/**
* Well known module class identifier: membership service
*/
public static final ModuleClassID membershipClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000005"
+ "05" );
/**
* Well known module class identifier: rendezvous service
*/
public static final ModuleClassID rendezvousClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000006"
+ "05" );
/**
* Well known module class identifier: peerinfo service
*/
public static final ModuleClassID peerinfoClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000007"
+ "05" );
/**
* Well known module class identifier: endpoint service
*/
public static final ModuleClassID endpointClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000008"
+ "05" );
/*
* FIXME: EndpointProtocols should probably all be of the same class
* and of different specs and roles... But we'll take a shortcut for now.
*/
/**
* Well known module class identifier: tcp protocol
*/
public static final ModuleClassID tcpProtoClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000009"
+ "05" );
/**
* Well known module class identifier: http protocol
*/
public static final ModuleClassID httpProtoClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe0000000A"
+ "05" );
/**
* Well known module class identifier: router protocol
*/
public static final ModuleClassID routerProtoClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe0000000B"
+ "05" );
/**
* Well known module class identifier: application
*/
public static final ModuleClassID applicationClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe0000000C"
+ "05" );
/**
* Well known module class identifier: tlsProtocol
*/
public static final ModuleClassID tlsProtoClassID = (ModuleClassID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe0000000D"
+ "05" );
/**
* Well known group specification identifier: the platform
*/
public static final ModuleSpecID refPlatformSpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000001"
+ "01"
+ "06" );
/**
* Well known group specification identifier: the Network Peer Group
*/
public static final ModuleSpecID refNetPeerGroupSpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000001"
+ "02"
+ "06" );
/**
* Well known service specification identifier: the standard resolver
*/
public static final ModuleSpecID refResolverSpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000002"
+ "01"
+ "06" );
/**
* Well known service specification identifier: the standard discovery
*/
public static final ModuleSpecID refDiscoverySpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000003"
+ "01"
+ "06" );
/**
* Well known service specification identifier: the standard pipe
*/
public static final ModuleSpecID refPipeSpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000004"
+ "01"
+ "06" );
/**
* Well known service specification identifier: the standard membership
*/
public static final ModuleSpecID refMembershipSpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000005"
+ "01"
+ "06" );
/**
* Well known service specification identifier: the standard rendezvous
*/
public static final ModuleSpecID refRendezvousSpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000006"
+ "01"
+ "06" );
/**
* Well known service specification identifier: the standard peerinfo
*/
public static final ModuleSpecID refPeerinfoSpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000007"
+ "01"
+ "06" );
/**
* Well known service specification identifier: the standard endpoint
*/
public static final ModuleSpecID refEndpointSpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000008"
+ "01"
+ "06" );
/**
* Well known endpoint protocol specification identifier: the standard
* tcp endpoint protocol
*/
public static final ModuleSpecID refTcpProtoSpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe00000009"
+ "01"
+ "06" );
/**
* Well known endpoint protocol specification identifier: the standard
* http endpoint protocol
*/
public static final ModuleSpecID refHttpProtoSpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe0000000A"
+ "01"
+ "06" );
/**
* Well known endpoint protocol specification identifier: the standard
* router
*/
public static final ModuleSpecID refRouterProtoSpecID = (ModuleSpecID)
IdMaker.mkID( "DeadBeefDeafBabaFeedBabe0000000B"
+ "01"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -