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

📄 relayconfigadv.java

📁 JXTA&#8482 is a set of open, generalized peer-to-peer (P2P) protocols that allow any networked devi
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (c) 2004-2007 Sun Microsystems, Inc.  All rights reserved. *   *  The Sun Project JXTA(TM) Software License *   *  Redistribution and use in source and binary forms, with or without  *  modification, are permitted provided that the following conditions are met: *   *  1. Redistributions of source code must retain the above copyright notice, *     this list of conditions and the following disclaimer. *   *  2. Redistributions in binary form must reproduce the above copyright notice,  *     this list of conditions and the following disclaimer in the documentation  *     and/or other materials provided with the distribution. *   *  3. The end-user documentation included with the redistribution, if any, must  *     include the following acknowledgment: "This product includes software  *     developed by Sun Microsystems, Inc. for JXTA(TM) technology."  *     Alternately, this acknowledgment may appear in the software itself, if  *     and wherever such third-party acknowledgments normally appear. *   *  4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must  *     not be used to endorse or promote products derived from this software  *     without prior written permission. For written permission, please contact  *     Project JXTA at http://www.jxta.org. *   *  5. Products derived from this software may not be called "JXTA", nor may  *     "JXTA" appear in their name, without prior written permission of Sun. *   *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND  *  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SUN  *  MICROSYSTEMS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *   *  JXTA is a registered trademark of Sun Microsystems, Inc. in the United  *  States and other countries. *   *  Please see the license information page at : *  <http://www.jxta.org/project/www/license.html> for instructions on use of  *  the license in source files. *   *  ==================================================================== *   *  This software consists of voluntary contributions made by many individuals  *  on behalf of Project JXTA. For more information on Project JXTA, please see  *  http://www.jxta.org. *   *  This license is based on the BSD license adopted by the Apache Foundation.  */package net.jxta.impl.protocol;import net.jxta.document.Advertisement;import net.jxta.document.AdvertisementFactory;import net.jxta.document.Attributable;import net.jxta.document.Attribute;import net.jxta.document.Document;import net.jxta.document.Element;import net.jxta.document.ExtendableAdvertisement;import net.jxta.document.MimeMediaType;import net.jxta.document.StructuredDocument;import net.jxta.document.XMLElement;import net.jxta.endpoint.EndpointAddress;import net.jxta.id.ID;import net.jxta.impl.util.TimeUtils;import java.util.logging.Level;import net.jxta.logging.Logging;import java.util.logging.Logger;import java.net.URI;import java.util.Enumeration;import java.util.HashSet;import java.util.Set;/** * Contains parameters for configuration of the Reference Implemenation * Relay Service. * <p/> * <p/><pre><code> * <p/> * </code></pre> */public final class RelayConfigAdv extends ExtendableAdvertisement implements Cloneable {    /**     * Log4J Logger     */    private static final Logger LOG = Logger.getLogger(RelayConfigAdv.class.getName());    /**     * Our DOCTYPE     */    private static final String advType = "jxta:RelayConfig";    private static final String RELAY_CLIENT_ATTR = "client";    private static final String RELAY_SERVER_ATTR = "server";    private static final String RELAY_CLIENT_ELEMENT = "client";    private static final String RELAY_CLIENT_SERVERS_ATTR = "maxRelays";    private static final String RELAY_CLIENT_LEASE_ATTR = "maxLease";    private static final String RELAY_CLIENT_POLL_ATTR = "messengerPollInterval";    private static final String RELAY_CLIENT_SEEDS_ELEMENT = "seeds";    private static final String USE_ONLY_SEEDS_ATTR = "useOnlySeeds";    private static final String SEED_RELAY_ADDR_ELEMENT = "addr";    private static final String SEED_RELAY_ADDR_SEEDING_ATTR = "seeding";    private static final String RELAY_SERVER_ELEMENT = "server";    private static final String RELAY_SERVER_CLIENTS_ATTR = "maxClients";    private static final String RELAY_SERVER_QUEUE_ATTR = "clientQueue";    private static final String RELAY_SERVER_LEASE_ATTR = "leaseDuration";    private static final String RELAY_SERVER_STALL_ATTR = "stallTimeout";    private static final String RELAY_SERVER_ANNOUNCE_ATTR = "announceInterval";    private static final String ACL_URI = "acl";    private static final String[] fields = {};    /**     * Are we configured as a relay client?     */    private boolean clientEnabled = false;    /**     * Max Relays     */    private int maxRelays = -1;    /**     * Max clients lease in relative milliseconds.     */    private long maxClientLeaseDuration = -1;    /**     * Messenger poll interval in relative milliseconds.     */    private long messengerPollInterval = -1;    /**     * Use only seeded relays.     */    private boolean useOnlySeeds = false;    /**     * Seed Relays     * <p/>     * <ul>     * <li>Elements are {@link net.jxta.endpoint.EndpointAddress}</li>     * </ul>     */    private Set<EndpointAddress> seedRelays = new HashSet<EndpointAddress>();    /**     * The list of seeding resources.     * <p/>     * <p/><ul>     * <li>The values are {@link java.net.URI}.</li>     * </ul>     */    private Set<URI> seedingURIs = new HashSet<URI>();    /**     * Are we configured as a relay server?     */    private boolean serverEnabled = false;    /**     * Max Clients     */    private int maxClients = -1;    /**     */    private int maxClientMessageQueue = -1;    /**     * Max Lease offered by server in relative milliseconds.     */    private long maxServerLeaseDuration = -1;    /**     * Stall timeout in relative milliseconds.     */    private long stallTimeout = -1;    /**     * Announce interval in relative milliseconds.     */    private long announceInterval = -1;    /**     * Access control URI     */    private URI aclURI = null;    /**     * Instantiator for RelayConfigAdv     */    public static class Instantiator implements AdvertisementFactory.Instantiator {        /**         * {@inheritDoc}         */        public String getAdvertisementType() {            return advType;        }        /**         * {@inheritDoc}         */        public Advertisement newInstance() {            return new RelayConfigAdv();        }        /**         * {@inheritDoc}         */        public Advertisement newInstance(Element root) {            return new RelayConfigAdv(root);        }    }    /**     * Returns the identifying type of this Advertisement.     * <p/>     * <p/><b>Note:</b> This is a static method. It cannot be used to determine     * the runtime type of an advertisment. ie.     * </p><code><pre>     *      Advertisement adv = module.getSomeAdv();     *      String advType = adv.getAdvertisementType();     *  </pre></code>     * <p/>     * <p/><b>This is wrong and does not work the way you might expect.</b>     * This call is not polymorphic and calls     * Advertiement.getAdvertisementType() no matter what the real type of the     * advertisment.     *     * @return String the type of advertisement     */    public static String getAdvertisementType() {        return advType;    }    private RelayConfigAdv() {}    private RelayConfigAdv(Element root) {        if (!XMLElement.class.isInstance(root)) {            throw new IllegalArgumentException(getClass().getName() + " only supports XLMElement");        }        XMLElement doc = (XMLElement) root;        String doctype = doc.getName();        String typedoctype = "";        Attribute itsType = doc.getAttribute("type");        if (null != itsType) {            typedoctype = itsType.getValue();        }        if (!doctype.equals(getAdvertisementType()) && !getAdvertisementType().equals(typedoctype)) {            throw new IllegalArgumentException(                    "Could not construct : " + getClass().getName() + "from doc containing a " + doc.getName());        }        Enumeration eachAttr = doc.getAttributes();        while (eachAttr.hasMoreElements()) {            Attribute aRelayAttr = (Attribute) eachAttr.nextElement();            if (super.handleAttribute(aRelayAttr)) {                // nothing to do                ;            } else if (RELAY_CLIENT_ATTR.equals(aRelayAttr.getName())) {                clientEnabled = Boolean.valueOf(aRelayAttr.getValue().trim());            } else if (RELAY_SERVER_ATTR.equals(aRelayAttr.getName())) {                serverEnabled = Boolean.valueOf(aRelayAttr.getValue().trim());            } else {                if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                    LOG.warning("Unhandled Attribute: " + aRelayAttr.getName());                }            }        }        Enumeration elements = doc.getChildren();        while (elements.hasMoreElements()) {            XMLElement elem = (XMLElement) elements.nextElement();            if (!handleElement(elem)) {                if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                    LOG.warning("Unhandled Element: " + elem.toString());                }            }        }        // Sanity Check!!!        if ((-1 != maxRelays) && (maxRelays <= 0)) {            throw new IllegalArgumentException("Max relays must not be negative or zero.");        }        if ((-1 != maxClientLeaseDuration) && (maxClientLeaseDuration <= 0)) {            throw new IllegalArgumentException("Max lease duration must not be negative or zero.");        }        if ((-1 != messengerPollInterval) && (messengerPollInterval <= 0)) {            throw new IllegalArgumentException("Messenger poll interval must not be negative or zero.");        }        if (useOnlySeeds && clientEnabled && seedRelays.isEmpty() && seedingURIs.isEmpty()) {            throw new IllegalArgumentException("Cannot specify 'useOnlySeeds' and no seed relays");        }        if ((-1 != maxClients) && (maxClients <= 0)) {            throw new IllegalArgumentException("Max clients must not be negative or zero.");        }        if ((-1 != maxClientMessageQueue) && (maxClientMessageQueue <= 0)) {            throw new IllegalArgumentException("Max client queue must not be negative or zero.");        }        if ((-1 != maxServerLeaseDuration) && (maxServerLeaseDuration <= 0)) {            throw new IllegalArgumentException("Max lease duration must not be negative or zero.");        }

⌨️ 快捷键说明

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