📄 platform.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: Platform.java,v 1.2 2002/03/04 21:42:59 echtcherbina Exp $
*/
package net.jxta.impl.peergroup;
import java.util.*;
import java.io.*;
import net.jxta.peer.*;
import net.jxta.endpoint.*;
import net.jxta.peergroup.*;
import net.jxta.rendezvous.*;
import net.jxta.protocol.*;
import net.jxta.id.ID;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import net.jxta.impl.discovery.*;
import net.jxta.impl.resolver.*;
import net.jxta.impl.endpoint.*;
import net.jxta.impl.discovery.*;
import net.jxta.impl.pipe.*;
import net.jxta.impl.rendezvous.*;
import net.jxta.impl.document.*;
import net.jxta.impl.protocol.*;
import net.jxta.service.*;
import net.jxta.resolver.*;
import net.jxta.exception.*;
import net.jxta.credential.*;
import net.jxta.document.*;
import net.jxta.impl.protocol.*;
import net.jxta.impl.endpoint.tcp.*;
import net.jxta.impl.endpoint.http.*;
import net.jxta.impl.endpoint.tls.*;
import net.jxta.impl.endpoint.EndpointRouter;
import net.jxta.platform.*;
import org.apache.log4j.Category; import org.apache.log4j.Priority;
/**
* The platform as a whole implements the PeerGroup Interface.
* Here we implement it as a subclass of the GenericPeerGroup.
* We do not need a membership service, because we never realy join
* the group. Peers in the Plaform group just do discovery between them,
* and the requests made within the group are always accepted.
* ...we'll see if it takes a dummy membership service to satify the
* mechanics, or not...
*/
public class Platform extends StdPeerGroup {
private static final Category LOG =
Category.getInstance(Platform.class.getName());
Configurator config;
private ModuleImplAdvertisement mkPlatformImplAdv() throws Exception {
// Start building the implAdv for the platform intself.
ModuleImplAdvertisement platformDef = mkImplAdvBuiltin(
PeerGroup.refPlatformSpecID,
"net.jxta.impl.peergroup.Platform",
"Standard Platform Reference Implementation");
// Build the param section now.
StdPeerGroupParamAdv paramAdv = new StdPeerGroupParamAdv();
Hashtable protos = new Hashtable();
Hashtable services = new Hashtable();
Hashtable apps = new Hashtable();
// Build ModuleImplAdvs for each of the modules
ModuleImplAdvertisement moduleAdv;
moduleAdv =
mkImplAdvBuiltin(refResolverSpecID,
"net.jxta.impl.resolver.ResolverServiceImpl",
"Reference Implementation of the ResolverService service");
services.put(resolverClassID, moduleAdv);
moduleAdv =
mkImplAdvBuiltin(refDiscoverySpecID,
"net.jxta.impl.discovery.DiscoveryServiceImpl",
"Reference Implementation of the DiscoveryService service");
services.put(discoveryClassID, moduleAdv);
moduleAdv =
mkImplAdvBuiltin(refPipeSpecID,
"net.jxta.impl.pipe.PipeServiceImpl",
"Reference Implementation of the PipeService service");
services.put(pipeClassID, moduleAdv);
moduleAdv =
mkImplAdvBuiltin(refMembershipSpecID,
"net.jxta.impl.membership.NullMembershipService",
"Reference Implementation of the MembershipService service");
services.put(membershipClassID, moduleAdv);
moduleAdv =
mkImplAdvBuiltin(refRendezvousSpecID,
"net.jxta.impl.rendezvous.RendezVousServiceImpl",
"Reference Implementation of the Rendezvous service");
services.put(rendezvousClassID, moduleAdv);
moduleAdv =
mkImplAdvBuiltin(refPeerinfoSpecID,
"net.jxta.impl.peer.PeerInfoServiceImpl",
"Reference Implementation of the Peerinfo service");
services.put(peerinfoClassID, moduleAdv);
moduleAdv =
mkImplAdvBuiltin(refEndpointSpecID,
"net.jxta.impl.endpoint.EndpointServiceImpl",
"Reference Implementation of the EndpointService service");
services.put(endpointClassID, moduleAdv);
moduleAdv =
mkImplAdvBuiltin(refTcpProtoSpecID,
"net.jxta.impl.endpoint.tcp.TcpTransport",
"Reference Implementation of the Tcp Proto");
protos.put(tcpProtoClassID, moduleAdv);
// allows the user to specify an alternate HTTP transport
// implementation
//PDA requirement 28.02.2002
//HttpTransport is not used for PDAs for the time being.
/*String httpTransportClassname =
"net.jxta.impl.endpoint.servlethttp.ServletHttpTransport";
String moduleDescription =
"Reference Implementation of the Http Proto";
String httpTransportProp = System.getProperty ("HTTP_TRANSPORT");
if (httpTransportProp != null) {
httpTransportClassname = httpTransportProp;
moduleDescription = "Alernate Http Proto implementation";
}
moduleAdv =
mkImplAdvBuiltin(refHttpProtoSpecID,
httpTransportClassname,
moduleDescription);
protos.put(httpProtoClassID, moduleAdv);*/
//PDA requirement
moduleAdv =
mkImplAdvBuiltin(refRouterProtoSpecID,
"net.jxta.impl.endpoint.EndpointRouter",
"Reference Implementation of the Router");
protos.put(routerProtoClassID, moduleAdv);
moduleAdv =
mkImplAdvBuiltin(refTlsProtoSpecID,
"net.jxta.impl.endpoint.tls.TlsTransport",
"Reference Implementation of the JXTA TLS Transport");
protos.put(tlsProtoClassID, moduleAdv);
moduleAdv =
mkImplAdvBuiltin(refStartNetPeerGroupSpecID,
"net.jxta.impl.peergroup.StartNetPeerGroup",
"Reference Implementation of StartNetPeerGroup");
apps.put(applicationClassID, moduleAdv);
paramAdv.setServices(services);
paramAdv.setProtos(protos);
paramAdv.setApps(apps);
// Pour the paramAdv in the platformDef
platformDef.setParam
((StructuredDocument)
paramAdv.getDocument(new MimeMediaType("text", "xml")));
return platformDef;
}
static {
try {
PeerGroupFactory.setPlatformClass(
Class.forName("net.jxta.impl.peergroup.Platform"));
} catch(Exception e) {
e.printStackTrace();
}
}
private boolean initialized = false;
public void init(PeerGroup nullParent, ID nullID, Advertisement nullAdv)
throws PeerGroupException {
if (initialized == true) {
if (LOG.isEnabledFor(Priority.WARN)) LOG.warn("You cannot initialize a PeerGroup more"
+ " than once !");
return;
}
initialized = true;
if (nullAdv != null) {
if (LOG.isEnabledFor(Priority.WARN)) LOG.warn("Platform has full control over its adv.");
}
config = new Configurator();
// Set the peer configuration bewfore we start.
setConfigAdvertisement(config.get());
// We set reconf in advance, just in case something screws up, in
// which case we want the configurator to show-up by default.
config.setReconf();
ModuleImplAdvertisement platformDef;
try {
// Build the platform's impl adv.
platformDef = mkPlatformImplAdv();
} catch (Exception e) {
throw new PeerGroupException(e.getMessage());
}
// Initialize the group.
super.init(null, PeerGroupID.worldPeerGroupID, platformDef);
try {
// Publish our own adv.
publishGroup("jxta.peergroup.PlatformGroup",
"The Universal Platform PeerGroup");
} catch (IOException e) {
throw new PeerGroupException(e.getMessage());
}
// Clear the reconf flag since things seem to be working.
config.clearReconf();
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -