netpeergroupfactory.java

来自「JXTA&#8482 is a set of open, generalize」· Java 代码 · 共 582 行 · 第 1/2 页

JAVA
582
字号
     * instance.     * @param desc      The description which will be used for the new Net Peer Group     * instance. You can construct an {@code XMLDocument} from a {@code String}     * via :     * <p/><pre>     *     XMLDocument asDoc = StructuredDocumentFactory.newStructuredDocument( MimeMediaType.XMLUTF8, "desc", asString );     * </pre>     * @throws PeerGroupException Thrown for problems constructing the Net Peer     * Group.     */    @Deprecated    public NetPeerGroupFactory(ConfigParams config, URI storeHome, ID id, String name, XMLElement desc) throws PeerGroupException {        WorldPeerGroupFactory world = new WorldPeerGroupFactory(config, storeHome);        PeerGroup worldGroup = world.getInterface();                try {            net = newNetPeerGroup(worldGroup, config, id, name, desc, null);        } finally {            worldGroup.unref();        }    }    /**     * Constructs a Net Peer Group instance using the specified parent peer     * group (normally the World Peer Group). This is the preferred constructor     * for constructing a private Net Peer Group.     *     * @deprecated With the addition of support for {@code PeerGroupConfigAdv}     * this constructor is being deprecated as the precedence of settings is     * ambiguous.     *     * @param parentGroup The Peer Group which will be the parent of the     * newly created net peer group. This should normally be the World Peer     * Group.     * @param id The PeerGroupID which will be used for the new Net Peer Group     * instance.     * @param name The name which will be used for the new Net Peer Group     * instance.     * @param desc The description which will be used for the new Net Peer Group     * instance. You can construct an {@code XMLDocument} from a {@code String}     * via :     * <p/><pre>     *     XMLDocument asDoc = StructuredDocumentFactory.newStructuredDocument( MimeMediaType.XMLUTF8, "desc", asString );     * </pre>     * @throws PeerGroupException Thrown for problems constructing the Net Peer     * Group.     */    @Deprecated    public NetPeerGroupFactory(PeerGroup parentGroup, ID id, String name, XMLElement desc) throws PeerGroupException {        net = newNetPeerGroup(parentGroup, null, id, name, desc, null);    }    /**     * Constructs a Net Peer Group instance using the specified parent peer     * group (normally the World Peer Group). This is the preferred constructor     * for constructing a private Net Peer Group with a specific implementation.     *     * @deprecated With the addition of support for {@code PeerGroupConfigAdv}     * this constructor is being deprecated as the precedence of settings is     * ambiguous.     *     * @param parentGroup The Peer Group which will be the parent of the newly     * created net peer group. This should normally be the World Peer     *                           * @param id The PeerGroupID which will be used for the new Net Peer Group     * instance.     * @param name The name which will be used for the new Net Peer Group     * instance.     * @param desc The description which will be used for the new Net Peer Group     * instance. You can construct an {@code XMLDocument} from a {@code String}     * via :     * <p/><pre>     *     XMLDocument asDoc = StructuredDocumentFactory.newStructuredDocument( MimeMediaType.XMLUTF8, "desc", asString );     * </pre>     * @param moduleImplAdv The Module Impl Advertisement for the new Net Peer     * Group instance.     * @throws PeerGroupException Thrown for problems constructing the Net Peer     * Group.     */    @Deprecated    public NetPeerGroupFactory(PeerGroup parentGroup, ID id, String name, XMLElement desc, ModuleImplAdvertisement moduleImplAdv) throws PeerGroupException {        net = newNetPeerGroup(parentGroup, null, id, name, desc, moduleImplAdv);    }    /**     * Constructs a Net Peer Group instance using the specified parent peer     * group (normally the World Peer Group). This is the preferred constructor     * for constructing a Net Peer Group with a specific implementation.     *     * @param parentGroup The Peer Group which will be the parent of the     * newly created net peer group. This should normally be the World Peer     * Group.     * @param config The configuration parameters for the newly created Net Peer     * Group instance.     * @param moduleImplAdv The Module Impl Advertisement for the new Net Peer     * Group instance.     * @throws PeerGroupException Thrown for problems constructing the Net Peer     * Group.     */    public NetPeerGroupFactory(PeerGroup parentGroup, ConfigParams config, ModuleImplAdvertisement moduleImplAdv) throws PeerGroupException {        PeerGroupConfigAdv netGroupConfig = (PeerGroupConfigAdv) config.getSvcConfigAdvertisement(PeerGroup.peerGroupClassID);        NetGroupTunables tunables;        if (null == netGroupConfig) {            tunables = new NetGroupTunables(ResourceBundle.getBundle("net.jxta.impl.config"), new NetGroupTunables());        } else {            tunables = new NetGroupTunables(netGroupConfig.getPeerGroupID(), netGroupConfig.getName(), netGroupConfig.getDesc());        }        net = newNetPeerGroup(parentGroup, config, tunables.id, tunables.name, tunables.desc, moduleImplAdv);    }        /**     * Returns a strong (reference counted) interface object for the Net Peer     * Group instance. This reference should be explicitly unreferenced when it     * is no longer needed.     *     * @return A strong (reference counted) interface object for the Net Peer Group.     * @see PeerGroup#unref()     */    public PeerGroup getInterface() {        return (PeerGroup) net.getInterface();    }    /**     * Returns a weak (non-reference counted) interface object for the Net Peer Group.     *     * @return A weak (non-reference counted) interface object for the Net Peer Group.     * @see PeerGroup#getWeakInterface()     */    public PeerGroup getWeakInterface() {        return net.getWeakInterface();    }    /**     * Construct the new Net Peer Group instance.     *     * @param parentGroup The parent group of the newly created net peer group.     * @param config Configuration parameters for the newly created net peer group.     * @param id The name to use for the newly created Net Peer Group.     * @param name The name to use for the newly created Net Peer Group.     * @param desc The description to use for the newly created Net Peer Group.     * @param implAdv The Module Impl Advertisement for the new Net Peer Group     * instance or {@code null} to use the advertisement returned by     * {@ link PeerGroup.getAllPurposePeerGroupImplAdvertisement()}.     * @return the PeerGroup     * @throws PeerGroupException Thrown for errors instantiating the new Net     * Peer Group instance.     */    private PeerGroup newNetPeerGroup(PeerGroup parentGroup, ConfigParams config, ID id, String name, XMLElement desc, ModuleImplAdvertisement implAdv) throws PeerGroupException {        synchronized (PeerGroup.globalRegistry) {            PeerGroup result = PeerGroup.globalRegistry.lookupInstance((PeerGroupID) id);            if (null != result) {                result.unref();                throw new PeerGroupException("Only a single instance of a Peer Group may be instantiated at a single time.");            }            if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                LOG.info( "Instantiating net peer group : " + id +                         "\n\tParent : " + parentGroup +                         "\n\tID : " + id +                         "\n\tName : " + name +                         "\n\timpl : " + implAdv);            }            try {                if (null == implAdv) {                    // Use the default Peer Group Impl Advertisement                    implAdv = parentGroup.getAllPurposePeerGroupImplAdvertisement();                }                // Build the group                GenericPeerGroup.setGroupConfigAdvertisement(id,config);                                result = (PeerGroup) parentGroup.loadModule(id, implAdv);                                // Set the name and description                // FIXME 20060217 bondolo How sad, we can't use our XML description.                if (null != desc) {                    result.publishGroup(name, desc.getTextValue());                } else {                    result.publishGroup(name, null);                }                return result;            } catch (PeerGroupException failed) {                if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) {                    LOG.log(Level.SEVERE, "newNetPeerGroup failed", failed);                }                // rethrow                throw failed;            } catch (RuntimeException e) {                if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) {                    LOG.log(Level.SEVERE, "newNetPeerGroup failed", e);                }                // rethrow                throw e;            } catch (Exception e) {                // should be all other checked exceptions                if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) {                    LOG.log(Level.SEVERE, "newNetPeerGroup failed", e);                }                // Simplify exception scheme for caller: every sort of problem                 // wrapped in a PeerGroupException.                throw new PeerGroupException("newNetPeerGroup failed", e);            }        }    }    /**     * Holds the construction tunables for the Net Peer Group. This consists of     * the peer group id, the peer group name and the peer group description.     */    static class NetGroupTunables {        final ID id;        final String name;        final XMLElement desc;        /**         * Constructor for loading the default Net Peer Group construction         * tunables.         */        NetGroupTunables() {            id = PeerGroupID.defaultNetPeerGroupID;            name = "NetPeerGroup";            desc = (XMLElement) StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, "desc", "default Net Peer Group");        }        /**         * Constructor for loading the default Net Peer Group construction         * tunables.         *         * @param pgid the PeerGroupID         * @param pgname the group name         * @param pgdesc the group description         */        NetGroupTunables(ID pgid, String pgname, XMLElement pgdesc) {            id = pgid;            name = pgname;            desc = pgdesc;        }        /**         * Constructor for loading the Net Peer Group construction         * tunables from the provided resource bundle.         *         * @param rsrcs The resource bundle from which resources will be loaded.         * @param defaults default values         */        NetGroupTunables(ResourceBundle rsrcs, NetGroupTunables defaults) {            ID idTmp;            String nameTmp;            XMLElement descTmp;            try {                String idTmpStr = rsrcs.getString("NetPeerGroupID").trim();                if (idTmpStr.startsWith(ID.URNNamespace + ":")) {                    idTmpStr = idTmpStr.substring(5);                }                idTmp = IDFactory.fromURI(new URI(ID.URIEncodingName + ":" + ID.URNNamespace + ":" + idTmpStr));                nameTmp = rsrcs.getString("NetPeerGroupName").trim();                descTmp = (XMLElement) StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, "desc",                        rsrcs.getString("NetPeerGroupDesc").trim());            } catch (Exception failed) {                if (null != defaults) {                    if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {                        LOG.log(Level.FINE, "NetPeerGroup tunables not defined or could not be loaded. Using defaults.", failed);                    }                    idTmp = defaults.id;                    nameTmp = defaults.name;                    descTmp = defaults.desc;                } else {                    if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) {                        LOG.log(Level.SEVERE, "NetPeerGroup tunables not defined or could not be loaded.", failed);                    }                    throw new IllegalStateException("NetPeerGroup tunables not defined or could not be loaded.");                }            }            id = idTmp;            name = nameTmp;            desc = descTmp;        }    }}

⌨️ 快捷键说明

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