📄 networkconfigurator.java
字号:
/** * Returns the highest port on which the TCP Transport will listen if * configured to do so. Valid values are <code>-1</code>, <code>0</code> and * <code>1-65535</code>. The <code>-1</code> value is used to signify that * the port range feature should be disabled. The <code>0</code> specifies * that the Socket API dynamic port allocation should be used. For values * <code>1-65535</code> the value must be equal to or greater than the value * used for start port. * * @param end the new TCP end port */ public void setTcpEndPort(int end) { tcpConfig.setEndPort(end); } /** * Toggles TCP transport server (incoming) mode (default is on) * * @param incoming the new TCP server mode */ public void setTcpIncoming(boolean incoming) { tcpConfig.setServerEnabled(incoming); } /** * Toggles TCP transport client (outgoing) mode (default is true) * * @param outgoing the new tcpOutgoing value */ public void setTcpOutgoing(boolean outgoing) { tcpConfig.setClientEnabled(outgoing); } /** * Sets the TCP transport interface address * <p/>e.g. "192.168.1.1" * * @param address the TCP transport interface address */ public void setTcpInterfaceAddress(String address) { tcpConfig.setInterfaceAddress(address); } /** * Sets the node public address * <p/>e.g. "192.168.1.1:9701" * <p/>This address is the physical address defined in a node's * AccessPointAdvertisement. This often required for NAT'd/FW nodes * * @param address the TCP transport public address * @param exclusive public address advertised exclusively */ public void setTcpPublicAddress(String address, boolean exclusive) { tcpConfig.setServer(address); tcpConfig.setPublicAddressOnly(exclusive); } /** * Toggles whether to use IP group multicast (default is true) * * @param multicastOn the new useMulticast value */ public void setUseMulticast(boolean multicastOn) { tcpConfig.setMulticastState(multicastOn); } /** * Determines whether to restrict RelayService leases to those defined in * the seed list * * @param useOnlyRelaySeeds restrict RelayService lease to seed list */ public void setUseOnlyRelaySeeds(boolean useOnlyRelaySeeds) { relayConfig.setUseOnlySeeds(useOnlyRelaySeeds); } /** * Determines whether to restrict RendezvousService leases to those defined in * the seed list * * @param useOnlyRendezvouSeeds restrict RendezvousService lease to seed list */ public void setUseOnlyRendezvousSeeds(boolean useOnlyRendezvouSeeds) { rdvConfig.setUseOnlySeeds(useOnlyRendezvouSeeds); } /** * Adds RelayService peer seed address * <p/>A RelayService seed is defined as a physical endpoint address * <p/>e.g. http://192.168.1.1:9700, or tcp://192.168.1.1:9701 * * @param seedURI the relay seed URI */ public void addSeedRelay(URI seedURI) { relayConfig.addSeedRelay(seedURI.toString()); } /** * Adds Rendezvous peer seed, physical endpoint address * <p/>A RendezVousService seed is defined as a physical endpoint address * <p/>e.g. http://192.168.1.1:9700, or tcp://192.168.1.1:9701 * * @param seedURI the rendezvous seed URI */ public void addSeedRendezvous(URI seedURI) { rdvConfig.addSeedRendezvous(seedURI); } /** * Returns true if a PlatformConfig file exist under store home * * @return true if a PlatformConfig file exist under store home */ public boolean exists() { URI platformConfig = storeHome.resolve("PlatformConfig"); try { return null != read(platformConfig); } catch( IOException failed ) { return false; } } /** * Sets the PeerID for this Configuration * * @param peerIdStr the new PeerID as a string */ public void setPeerId(String peerIdStr) { this.peerid = (PeerID) ID.create(URI.create(peerIdStr)); } /** * Sets the new RendezvousService seeding URI as a string. * <p/>A seeding URI (when read) is expected to provide a list of * physical endpoint address to rendezvous peers * * @param seedURIStr the new rendezvous seed URI as a string */ public void addRdvSeedingURI(String seedURIStr) { rdvConfig.addSeedingURI(URI.create(seedURIStr)); } /** * Sets the new RelayService seeding URI as a string. * <p/>A seeding URI (when read) is expected to provide a list of * physical endpoint address to relay peers * * @param seedURIStr the new RelayService seed URI as a string */ public void addRelaySeedingURI(String seedURIStr) { relayConfig.addSeedingURI(URI.create(seedURIStr)); } /** * Sets the List relaySeeds represented as Strings * <p/>A RelayService seed is defined as a physical endpoint address * <p/>e.g. http://192.168.1.1:9700, or tcp://192.168.1.1:9701 * * @param seeds the Set RelayService seed URIs as a string */ public void setRelaySeedURIs(List<String> seeds) { relayConfig.clearSeedRelays(); for (String seedStr : seeds) { relayConfig.addSeedRelay(new EndpointAddress(seedStr)); } } /** * Sets the relaySeeds represented as Strings * <p/>A seeding URI (when read) is expected to provide a list of * physical endpoint address to relay peers * * @param seedURIs the List relaySeeds represented as Strings */ public void setRelaySeedingURIs(Set<String> seedURIs) { relayConfig.clearSeedingURIs(); for (String seedStr : seedURIs) { relayConfig.addSeedingURI(URI.create(seedStr)); } } /** * Clears the List of RelayService seeds */ public void clearRelaySeeds() { relayConfig.clearSeedRelays(); } /** * Clears the List of RelayService seeding URIs */ public void clearRelaySeedingURIs() { relayConfig.clearSeedingURIs(); } /** * Sets the List of RendezVousService seeds represented as Strings * <p/>A RendezvousService seed is defined as a physical endpoint address * <p/>e.g. http://192.168.1.1:9700, or tcp://192.168.1.1:9701 * * @param seeds the Set of rendezvousSeeds represented as Strings */ public void setRendezvousSeeds(Set<String> seeds) { rdvConfig.clearSeedRendezvous(); for (String seedStr : seeds) { rdvConfig.addSeedRendezvous(URI.create(seedStr)); } } /** * Sets the List of RendezVousService seeding URIs represented as Strings. * A seeding URI (when read) is expected to provide a list of * physical endpoint address to rendezvous peers. * * @deprecated The name of this method is inconsistent with it's function! * It sets the <strong>seeding</strong> URIs and not the seed URIs. Use * {@link #setRendezvousSeedingURIs()} instead. * * @param seedURIs the List rendezvousSeeds represented as Strings */ @Deprecated public void setRendezvousSeedURIs(List<String> seedingURIs) { setRendezvousSeedingURIs(seedingURIs); } /** * Sets the List of RendezVousService seeding URIs represented as Strings. * A seeding URI (when read) is expected to provide a list of * physical endpoint address to rendezvous peers. * * @param seedURIs the List rendezvousSeeds represented as Strings. */ public void setRendezvousSeedingURIs(List<String> seedingURIs) { rdvConfig.clearSeedingURIs(); for (String seedStr : seedingURIs) { rdvConfig.addSeedingURI(URI.create(seedStr)); } } /** * Clears the list of RendezVousService seeds */ public void clearRendezvousSeeds() { rdvConfig.clearSeedRendezvous(); } /** * Clears the list of RendezVousService seeding URIs * * @deprecated The name of this method is inconsistent with it's function! * It clears the <strong>seeding</strong> URIs and not the seed URIs. Use * {@link #clearRendezvousSeedingURIs()} instead. * */ @Deprecated public void clearRendezvousSeedURIs() { rdvConfig.clearSeedingURIs(); } /** * Clears the list of RendezVousService seeding URIs */ public void clearRendezvousSeedingURIs() { rdvConfig.clearSeedingURIs(); } /** * Load a configuration from the specified store home uri * <p/> * e.g. file:/export/dist/EdgeConfig.xml, e.g. http://configserver.net/configservice?Edge * * @return The loaded configuration. * @throws IOException if an i/o error occurs * @throws CertificateException if the MembershipService is invalid */ public ConfigParams load() throws IOException, CertificateException { return load(storeHome.resolve("PlatformConfig")); } /** * Loads a configuration from a specified uri * <p/> * e.g. file:/export/dist/EdgeConfig.xml, e.g. http://configserver.net/configservice?Edge * * @param uri the URI to PlatformConfig * @return The loaded configuration. * @throws IOException if an i/o error occurs * @throws CertificateException if the MemebershipService is invalid */ public ConfigParams load(URI uri) throws IOException, CertificateException { if (uri == null) { throw new IllegalArgumentException("URI can not be null"); } if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Loading configuration : " + uri); } PlatformConfig platformConfig = read(uri); name = platformConfig.getName(); peerid = platformConfig.getPeerID(); description = platformConfig.getDescription(); // TCP XMLElement param = (XMLElement) platformConfig.getServiceParam(PeerGroup.tcpProtoClassID); tcpEnabled = platformConfig.isSvcEnabled(PeerGroup.tcpProtoClassID); Enumeration tcpChilds = param.getChildren(TransportAdvertisement.getAdvertisementType()); // get the TransportAdv from either TransportAdv or tcpConfig if (tcpChilds.hasMoreElements()) { param = (XMLElement) tcpChilds.nextElement(); } else { throw new IllegalStateException("Missing TCP Advertisment"); } tcpConfig = (TCPAdv) AdvertisementFactory.newAdvertisement(param); // HTTP try { param = (XMLElement) platformConfig.getServiceParam(PeerGroup.httpProtoClassID); httpEnabled = platformConfig.isSvcEnabled(PeerGroup.httpProtoClassID); Enumeration httpChilds = param.getChildren(TransportAdvertisement.getAdvertisementType()); // get the TransportAdv from either TransportAdv if (httpChilds.hasMoreElements()) { param = (XMLElement) httpChilds.nextElement(); } else { throw new IllegalStateException("Missing HTTP Advertisment"); } // Read-in the adv as it is now. httpConfig = (HTTPAdv) AdvertisementFactory.newAdvertisement(param); } catch (Exception failure) { IOException ioe = new IOException("error processing the HTTP config advertisement"); ioe.initCause(failure); throw ioe; } // ProxyService try { param = (XMLElement) platformConfig.getServiceParam(PeerGroup.proxyClassID); if (param != null && !platformConfig.isSvcEnabled(PeerGroup.proxyClassID)) { mode = mode | PROXY_SERVER; } } catch (Exception failure) { IOException ioe = new IOException("error processing the pse config advertisement"); ioe.initCause(failure); throw ioe; } // Rendezvous try { param = (XMLElement) platformConfig.getServiceParam(PeerGroup.rendezvousClassID); // backwards compatibility param.addAttribute("type", RdvConfigAdv.getAdvertisementType()); rdvConfig = (RdvConfigAdv) AdvertisementFactory.newAdvertisement(param); if (rdvConfig.getConfiguration() == RendezVousConfiguration.AD_HOC) { mode = mode | RDV_AD_HOC; } else if (rdvConfig.getConfiguration() == RendezVousConfiguration.EDGE) { mode = mode | RDV_CLIENT; } else if (rdvConfig.getConfiguration() == RendezVousConfiguration.RENDEZVOUS) { mode = mode | RDV_SERVER; } } catch (Exception failure) { IOException ioe = new IOException("error processing the rendezvous config advertisement"); ioe.initCause(failure); throw ioe; } // Relay try { param = (XMLElement) platformConfig.getServiceParam(PeerGroup.relayProtoClassID); if (param != null && !platformConfig.isSvcEnabled(PeerGroup.relayProtoClassID)) { mode = mode | RELAY_OFF;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -