📄 rendezvousserviceinterface.java
字号:
/*
*
* $Id: RendezVousServiceInterface.java,v 1.2 2002/03/04 21:43:00 echtcherbina Exp $
*
* Copyright (c) 2001 Sun Microsystems, Inc. All rights reserved.
*
* 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 the
* Sun Microsystems, Inc. for Project JXTA."
* 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.
*
* =========================================================
*
* 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;
import java.util.*;
import java.io.*;
import java.net.*;
import net.jxta.rendezvous.*;
import net.jxta.peergroup.*;
import net.jxta.protocol.*;
import net.jxta.endpoint.*;
import net.jxta.service.*;
import net.jxta.peer.*;
import net.jxta.document.Advertisement;
import net.jxta.id.ID;
/**
* This class implements the RendezVousService interface.
*/
public class RendezVousServiceInterface implements RendezVousService {
RendezVousServiceImpl impl;
/**
* The only authorized constructor.
*/
public RendezVousServiceInterface(RendezVousServiceImpl theRealThing) {
impl = theRealThing;
}
/**
* returns an interface object that permits to use this
* service without having access to the real object.
*
* Since THIS is already such an object, it returns itself.
* FIXME: it is kind of absurd to have this method part of the
* interface but we do not want to define two levels of Service interface
* just for that.
* @return ResolverService An interface object that implements
* this service and nothing more.
*/
public Service getInterface() {
return this;
}
/**
* Returns the advertisment for that service.
*
* @return Advertisement the advertisement.
*
* @version $Revision: 1.2 $
* @since JXTA 1.0
*/
public Advertisement getImplAdvertisement() {
return impl.getImplAdvertisement();
}
/**
* Initialize the application
* FIXME: This is meaningless for the interface object;
* it is there only to satisfy the requirements of the
* interface that we implement. Ultimately, the API should define
* two levels of interfaces: one for the real service implementation
* and one for the interface object. Right now it feels a bit heavy
* to so that since the only different between the two would be
* init() and may-be getName().
* @param g PeerGroup this application is started from
* @since JXTA 1.0
*/
public void init(PeerGroup pg, ID assignedID, Advertisement impl) {
}
/**
* This is here for temporary class hierarchy reasons.
* it is ALWAYS ignored. By definition, the interface object
* protects the real object's start/stop methods from being called
*
* @param arg A table of strings arguments.
* @return int status indication.
*/
public int startApp(String[] arg) {
return 0;
}
/**
* This is here for temporary class hierarchy reasons.
* it is ALWAYS ignored. By definition, the interface object
* protects the real object's start/stop methods from being called
*
* This request is currently ignored.
*/
public void stopApp() {
}
/**
* Add a peer as a new RendezVousService point.
* If/When the RendezVousService accepts the connection, the RendezVousService
* service will invoke the RendezVousMonitor.
*
* @param adv the advertisement of the RendezVousService peer
* @exception IOException when the RendezVousService peer is not reachable
*/
public void connectToRendezVous (PeerAdvertisement adv)
throws IOException {
impl.connectToRendezVous (adv);
}
/**
* Add a peer as a new RendezVousService point.
* If/When the RendezVousService accepts the connection, the RendezVousService
* service will invoke the RendezVousMonitor.
*
* @param addr EndpointAddress of the rendezvous peer
* @exception IOException when the RendezVousService peer is not reachable
*/
public void connectToRendezVous (EndpointAddress addr) throws IOException {
impl.connectToRendezVous (addr);
}
/**
* Remove a RendezVousService point.
*
* @param rendezVous the PeerId of the RendezVousService point to remove
*/
public void disconnectFromRendezVous (PeerID rendezVous) {
impl.disconnectFromRendezVous (rendezVous);
}
/**
* Register a notification handler that is called each time a RendezVousService
* peer is not reachable anymore.
*
* @param handler a handler that is called each time a RendezVousService peer is
* is not reachable anymore.
* @return RendezVousMonitor returns, if any, the current RendezVousMonitor
*/
public RendezVousMonitor setMonitor (RendezVousMonitor handler) {
return impl.setMonitor (handler);
}
/**
* Returns an Enumeration of the PeerID all the RendezVousService on which this
* Peer is currentely connected.
*
* @return Enumeration enumeration of RendezVousService
*/
public Enumeration getConnectedRendezVous () {
return impl.getConnectedRendezVous();
}
/**
* Returns an Enumeration of the PeerID all the RendezVousService on which this
* Peer failed to connect to.
*
* @return Enumeration enumeration of RendezVousService
*/
public Enumeration getDisconnectedRendezVous () {
return impl.getDisconnectedRendezVous();
}
/**
** This portion is for peers that are RendezVousService
**/
/**
* Start the local peer as a RendezVousService peer. The caller must provide
* a handler to an authorization manager.
*
* @param handler is the RendezVousManager that will be invoked each
* time a new Peer request to be connected.
*
* @exception IOException when a handler has already been connected
*/
public void startRendezVous (RendezVousManager handler) throws IOException {
impl.startRendezVous (handler);
}
/**
* Start the local peer as a RendezVousService peer with the default rdv manager.
*
*/
public void startRendezVous() {
impl.startRendezVous();
}
/**
* Stop the RendezVousService function on the local Peer. All connected Peer are
* disconnected.
*/
public void stopRendezVous () {
impl.stopRendezVous();
}
/**
* Returns an Enumeration of PeerID of the peers that are currentely
* connected.
*
* @return Enumeration enumeration of peers connected to that rendezvous
*/
public Enumeration getConnectedPeers() {
return impl.getConnectedPeers();
}
/**
* Sends advertisement about other RendezVousService to a given peer
*
* @param destPeer is the advertisement of the peer to which to
* send the RendezVousService advertisement.
* @param rendezVous is the advertisment of a RendezVousService peer
*/
public void sendRendezVousAdv (PeerAdvertisement destPeer,
PeerAdvertisement rendezVous) {
impl.sendRendezVousAdv (destPeer, rendezVous);
}
/**
* Clients of the rendezvous service can use this to receive raw
* propagation rather than crawling query/responses. It takes care of TTL
* counting and loop detection.
*
* @param name The name of the listener.
* @param listener An EndpointListener to process the message.
*/
public void addPropagateListener(String name,
EndpointListener listener)
throws IOException {
impl.addPropagateListener(name, listener);
}
/**
* Removes a Listener previously added with addPropagateListener.
*
* @param name The name of the listener.
* @param listener An EndpointListener to process the message.
*/
public void removePropagateListener(String name,
EndpointListener listener)
throws IOException {
impl.removePropagateListener(name, listener);
}
/**
*
* Add a listener for RenDezVousEvents
*
* @param listener An RendezvousListener to process the event.
*/
public void addListener( RendezvousListener listener ) {
impl.addListener(listener);
}
/**
* Removes a Listener previously added with addListener.
*
* @param listener the RendezvousListener listener remove
*/
public boolean removeListener( RendezvousListener listener ) {
return impl.removeListener(listener);
}
public void propagate (Message msg,
String serviceName,
String serviceParam,
int defaultTTL)
throws IOException
{
impl.propagate (msg, serviceName, serviceParam, defaultTTL);
}
/**
* Propagates a message onto as many peers on the local network
* as possible. Typically the message will go to all the peers to
* which at least one endpoint transport can address without using
* the router.
*
* Only a single HOP at a time is performed. Messages are always
* delivered to the destination handler on arrival. This handler
* is responsible for repropagating further, if deemed appropropriate.
*
* Loop and TTL control are performed automatically.
*
* Messages can be propagated via this method for the first time or
* can be re-propagated by re-using a message that came in via propagation.
* In the later case, the TTL and loop detection parameters CANNOT be
* re-initialized. If one wants to "re-propagate" a message with a new TTL
* and blank gateways list one must generate a completely new message.
* This limits the risk of accidental propagation storms, although they
* can always be engineered deliberately.
*
* Note: The original msg is not modified and may be reused upon return.
*
* @param msg is the message to propagate.
* @param serviceName is the name of the service
* @param serviceParam is the parameter of the service
* @param prunePeer is a peer to prune in the propagation.
*/
public void propagateToNeighbors (Message msg, String serviceName,
String serviceParam, int defaultTTL,
String prunePeer)
throws IOException {
impl.propagateToNeighbors(msg, serviceName, serviceParam,
defaultTTL, prunePeer);
}
/**
* Propagates a message onto as many peers in the group as possible.
*
* Only a single HOP at a time is performed. Messages are always
* delivered to the destination handler on arrival. This handler
* is responsible for repropagating further, if deemed appropropriate.
*
* Loop and TTL control are performed automatically.
*
* Messages can be propagated via this method for the first time or
* can be re-propagated by re-using a message that came in via propagation.
* In the later case, the TTL and loop detection parameters CANNOT be
* re-initialized. If one wants to "re-propagate" a message with a new TTL
* and blank gateways list one must generate a completely new message.
* This limits the risk of accidental propagation storms, although they
* can always be engineered deliberately.
*
* Note: The original msg is not modified and may be reused upon return.
*
* @param msg is the message to propagate.
* @param serviceName is the name of the service
* @param serviceParam is the parameter of the service
* @param prunePeer is a peer to prune in the propagation.
*/
public void propagateInGroup (Message msg, String serviceName,
String serviceParam, int defaultTTL,
String prunePeer)
throws IOException {
impl.propagateInGroup(msg, serviceName, serviceParam,
defaultTTL, prunePeer);
}
/**
* Gets the rendezvousConnected attribute of the RendezVousServiceImpl object
*
* @return true if connected to a rendezvous, false otherwise
*/
public boolean isConnectedToRendezVous(){
return impl.isConnectedToRendezVous();
}
/**
* Get whether this Rendezvous service acts as a rendezvous or as a client.
*/
public boolean isRendezVous() {
return impl.isRendezVous();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -