⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 platform.java

📁 jxta_src_2.41b jxta 2.41b 最新版源码 from www.jxta.org
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2001-2003 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.108 2006/06/14 16:02:27 bondolo Exp $ */package net.jxta.impl.peergroup;import java.io.File;import java.net.URI;import java.net.URL;import java.util.Hashtable;import java.io.IOException;import java.net.MalformedURLException;import org.apache.log4j.Level;import org.apache.log4j.Logger;import net.jxta.document.Advertisement;import net.jxta.document.AdvertisementFactory;import net.jxta.document.MimeMediaType;import net.jxta.document.XMLDocument;import net.jxta.document.XMLElement;import net.jxta.id.ID;import net.jxta.peergroup.PeerGroup;import net.jxta.peergroup.PeerGroupFactory;import net.jxta.peergroup.PeerGroupID;import net.jxta.platform.ModuleSpecID;import net.jxta.protocol.ConfigParams;import net.jxta.protocol.ModuleImplAdvertisement;import net.jxta.exception.ConfiguratorException;import net.jxta.exception.JxtaError;import net.jxta.exception.PeerGroupException;import net.jxta.impl.endpoint.cbjx.CbJxDefs;import net.jxta.impl.membership.PasswdMembershipService;import net.jxta.impl.membership.pse.PSEMembershipService;import net.jxta.impl.peergroup.PlatformConfigurator;import net.jxta.impl.protocol.PlatformConfig;/** * Provides the implementation for the World Peer Group. * * <p/>Key differences from regular groups are: * * <ul> * <li>Provides a mechanism for peer group configuration parameter and for * reconfiguration via a plugin configurator.</li> * <li>Ensures that only a single instance of the World Peer Group exists * within the context of the current classloader.</li> * </ul> **/public class Platform extends StdPeerGroup {        /**     *  Log4J Logger     **/    private final static transient  Logger LOG = Logger.getLogger(Platform.class.getName());        /**     *  If <code>true</code> then initialization has been completed. Declared     *  <code>static</code> to ensure that only one instance exists.     **/    private static boolean initialized = false;        /**     *  The Module Impl Advertisement we will return in response to     *  {@link #getAllPurposePeerGroupImplAdvertisement()} requests.     **/    private ModuleImplAdvertisement allPurposeImplAdv = null;        /**     *  Default constructor     **/    public Platform() throws PeerGroupException {        throw new JxtaError( "Zero params constructor is no longer supported for Platform class." );    }        public Platform( ConfigParams config, URI storeHome ) {        // initialize the store location.        jxtaHome = storeHome;                // initialize the configuration advertisement.        setConfigAdvertisement( config );    }        /**     *  {@inheritDoc}     **/    protected synchronized void initFirst( PeerGroup nullParent, ID assignedID, Advertisement impl)    throws PeerGroupException {                if ( initialized ) {            LOG.fatal("You cannot initialize more than one World PeerGroup!");            throw new PeerGroupException("You cannot initialize more than one World PeerGroup!");        }                ModuleImplAdvertisement implAdv = (ModuleImplAdvertisement) impl;                if (nullParent != null) {            LOG.fatal("World PeerGroup cannot be instantiated with a parent group!");            throw new PeerGroupException( "World PeerGroup cannot be instantiated with a parent group!" );        }                // if we weren't given a module impl adv then make one from scratch.        if( null == implAdv ) {            try {                // Build the platform's impl adv.                implAdv = mkPlatformImplAdv();            } catch (Throwable e) {                if (LOG.isEnabledFor(Level.FATAL))                    LOG.fatal( "Fatal Error making Platform Impl Adv", e);                throw new PeerGroupException(  "Fatal Error making Platform Impl Adv", e );            }        }                                if( null != jxtaHome ) {            try {                URL downloadablesURL = jxtaHome.resolve( "Downloaded/" ).toURL();                getJxtaLoader().addURL( downloadablesURL );            } catch( MalformedURLException badPath ) {                if (LOG.isEnabledFor(Level.WARN)) {                    LOG.warn( "Could not install path for downloadables into JXTA Class Loader.");                }            }        }                // Initialize the group.        super.initFirst( null, PeerGroupID.worldPeerGroupID, implAdv );                }        /**     * {@inheritDoc}     **/    protected synchronized void initLast() throws PeerGroupException {        // Nothing special for now, but we might want to move some steps        // from initFirst, in the future.        super.initLast();                initialized = true;                // XXX bondolo 20040415 Hack to initialize class loader with specID for password membership        // This is to provide compatibility with apps which imported passwd membership directly.        ModuleSpecID id = PasswdMembershipService.passwordMembershipSpecID;                // Publish our own adv.        try {            publishGroup("World PeerGroup", "Standard World PeerGroup Reference Implementation");        } catch (IOException e) {            throw new PeerGroupException( "Failed to publish World Peer Group Advertisement", e );        }    }        protected static ModuleImplAdvertisement mkPlatformImplAdv() throws Exception {                // Start building the implAdv for the platform intself.        ModuleImplAdvertisement platformDef = mkImplAdvBuiltin(PeerGroup.refPlatformSpecID,                "World PeerGroup",                "Standard World PeerGroup 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;                // Do the Services                // "Core" Services        moduleAdv = mkImplAdvBuiltin(PeerGroup.refEndpointSpecID,                "net.jxta.impl.endpoint.EndpointServiceImpl",                "Reference Implementation of the Endpoint service");        services.put(PeerGroup.endpointClassID, moduleAdv);                moduleAdv = mkImplAdvBuiltin(PeerGroup.refResolverSpecID,                "net.jxta.impl.resolver.ResolverServiceImpl",                "Reference Implementation of the Resolver service");        services.put(PeerGroup.resolverClassID, moduleAdv);                moduleAdv = mkImplAdvBuiltin( PeerGroup.refMembershipSpecID,                "net.jxta.impl.membership.none.NoneMembershipService",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -