⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 networkconfigurator.java

📁 jxta_src_2.41b jxta 2.41b 最新版源码 from www.jxta.org
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    /**     *  Creates NetworkConfigurator instance with default Proxy configuration     *     * @param  storeHome the URI to persistent store     * @return            NetworkConfigurator instance with defaultProxy configuration     */    public static NetworkConfigurator newProxyConfiguration(URI storeHome) {        return new NetworkConfigurator(PROXY_NODE, storeHome);    }    /**     *  Creates NetworkConfigurator instance with default Rendezvous, Relay, Proxy configuration     *     * @param  storeHome the URI to persistent store     * @return            NetworkConfigurator instance with default Rendezvous, Relay, Proxy configuration     */    public static NetworkConfigurator newRdvRelayProxyConfiguration(URI storeHome) {        return new NetworkConfigurator(RDV_RELAY_PROXY_NODE, storeHome);    }    /**     *  Creates a NetworkConfigurator object with a default configuration mode of EDGE_NODE     */    public NetworkConfigurator() {        this(EDGE_NODE, null);    }    /**     *  Creates a NetworkConfigurator with the default configuration of the     *  specified mode. <p/>Valid modes include ADHOC_NODE, EDGE_NODE, RDV_NODE     *  PROXY_NODE, RELAY_NODE, RDV_RELAY_PROXY_NODE, or any combination of     * specific configuration.<p/> e.g. RDV_NODE | HTTP_CLIENT      * @see #setMode     * @param  mode the new configuration mode     * @param  storeHome the URI to persistent store     */    public NetworkConfigurator(int mode, URI storeHome) {        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("Creating a default configuration");        }        if (storeHome == null) {            String jxta_home = System.getProperty("JXTA_HOME", ".jxta/");            if (!jxta_home.endsWith(File.separator)) {                jxta_home += File.separator;            }            storeHome = new File(jxta_home).toURI();        }        // Fail if the URI is not absolute.        if (!storeHome.isAbsolute()) {            throw new IllegalArgumentException("Only absolute URIs accepted for store home location.");        }        // Fail if the URI is Opaque.        if (storeHome.isOpaque()) {            throw new IllegalArgumentException("Only hierarchical URIs accepted for store home location.");        }        //FIXME this should be removed when 1488 is committed        if (!"file".equalsIgnoreCase(storeHome.getScheme())) {            throw new IllegalArgumentException("Only file based URI currently supported");        }        //Adds a terminating /        if (!storeHome.toString().endsWith("/")) {            storeHome = URI.create(storeHome.toString()+"/");        }        this.storeHome = storeHome;        this.home = new File(storeHome);        System.setProperty("JXTA_HOME", home.getAbsolutePath());        this.configFile = new File(home, "PlatformConfig");        httpConfig = createHttpAdv();        rdvConfig = createRdvConfigAdv();        relayConfig = createRelayConfigAdv();        proxyConfig = createProxyAdv();        tcpConfig = createTcpAdv();        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("Setting default configurator class to :" + net.jxta.impl.peergroup.NullConfigurator.class.getName());        }        setMode(mode);    }    /**     *  Sets PlaformConfig Peer Description element     *     * @param  description  the peer description     */    public void setDescription(String description) {        this.description = description;    }    /**     *  Set the current directory for configuration and cache persistent store     *  <p/>(default is $CWD/.jxta)     *     * <dt>Simple example :</dt>     * <pre>     *  <code>     *   //Create an application home     *   File appHome = new File(System.getProperty("JXTA_HOME", ".cache"));     *   //Create an instance home under the application home     *   File instanceHome = new File(appHome, instanceName);     *   jxtaConfig.setHome(instanceHome);     *   </code>     * </pre>     * @see #getHome     * @param  home  the new home value     */    public void setHome(File home) {        this.home = home;        this.storeHome = home.toURI();        System.setProperty("JXTA_HOME", home.getAbsolutePath());        this.configFile = new File(home, "PlatformConfig");    }    /**     *  Returns the current directory for configuration and cache persistent store     * @see #setHome     @return Returns the current home directory     */     public File getHome() {        return home;    }    /**     * Returns the location which will serve as the parent for all stored items     * used by JXTA. This method is intended for use by PeerGroup implementations     * and is not intended for use by applications. Applications and services     * should use the PeerGroup method with the same name.     *     * @see net.jxta.peergroup.PeerGroup#getStoreHome()     *     * @return The location which will serve as the parent for all stored     * items used by JXTA.     */    public static URI getStoreHome() {        return storeHome;    }        /**     *  Toggles HTTP transport state     *     * @param  enabled if true, enables HTTP transport     */    public void setHttpEnabled(boolean enabled) {        this.httpEnabled = enabled;    }    /**     *  Toggles the HTTP transport server (incoming) mode     *     * @param  incoming toggles HTTP transport server mode     */    public void setHttpIncoming(boolean incoming) {        httpConfig.setServerEnabled(incoming);    }    /**     *  Toggles the HTTP transport client (outgoing) mode     *     * @param  outgoing toggles HTTP transport client mode     */    public void setHttpOutgoing(boolean outgoing) {        httpConfig.setClientEnabled(outgoing);    }    /**     *  Sets the HTTP listening port (default 9901)     *     * @param  port the new HTTP port value     */    public void setHttpPort(int port) {        httpConfig.setPort(port);    }    /**     *  Sets the HTTP interface Address to bind the HTTP transport to     *  <p/>e.g. "192.168.1.1"     *     * @param  address  the new address value     */    public void setHttpInterfaceAddress(String address) {        httpConfig.setInterfaceAddress(address);    }    /**     *  Sets the HTTP JXTA Public Address     *  e.g. "192.168.1.1:9700"     *     * @param  address    the HTTP transport public address     * @param  exclusive  determines whether an address is advertised exclusively     */    public void setHttpPublicAddress(String address, boolean exclusive) {        httpConfig.setServer(address);        httpConfig.setPublicAddressOnly(exclusive);    }    /**     *  Sets the ID which will be used for new net peer group instances.     *     *  <p/>By Setting an alternate infrastructure PeerGroup ID (aka NetPeerGroup),     *  it prevents heterogeneous infrstructure PeerGroups from intersecting.     *  <p/>This is highly recommended practice foapplicaiton deployment     * @see net.jxta.peergroup.PeerGroupFactory#setNetPGID     * @param  id the new infrastructure PeerGroupID as a string     */    public void setInfrastructureID(ID id) {        if (id == null || id.equals(ID.nullID)) {            throw new IllegalArgumentException("PeerGroupID can not be null");        }        setInfrastructureID(id.toString());    }    /**     *  Sets the ID which will be used for new net peer group instances.     *     *  <p/>By Setting an alternate infrastructure PeerGroup ID (aka NetPeerGroup),     *  it prevents heterogeneous infrstructure PeerGroups from intersecting.     *  <p/>This is highly recommended practice foapplicaiton deployment     * @see net.jxta.peergroup.PeerGroupFactory#setNetPGID     * @param  idStr the new infrastructure PeerGroupID as a string     */    public void setInfrastructureID(String idStr) {        if (idStr == null || idStr.length() == 0) {            throw new IllegalArgumentException("PeerGroupID string can not be empty or null");        }        PeerGroupID pgid = (PeerGroupID) ID.create(URI.create(idStr));        PeerGroupFactory.setNetPGID(pgid);        configProps = new Properties();        configProps.setProperty("NetPeerGroupID", pgid.getUniqueValue().toString());    }    /**     *  Sets the infrastructure PeerGroup name meta-data     * @see net.jxta.peergroup.PeerGroupFactory#setNetPGName     * @param  name the Infrastructure PeerGroup name     */    public void setInfrastructureName(String name) {        PeerGroupFactory.setNetPGName(name);        if (configProps == null) {            configProps = new Properties();        }        configProps.setProperty("NetPeerGroupName", name);    }    /**     *  Sets the infrastructure PeerGroup description meta-data     *     * @see net.jxta.peergroup.PeerGroupFactory#setNetPGDesc     * @param  description  the infrastructure PeerGroup description     */    public void setInfrastructureDescription(String description) {        PeerGroupFactory.setNetPGDesc(description);        if (configProps == null) {            configProps = new Properties();        }        configProps.setProperty("NetPeerGroupDesc", description);    }    /**     *  Sets the current node configuration mode.     *  <p/>The default mode is EDGE, unless modified at construction time.     *  A node configuration mode defined a preset configuration     *  parameters based on a operating mode. i.e. an EDGE mode, enable     *  client/server side tcp, multicast, client side http, RelayService     *  client mode.     *  <p/> Valid modes include EDGE, RDV_SERVER,     *  RELAY_OFF, RELAY_CLIENT, RELAY_SERVER, PROXY_SERVER, or any combination     *  of which.<p/> e.g. RDV_SERVER + RELAY_SERVER     * @see #getMode     * @param  mode the new configuration mode     */    public void setMode(int mode) {        this.mode = mode;        if ((mode & PROXY_SERVER) == PROXY_SERVER && ((mode & RELAY_SERVER) != RELAY_SERVER)) {            /*            // A proxy must at the very least support relaying            if (LOG.isLoggable(Level.INFO)) {                LOG.log(Level.INFO, "Mode defined PROXY_SERVER, and no RELAY_SERVER, adding RELAY_SERVER support");            }            */            mode = mode | RELAY_SERVER;        }        //RELAY config         relayConfig.setClientEnabled((mode & RELAY_CLIENT) == RELAY_CLIENT);         relayConfig.setServerEnabled((mode & RELAY_SERVER) == RELAY_SERVER);        //RDV_SERVER        if ((mode & RDV_SERVER) == RDV_SERVER) {            rdvConfig.setConfiguration(RendezVousConfiguration.RENDEZVOUS);        } else if ((mode & RDV_CLIENT) == RDV_CLIENT) {            rdvConfig.setConfiguration(RendezVousConfiguration.EDGE);        } else if ((mode & RDV_AD_HOC) == RDV_AD_HOC) {            rdvConfig.setConfiguration(RendezVousConfiguration.AD_HOC);        }        //TCP        tcpConfig.setClientEnabled((mode & TCP_CLIENT) == TCP_CLIENT);        tcpConfig.setServerEnabled((mode & TCP_SERVER) == TCP_SERVER);        //HTTP        httpConfig.setClientEnabled((mode & HTTP_CLIENT) == HTTP_CLIENT);        httpConfig.setServerEnabled((mode & HTTP_SERVER) == HTTP_SERVER);        //Multicast        tcpConfig.setMulticastState((mode & IP_MULTICAST) == IP_MULTICAST);        //EDGE        if (mode == EDGE_NODE) {            rdvConfig.setConfiguration(RendezVousConfiguration.EDGE);        }    }    /**     *  Returns the current configuration mode     *  <p/>The default mode is EDGE, unless modified at construction time or through     *  Method {@link NetworkConfigurator#setMode}.  A node configuration mode defined a preset configuration     *  parameters based on a operating mode. i.e. an EDGE mode, enable     *  client/server side tcp, multicast, client side http, RelayService     *  client mode.     * @see #setMode     * @return  mode  the current mode value     */    public int getMode() {        return mode;    }    /**     *  Sets the IP group multicast address (default 224.0.1.85)     * @see #setMulticastPort     * @param  mcastAddress  the new multicast group address     */    public void setMulticastAddress(String mcastAddress) {        tcpConfig.setMulticastAddr(mcastAddress);    }    /**     *  Sets the IP group multicast port (default 1234)     * @see #setMulticastAddress     * @param  port  the new IP group multicast port     */    public void setMulticastPort(int port) {        tcpConfig.setMulticastPort(port);    }    /**     *  Sets the node name     *     * @param  name  node name     */    public void setName(String name) {        this.name = name;    }    /**     *  Sets the Principal for the peer root certificate     * @see #setPassword     * @see #getPrincipal     * @see #setPrincipal     * @param  principal the new principal value     */    public void setPrincipal(String principal) {        this.principal = principal;    }    /**     *  Gets the Principal for the peer root certificate     * @see #setPassword     * @see #getPrincipal     * @see #setPrincipal     * @return  principal  if a principal is set, null otherwise     */    public String getPrincipal() {        return principal;    }    /**     * Sets the public certificate for this configuration.     * @param  cert the new cert value     */    public void setCertificate(X509Certificate cert) {        this.cert = cert;    }    /**     *  Returns the public certificate for this configuration.     * @return  X509Certificate     */    public X509Certificate getCertificate() {        return cert;

⌨️ 快捷键说明

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