📄 netpeergroupfactory.java
字号:
* @param storeHome The optional location that the World Peer Group, the * Net Peer Group and its' services should use for storing persistent and * transient information. May be {@code null} if the World Peer Group is * not provided a persistent store (though this not currently supported). * @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. **/ 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, 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. * * @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. **/ public NetPeerGroupFactory( PeerGroup parentGroup, ID id, String name, XMLElement desc ) throws PeerGroupException { net = newNetPeerGroup( parentGroup, 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. * * @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> * @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, ID id, String name, XMLElement desc, ModuleImplAdvertisement moduleImplAdv ) throws PeerGroupException { net = newNetPeerGroup( parentGroup, id, name, 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. * * @see PeerGroup#unref() * * @return A strong (reference counted) interface object for the Net Peer Group. **/ public PeerGroup getInterface() { return (PeerGroup) net.getInterface(); } /** * Returns a weak (non-reference counted) interface object for the Net Peer Group. * * @see PeerGroup#getWeakInterface() * * @return A weak (non-reference counted) interface object for the Net Peer Group. **/ 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 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()}. * @throws PeerGroupException Thrown for problems constructing the Net Peer * Group. **/ private PeerGroup newNetPeerGroup( PeerGroup parentGroup, ID id, String name, XMLElement desc, ModuleImplAdvertisement implAdv ) throws PeerGroupException { synchronized( PeerGroup.globalRegistry ) { PeerGroup result = PeerGroup.globalRegistry.lookupInstance( (PeerGroupID) id ); if( null != result ) { throw new PeerGroupException( "Only a single instance of the World Peer Group may be instantiated at a single time." ); } if (LOG.isEnabledFor(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 result = (PeerGroup) parentGroup.loadModule( id, implAdv ); // Set the name and description // FIXME 20060217 bondolo How sad, we can't use our XML description. result.publishGroup( name, desc.getTextValue() ); return result; } catch(PeerGroupException failed) { if (LOG.isEnabledFor(Level.FATAL)) { LOG.fatal("newNetPeerGroup failed", failed); } // rethrow throw failed; } catch(RuntimeException e) { if (LOG.isEnabledFor(Level.FATAL)) { LOG.fatal("newNetPeerGroup failed", e); } // rethrow throw e; } catch(Exception e) { // should be all other checked exceptions if (LOG.isEnabledFor(Level.FATAL)) { LOG.fatal("newNetPeerGroup failed", e); } // Simplify exception scheme for caller: any 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. **/ 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. **/ 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( LOG.isEnabledFor( Level.DEBUG ) ) { LOG.debug( "NetPeerGroup tunables not defined or could not be loaded. Using defaults.", failed ); } idTmp = defaults.id; nameTmp = defaults.name; descTmp = defaults.desc; } else { if( LOG.isEnabledFor( Level.ERROR ) ) { LOG.error( "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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -