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

📄 edgepeerrdvservice.java

📁 JXTA&#8482 is a set of open, generalized peer-to-peer (P2P) protocols that allow any networked devi
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (c) 2001-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.rendezvous.edge;import java.net.URI;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.TimerTask;import java.util.Vector;import java.util.logging.Level;import java.util.logging.Logger;import java.io.IOException;import java.net.URISyntaxException;import net.jxta.discovery.DiscoveryService;import net.jxta.document.Advertisement;import net.jxta.document.AdvertisementFactory;import net.jxta.document.StructuredDocumentFactory;import net.jxta.document.XMLDocument;import net.jxta.endpoint.EndpointAddress;import net.jxta.endpoint.Message;import net.jxta.endpoint.MessageElement;import net.jxta.endpoint.Messenger;import net.jxta.endpoint.MessageTransport;import net.jxta.endpoint.TextDocumentMessageElement;import net.jxta.id.ID;import net.jxta.id.IDFactory;import net.jxta.impl.endpoint.relay.RelayReferralSeedingManager;import net.jxta.logging.Logging;import net.jxta.peer.PeerID;import net.jxta.peergroup.PeerGroup;import net.jxta.peergroup.PeerGroupID;import net.jxta.platform.Module;import net.jxta.protocol.ConfigParams;import net.jxta.protocol.PeerAdvertisement;import net.jxta.protocol.RouteAdvertisement;import net.jxta.rendezvous.RendezvousEvent;import net.jxta.impl.protocol.RdvConfigAdv;import net.jxta.impl.rendezvous.PeerConnection;import net.jxta.impl.rendezvous.RendezVousPropagateMessage;import net.jxta.impl.rendezvous.RendezVousServiceImpl;import net.jxta.impl.rendezvous.RendezVousServiceProvider;import net.jxta.impl.rendezvous.StdRendezVousService;import net.jxta.impl.rendezvous.rendezvousMeter.RendezvousConnectionMeter;import net.jxta.impl.rendezvous.rendezvousMeter.RendezvousMeterBuildSettings;import net.jxta.impl.rendezvous.rpv.PeerviewSeedingManager;import net.jxta.impl.util.SeedingManager;import net.jxta.impl.util.TimeUtils;import net.jxta.impl.util.URISeedingManager;/** * A JXTA {@link net.jxta.rendezvous.RendezVousService} implementation which * implements the client portion of the standard JXTA Rendezvous Protocol (RVP). * * @see net.jxta.rendezvous.RendezVousService * @see <a href="https://jxta-spec.dev.java.net/nonav/JXTAProtocols.html#proto-rvp" target="_blank">JXTA Protocols Specification : Rendezvous Protocol</a> */public class EdgePeerRdvService extends StdRendezVousService {        /**     * Logger     */    private final static transient Logger LOG = Logger.getLogger(EdgePeerRdvService.class.getName());        /**     * Interval in milliseconds at which we will check our rendezvous connection.     */    private final static long MONITOR_INTERVAL = 15 * TimeUtils.ASECOND;        /**     * Number of rendezvous we will try to connect to.     */    private final int MAX_RDV_CONNECTIONS = 1;        /**     * The default amount of time we will attempt to renew a lease before it     * expires.     */    private long LEASE_MARGIN = 5 * TimeUtils.AMINUTE;        /**     * Our source for rendezvous server seeds.     */    private final SeedingManager seedingManager;        /**     * Our current seeds.     */    private final List<RouteAdvertisement> seeds = new ArrayList<RouteAdvertisement>();        /**     * Our current connections with RendezVous peers.     */    private final Map<ID, RdvConnection> rendezVous = Collections.synchronizedMap(new HashMap<ID, RdvConnection>());        /**     * Standard Constructor     *     * @param group      Description of Parameter     * @param rdvService Description of Parameter     */    public EdgePeerRdvService(PeerGroup group, RendezVousServiceImpl rdvService) {                super(group, rdvService);                Advertisement adv = null;        ConfigParams confAdv = group.getConfigAdvertisement();                // Get the config. If we do not have a config, we're done; we just keep        // the defaults (edge peer/no auto-rdv)        if (confAdv != null) {            adv = confAdv.getSvcConfigAdvertisement(rdvService.getAssignedID());        }                RdvConfigAdv rdvConfigAdv;                if (!(adv instanceof RdvConfigAdv)) {            if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {                LOG.fine("Creating new RdvConfigAdv for defaults.");            }            rdvConfigAdv = (RdvConfigAdv) AdvertisementFactory.newAdvertisement(RdvConfigAdv.getAdvertisementType());        } else {            rdvConfigAdv = (RdvConfigAdv) adv;        }                if (-1 != rdvConfigAdv.getMaxTTL()) {            MAX_TTL = rdvConfigAdv.getMaxTTL();        }                if (0 != rdvConfigAdv.getLeaseMargin()) {            LEASE_MARGIN = rdvConfigAdv.getLeaseMargin();        }                String serviceName = rdvService.getAssignedID().toString() + group.getPeerGroupID().getUniqueValue().toString();        if (PeerGroupID.worldPeerGroupID.equals(group.getParentGroup().getPeerGroupID())) {            URISeedingManager uriSeedingManager;                        if (rdvConfigAdv.getProbeRelays()) {                uriSeedingManager = new RelayReferralSeedingManager(rdvConfigAdv.getAclUri(), rdvConfigAdv.getUseOnlySeeds(), group, serviceName);            } else {                uriSeedingManager = new URISeedingManager(rdvConfigAdv.getAclUri(), rdvConfigAdv.getUseOnlySeeds(), group, serviceName);            }                        for (URI aSeeder : Arrays.asList(rdvConfigAdv.getSeedingURIs())) {                uriSeedingManager.addSeedingURI(aSeeder);            }                        for (URI aSeed : Arrays.asList(rdvConfigAdv.getSeedRendezvous())) {                uriSeedingManager.addSeed(aSeed);            }                        this.seedingManager = uriSeedingManager;        } else {            this.seedingManager = new PeerviewSeedingManager(rdvConfigAdv.getAclUri(), group, group.getParentGroup(), serviceName);        }                if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {            LOG.info("RendezVous Service is initialized for " + group.getPeerGroupID() + " as an Edge peer.");        }    }        /**     * Listener for     * <p/>     * &lt;assignedID>     */    private class StdRdvEdgeProtocolListener implements StdRendezVousService.StdRdvProtocolListener {                /**         * {@inheritDoc}         */        public void processIncomingMessage(Message msg, EndpointAddress srcAddr, EndpointAddress dstAddr) {                        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {                LOG.fine("[" + group.getPeerGroupID() + "] processing " + msg);            }                        if ((msg.getMessageElement(RendezVousServiceProvider.RDV_MSG_NAMESPACE_NAME, ConnectedPeerReply) != null)                    || (msg.getMessageElement(RendezVousServiceProvider.RDV_MSG_NAMESPACE_NAME, ConnectedRdvAdvReply) != null)) {                processConnectedReply(msg);            }                        if (msg.getMessageElement(RendezVousServiceProvider.RDV_MSG_NAMESPACE_NAME, DisconnectRequest) != null) {                processDisconnectRequest(msg);            }        }    }        /**     * {@inheritDoc}     */    @Override    protected int startApp(String[] arg) {                super.startApp(arg, new StdRdvEdgeProtocolListener());                // The other services may not be fully functional but they're there        // so we can start our subsystems.        // As for us, it does not matter if our methods are called between init        // and startApp().                if (RendezvousMeterBuildSettings.RENDEZVOUS_METERING && (rendezvousMeter != null)) {            rendezvousMeter.startEdge();        }                rdvService.generateEvent(RendezvousEvent.BECAMEEDGE, group.getPeerID());                timer.schedule(new MonitorTask(), 0, MONITOR_INTERVAL);                return Module.START_OK;    }        /**     * {@inheritDoc}     */    @Override    public synchronized void stopApp() {                if (closed) {            return;        }                closed = true;                seedingManager.stop();                disconnectFromAllRendezVous();                super.stopApp();

⌨️ 快捷键说明

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