📄 peergroupfactory.java
字号:
File jxta_home = new File( jxta_path ); jxta_home.mkdirs(); URI defaultHome = jxta_home.toURI(); return defaultHome; } return storeHome; } /** * Set the location which will serve as the parent for all stored items used * by JXTA. * * @deprecated Consider converting to use {@link NetPeerGroupFactory} and/or {@link WorldPeerGroupFactory}. * * @param newHome The absolute URI location which will serve as the parent * for all stored items used by JXTA. Currently this must be a non-opaque URI. * May also be {@code null} to restore the default value. */ public static void setStoreHome(URI newHome) { if( null != newHome ) { // Fail if the URI is not absolute. if( !newHome.isAbsolute() ) { throw new IllegalArgumentException( "Only absolute URIs accepted for store home location." ); } // Fail if the URI is Opaque. if( newHome.isOpaque() ) { throw new IllegalArgumentException( "Only hierarchical URIs accepted for store home location." ); } // Add a trailing slash if necessary. if (!newHome.toString().endsWith("/")) { newHome = URI.create(newHome.toString() + "/"); } } storeHome = newHome; } /** * Static Method to create a new peer group instance. * * <p/>After being created the init() method needs to be called, and * the startApp() method may be called, at the invoker's discretion. * * @deprecated This method was previously unused and has been removed with no alternatives. (it wasn't useful) * * @return PeerGroup instance of a new PeerGroup **/ public static PeerGroup newPeerGroup() { throw new UnsupportedOperationException( "This feature has been removed. (sorry)" ); } /** * Instantiates the World (Platform) Peer Group and can also optionally * (re)configure the world peer group before instantiation using the * configurator specified via {@link #setConfiguratorClass(Class)}. * * <p/>Only one instance of the World Peer Group may be created within the * context of the {@code PeerGroupFactory}'s class loader. Invoking this * method amounts to creating an instance of JXTA. * * <p/>The {@link PeerGroup#init(PeerGroup,ID,Advertisement)} method is * called automatically. The {@link PeerGroup#startApp(String[])} method * is left for the invoker to call if appropriate. * * @deprecated Consider converting to use {@link WorldPeerGroupFactory#WorldPeerGroupFactory()}. * * @return PeerGroup The World Peer Group instance. * @throws JxtaError Thrown for all checked Exceptions which occur during * construction of the World Peer Group. **/ public static PeerGroup newPlatform() { Class c = PeerGroupFactory.getConfiguratorClass(); if( null == c ) { c = NULL_CONFIGURATOR; } Configurator configurator; try { Constructor config_constructor = c.getConstructor( URI.class ); configurator = (Configurator) config_constructor.newInstance( getStoreHome() ); } catch (InvocationTargetException ie) { LOG.error("Uninstantiatable configurator: " + c, ie ); throw new JxtaError("Uninstantiatable configurator: " + c, ie ); } catch (NoSuchMethodException ie) { LOG.error("Uninstantiatable configurator: " + c, ie ); throw new JxtaError("Uninstantiatable configurator: " + c, ie ); } catch (InstantiationException ie) { LOG.error("Uninstantiatable configurator: " + c, ie ); throw new JxtaError("Uninstantiatable configurator: " + c, ie ); } catch (IllegalAccessException iae) { LOG.error("can't instantiate configurator: " + c, iae ); throw new JxtaError("Can't instantiate configurator: " + c, iae ); } catch (ClassCastException cce ) { LOG.error("Not a Configurator :" + c, cce ); throw new JxtaError("Not a Configurator :" + c, cce ); } ConfigParams pc; try { pc = configurator.getConfigParams(); } catch (ConfiguratorException cce ) { LOG.error("Could not retrieve configuration", cce ); throw new JxtaError("Could not retrieve configuration", cce ); } try { WorldPeerGroupFactory wpgf; if( null == worldGroupClass ) { wpgf = new WorldPeerGroupFactory( pc, getStoreHome() ); } else { wpgf = new WorldPeerGroupFactory( worldGroupClass, pc, getStoreHome() ); } configurator.setConfigParams( pc ); configurator.save(); // Forget about the configurator configurator = null; return (PeerGroup) wpgf.getInterface(); } catch(RuntimeException e) { if (LOG.isEnabledFor(Level.FATAL)) { LOG.fatal("newPlatform failed", e); } // rethrow throw e; } catch(Exception e) { // should be all other checked exceptions if (LOG.isEnabledFor(Level.FATAL)) { LOG.fatal("newPlatform failed", e); } // Simplify exception scheme for caller: any sort of problem wrapped // in a PeerGroupException. throw new JxtaError("newPlatform failed", e); } catch(Error e) { if (LOG.isEnabledFor(Level.FATAL)) { LOG.fatal("newPlatform failed", e); } // rethrow throw e; } } /** * Instantiates the net peer group using the provided parent peer group. * * @deprecated Consider converting to use {@link NetPeerGroupFactory#NetPeerGroupFactory(PeerGroup,ID,String,XMLElement)}. * * @param ppg The parent group. * @return PeerGroup The default netPeerGroup * @throws PeerGroupException For failures in constructing the Net Peer Group. **/ public static PeerGroup newNetPeerGroup(PeerGroup ppg) throws PeerGroupException { try { NetPeerGroupFactory npgf; NetPeerGroupFactory.NetGroupTunables tunables; if( null == netPGID ) { // Determine net peer group configuration parameters if they // have not already been set. tunables = new NetPeerGroupFactory.NetGroupTunables( ResourceBundle.getBundle("net.jxta.impl.config"), new NetPeerGroupFactory.NetGroupTunables() ); // load overides from "${JXTA_HOME}config.properties". URI configPropertiesLocation = getStoreHome().resolve( "config.properties" ); try { URLConnection configProperties = configPropertiesLocation.toURL().openConnection(); ResourceBundle rsrcs = new PropertyResourceBundle(configProperties.getInputStream()); tunables = new NetPeerGroupFactory.NetGroupTunables( rsrcs, tunables ); if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug( "Loaded defaults from " + rsrcs); } } catch(MissingResourceException ignored) { ; } catch(IOException ignored ) { ; } catch(Exception ignored ) { ; } } else { tunables = new NetPeerGroupFactory.NetGroupTunables(netPGID, netPGName, (XMLDocument) StructuredDocumentFactory.newStructuredDocument( MimeMediaType.XMLUTF8, "desc", netPGDesc )); } npgf = new NetPeerGroupFactory(ppg, tunables.id, tunables.name, tunables.desc ); PeerGroup newPg = npgf.getInterface(); return newPg; } 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); } catch(Error e) { if (LOG.isEnabledFor(Level.FATAL)) { LOG.fatal("newNetPeerGroup failed", e); } // rethrow throw e; } } /** * Instantiates the World Peer Group and then instantiates the Net Peer * Group. This simplifies the method by which applications can start JXTA. * * @deprecated Consider converting to use {@link NetPeerGroupFactory#NetPeerGroupFactory()} * or preferably one of the other {@code NetPeerGroupFactory} constructors. * * @return The newly instantiated Net Peer Group. **/ public static PeerGroup newNetPeerGroup() throws PeerGroupException { // get/create the World Peer Group. PeerGroup wpg = getWorldPeerGroup(); try { PeerGroup npg = newNetPeerGroup(wpg); return npg; } finally { wpg.unref(); } } /** * Retrieves or constructs a new World Peer Group instance suitable for * use as the parent for Net Peer Group instances. This implementation * makes an important trade-off worth noting; it will use an existing * world peer group instance if available and ignore any changes which have * been made to the static configuration methods provided by this class. * * @return The World Peer Group. * @throws PeerGroupException For failures in recovering the World Peer Group. **/ private static PeerGroup getWorldPeerGroup() throws PeerGroupException { synchronized( PeerGroup.globalRegistry ) { PeerGroup result = PeerGroup.globalRegistry.lookupInstance( PeerGroupID.worldPeerGroupID ); if( null != result ) { return result; } return newPlatform(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -