📄 configurator.java
字号:
this.rdvConfig.getSeedingURIs() : new URI[0]; return (u.length > 0 ? u[0] : null); } /** * Specify a RendezVous Bootstrap address. * * @param rendezVousBootstrapAddress the RendezVous bootstrap address * @throws ConfiguratorException {@link java.net.exception.ConfiguratorException} * chained list of configuration errors */ public void setRendezVousBootstrapAddress(URI rendezVousBootstrapAddress) throws ConfiguratorException { if (rendezVousBootstrapAddress != null && Util.validateAddress(rendezVousBootstrapAddress, -1).trim().length() > 0) { throw new ConfiguratorException("invalid address: " + rendezVousBootstrapAddress); } this.rdvConfig.clearSeedingURIs(); if (rendezVousBootstrapAddress != null) { this.rdvConfig.addSeedingURI(rendezVousBootstrapAddress); } } /** * Accessor to the RendezVous discovery attribute. * * <p>The RendezVous discovery allows the instance to discover and utilize * happended upon {@link net.jxta.rendezvous.RendezVousSerivce} if true, * and not utilize discovered {@link net.jxta.rendezvous.RendezVousService} * if false. * * @return the RendezVous discovery attribute. */ public boolean isRendezVousDiscovery() { return ! rdvConfig.getUseOnlySeeds(); } /** * Specify the {@code RendezVous} serivce discovery attribute. * * @param discover {@code RendezVous} discovery attribute */ public void setRendezVousDiscovery(boolean discover) { rdvConfig.setUseOnlySeeds(! discover); } /** * Accessor to the Relays Bootstrap address. * * <p>A Relays Bootstrap address is used to establish initial, aka * "seeding," Relays addresses, in the form of {@link java.net.URI}. * * @return the Relay Bootstrap address in the form of a * {@link java.net.URI} */ public URI getRelaysBootstrapAddress() { URI[] u = this.relayConfig != null ? this.relayConfig.getSeedingURIs() : new URI[0]; return (u.length > 0 ? u[0] : null); } /** * Specify a Relays Bootstrap address. * * @param relaysBootstrapAddress the Relay Bootstrap address * @throws ConfiguratorException {@link net.jxta.exception.ConfiguratorException} * chained list of configuration errors */ public void setRelaysBootstrapAddress(URI relaysBootstrapAddress) throws ConfiguratorException { if (relaysBootstrapAddress != null && Util.validateAddress(relaysBootstrapAddress, -1).trim().length() > 0) { throw new ConfiguratorException("invalid address: " + relaysBootstrapAddress); } this.relayConfig.clearSeedingURIs(); if (relaysBootstrapAddress != null) { this.relayConfig.addSeedingURI(relaysBootstrapAddress); } } /** * The Relay discovery allows the instance to discover and utilize * happended upon if true, and not utilize discovered Relay Service if false. * * @return the Relay discovery attribute. */ public boolean isRelaysDiscovery() { return this.isRelaysDiscovery; } /** * Specify the {@code Relay} serivce discovery attribute. * * @param isEnabled {@code Relay} discovery attribute */ public void setRelaysDiscovery(boolean isEnabled) { this.isRelaysDiscovery = isEnabled; } /** * Creates a {@link net.jxta.impl.protocol.PlatformConfig} instance that is * representative of the current Configurator state. * * <p>Prior to {@link net.jxta.impl.protocol.PlatformConfig} generation the * current Configurator state is normalized, optimized and validated. The * normalization process simply adds missing data per backing defaults. The * optimization process proceeds to excercise the normalized configuration * state against the series of registered {@code Optimizers} thereby providing * applications the opportunity to specialize the configuration process. * Lastly, the configuration state is validated against a set of rules which * ensure {@link net.jxta.impl.protocol.PlatformConfig} integrity. * * <p>In the event the configuration information as specified is invalid or * the representative {@link net.jxta.impl.protocol.PlatformConfig} can't be * generated, a {@link net.jxta.exception.ConfiguratorException} is thrown * which, in turn, includes a chained exception list from which one can * interogate to work towards configuration resolution. * * @return generated {@link net.jxta.impl.protocol.PlatformConfig} * @throws ConfiguratorException {@link net.jxta.exception.ConfiguratorException} * chained list of configuration errors */ public PlatformConfig getPlatformConfig() throws ConfiguratorException { normalize(); optimize(); validate(); return (this.platformConfig = constructPlatformConfig()); } /** * Accessor for {@link net.jxta.protocol.ConfigParams}. * * @return the corresponding {@link net.jxta.protocol.ConfigParams} */ public ConfigParams getConfigParams() throws ConfiguratorException { return getPlatformConfig(); } /** * Specify the configuration state per the provided {@link net.jxta.impl.protocol.PlatformConfig}. * * @param pc the provided {@link net.jxta.impl.protocol.PlatformConfig} */ public void setPlatformConfig(PlatformConfig pc) { try { process(pc); } catch( ConfiguratorException badConfig ) { throw new UndeclaredThrowableException( badConfig, "Configuration Failure" ); } } /** * Specify the configuration state per the provided {@link net.jxta.protocol.ConfigParams}. * * @param pc the provided {@link net.jxta.protocol.ConfigParams} */ public void setConfigParams(ConfigParams pc) { setPlatformConfig( (PlatformConfig) pc); } /** * Accessor to the {@link net.jxta.ext.config.Optimizer}. * * @return (@link net.jxta.ext.config.Optimizer} as a {@link java.util.List} */ public Iterator getOptimizers() { return this.optimizers != null ? this.optimizers.iterator() : Collections.EMPTY_LIST.iterator(); } /** * Adds an {@link net.jxta.ext.config.Optimizer}. * * @param optimizer {@link net.jxta.ext.config.Optimizer} */ public void addOptimizer(Optimizer optimizer) { if (optimizer != null) { if (this.optimizers == null) { this.optimizers = new ArrayList(); } this.optimizers.add(optimizer); } } /** * Adds a {@link java.util.List} of {@link net.jxta.ext.config.Optimizer}. * * @param optimizers {@link net.jxta.ext.config.Optimizer} */ public void addOptimizers(List optimizers) { for (Iterator o = optimizers != null ? optimizers.iterator() : Collections.EMPTY_LIST.iterator(); o.hasNext(); ) { addOptimizer((Optimizer)o.next()); } } /** * Remove an {@code Optimizer}. * * @param optimizer {@code Optimizer} to be removed * @return removed {@code Optimizer} */ public Optimizer removeOptimizer(Optimizer optimizer) { Optimizer o = null; if (this.optimizers != null) { int i = this.optimizers.indexOf(optimizer); if (i > -1) { o = (Optimizer)this.optimizers.remove(i); } } return o; } /** * Remove all {@link net.jxta.ext.config.Optimizer}. */ public void clearOptimizers() { if (this.optimizers != null) { this.optimizers.clear(); } } /** * Accessor to the {@link net.jxta.ext.config.Validator}. * * @return (@link net.jxta.ext.config.Validator} as a {@link java.util.List} */ public Iterator getValidators() { return this.validators != null ? this.validators.iterator() : Collections.EMPTY_LIST.iterator(); } /** * Adds an {@link net.jxta.ext.config.Validator}. * * @param validator {@link net.jxta.ext.config.Validator} */ public void addValidator(Validator validator) { if (validator != null) { if (this.validators == null) { this.validators = new ArrayList(); } this.validators.add(validator); } } /** * Adds a {@link java.util.List} of {@link net.jxta.ext.config.Validator}. * * @param validators {@link net.jxta.ext.config.Validator} */ public void addValidator(List validators) { for (Iterator o = validators != null ? validators.iterator() : Collections.EMPTY_LIST.iterator(); o.hasNext(); ) { addValidator((Validator)o.next()); } } /** * Remove an {@code Validator}. * * @param validator {@code Validator} to be removed * @return removed {@code Validatorr} */ public Validator removeValidator(Validator validator) { Validator o = null; if (this.validators != null) { int i = this.validators.indexOf(validator); if (i > -1) { o = (Validator)this.validators.remove(i); } } return o; } /** * Remove all {@link net.jxta.ext.config.Validator}. */ public void clearValidators() { if (this.validators != null) { this.validators.clear(); } } /** * Accessor to the reconfiguration attribute. * * Provides a mechanism to trigger reconfiguration processes. * * @return the reconfiguration state */ public boolean isReconfigure() { File f = new File(toFile(getJxtaHome()), Env.RECONFIGURE); return f.exists(); } /** * Specify the reconfiguration attribute. * * @param reconfigure the reconfiguration value. */ public void setReconfigure(boolean reconfigure) { File f = new File(toFile(getJxtaHome()), Env.RECONFIGURE); try { if (reconfigure) { new FileOutputStream(f).close(); } else { f.delete(); } } catch (FileNotFoundException fnfe) { LOG.warn("can't access reconfigure file: " + f); } catch (IOException ioe) { LOG.warn("can't access reconfigure file: " + f); } } /** * Persist the representative {@link net.jxta.impl.protocol.PlatformConfig} * to the configured JXTA persistence directory. * * A {@link net.jxta.exception.ConfiguratorException} will be thrown in the * event the {@link net.jxta.impl.protocol.PlatformConfig} can't be generated * or it is not possible to write to the specified {@link java.io.File}. * * @return success indicator * @throws ConfiguratorException {@link net.jxta.exception.ConfigurationException} * chained list of configuration errors */ public boolean save() throws ConfiguratorException { File f = null; URI u = getJxtaHome(); try { f = new File(Conversion.toFile(u), Env.PLATFORM_CONFIG); } catch (ConversionException ce) { if (LOG.isEnabledFor(Level.ERROR)) { LOG.error("can't convert uri to file: " + u, ce); } } return save(f); } /** * Persist the representative {@link net.jxta.impl.protocol.PlatformConfig} * to the provided {@link java.io.File}. * * If the provided {@link java.io.File} is a directory then the serialized * {@link net.jxta.impl.protocol.PlatformConfig} will reside in a file named * "PlatformConfig" within the specified JXTA persistence directory. If, on * the other hand, the {@link java.io.File} is a file, the serialzed * {@link net.jxta.impl.protocol.PlatformConfig} will reside in the named * {@link java.io.File}. * * A {@link net.jxta.exception.ConfiguratorException} will be thrown in the * event the {@link net.jxta.impl.protocol.PlatformConfig} can't be generated * or it is not possible to write to the s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -