2 * Copyright (c) 2001-2007 Sun Microsystems, Inc. All rights reserved.
4 * The Sun Project JXTA(TM) Software License
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * 3. The end-user documentation included with the redistribution, if any, must
17 * include the following acknowledgment: "This product includes software
18 * developed by Sun Microsystems, Inc. for JXTA(TM) technology."
19 * Alternately, this acknowledgment may appear in the software itself, if
20 * and wherever such third-party acknowledgments normally appear.
22 * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must
23 * not be used to endorse or promote products derived from this software
24 * without prior written permission. For written permission, please contact
25 * Project JXTA at http://www.jxta.org.
27 * 5. Products derived from this software may not be called "JXTA", nor may
28 * "JXTA" appear in their name, without prior written permission of Sun.
30 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
32 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SUN
33 * MICROSYSTEMS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
36 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
39 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 * JXTA is a registered trademark of Sun Microsystems, Inc. in the United
42 * States and other countries.
44 * Please see the license information page at :
45 * <http://www.jxta.org/project/www/license.html> for instructions on use of
46 * the license in source files.
48 * ====================================================================
50 * This software consists of voluntary contributions made by many individuals
51 * on behalf of Project JXTA. For more information on Project JXTA, please see
52 * http://www.jxta.org.
54 * This license is based on the BSD license adopted by the Apache Foundation.
57 package net.jxta.rendezvous;
60 import java.io.IOException;
61 import java.util.Enumeration;
62 import java.util.Vector;
64 import net.jxta.endpoint.EndpointAddress;
65 import net.jxta.endpoint.EndpointListener;
66 import net.jxta.endpoint.Message;
67 import net.jxta.id.ID;
68 import net.jxta.protocol.PeerAdvertisement;
69 import net.jxta.protocol.RdvAdvertisement;
70 import net.jxta.service.Service;
74 * The RendezVous Service provides propagation of messages within a JXTA
77 * <p/>The JXTA RendezVous Service defines a subscription mechanism
78 * allowing JXTA peers to receive propagated messages (clients of the service)
79 * or become a repeater of the service (rendezvous peers).
81 * <p/>The Standard Reference Implementation requires that at least one peer in
82 * a PeerGroup to act as a Rendezvous. Rendezvous peers may dynamically join or
83 * leave the PeerGroup over time.
85 * @see <a href="https://jxta-spec.dev.java.net/nonav/JXTAProtocols.html#proto-rvp" target='_blank'>JXTA Protocols Specification : Rendezvous</a>
87 public interface RendezVousService extends Service {
90 * Perform <code>propagate()</code> or <code>walk()</code> using the most
91 * appropriate TTL value for the implementation and configuration. The
92 * message will almost certainly be sent with a TTL value much less than
95 public final static int DEFAULT_TTL = Integer.MAX_VALUE;
98 * Attempt connection to the specified RendezVous peer.
100 * @deprecated Directly connecting to rendezvous peers is not recommended.
101 * Seed rendezvous should be specified using the RdvConfigAdv mechanisms.
103 * @param adv the advertisement of the RendezVousService peer
104 * @throws IOException When the specified peer is unreachable
107 public void connectToRendezVous(PeerAdvertisement adv) throws IOException;
110 * Attempt connection to the specified RendezVous peer.
112 * @deprecated Directly connecting to rendezvous peers is not recommended.
113 * Seed rendezvous should be specified using the RdvConfigAdv mechanisms.
115 * @param addr EndpointAddress of the rendezvous peer
116 * @throws IOException When the specified peer is unreachable
119 public void connectToRendezVous(EndpointAddress addr) throws IOException;
122 * Disconnect from the specified rendezvous.
124 * @param peerID the PeerId of the RendezVous to disconnect from.
126 public void disconnectFromRendezVous(ID peerID);
129 * Returns an Enumeration of the PeerID all the RendezVous on which this
130 * Peer is currently connected. This returns the same result as
131 * {@link #getConnectedPeers()}.
133 * @return Enumeration enumeration of RendezVous.
135 public Enumeration<ID> getConnectedRendezVous();
138 * Returns an Enumeration of the PeerID all the RendezVous on which this
139 * Peer failed to connect to.
141 * @deprecated Due to design changes this no longer returns accurate nor
142 * complete results. It will eventually be removed.
144 * @return Enumeration of the PeerID all the RendezVous on which this
145 * Peer failed to connect to.
148 public Enumeration<ID> getDisconnectedRendezVous();
151 * Start the local peer as a RendezVous peer.
153 public void startRendezVous();
156 * Stop the RendezVous function on the local Peer. All connected Peers are
159 public void stopRendezVous();
162 * Returns an Enumeration of the PeerID of the peers that are currently
163 * connected to this peer. Depending upon the role of of this peer the
164 * result may be an enumeration of clients or an enumeration of rendezvous
167 * @return Enumeration of {@link net.jxta.peer.PeerID} connected to this peer.
169 public Enumeration<ID> getConnectedPeers();
172 * Returns a Vector of the PeerID of the peers that are currently
173 * connected to this peer. Depending upon the role of of this peer the
174 * result may be an enumeration of clients or an enumeration of rendezvous
177 * @return Vector of {@link net.jxta.peer.PeerID} connected to this peer.
179 public Vector<ID> getConnectedPeerIDs();
182 * Registers the provided listener under the given serviceName and
183 * serviceParam to receive messages propagated by the Rendezvous service.
184 * The listener will be added only if no other listener is already
185 * registered with these names.
187 * @deprecated This method just calls
188 * {@link net.jxta.endpoint.EndpointService#addIncomingMessageListener}. It's better to just
189 * register your listener with the Endpoint. This call <b>may</b> be
190 * eventually removed.
192 * @param serviceName The serviceName of the listener.
193 * @param serviceParam The serviceParam of the listener.
194 * @param listener An EndpointListener to process the message.
195 * @return true if listener was registered, otherwise false.
198 public boolean addPropagateListener(String serviceName, String serviceParam, EndpointListener listener);
201 * Removes a Listener previously added with addPropagateListener.
202 * If the given listener is not the one currently registered, nothing is removed.
204 * @deprecated This method just calls
205 * {@link net.jxta.endpoint.EndpointService#removeIncomingMessageListener}.
206 * It's better to just deregister your listener with the Endpoint. This call
207 * <b>may</b> be eventually removed.
209 * @param serviceName The serviceName of the listener.
210 * @param serviceParam The serviceParam of the listener.
211 * @param listener An EndpointListener to process the message.
212 * @return the listener removed, <tt>null</tt> if the listener was not registered.
215 public EndpointListener removePropagateListener(String serviceName, String serviceParam, EndpointListener listener);
218 * Add a listener for RendezVousEvents.
220 * @param listener An RendezvousListener to process the event.
222 public void addListener(RendezvousListener listener);
225 * Removes a Rendezvous event listener previously added with addListener.
227 * @param listener the RendezvousListener listener remove
228 * @return true if successful
230 public boolean removeListener(RendezvousListener listener);
233 * Propagates a message to the local network and to as many members of
234 * the peer group as possible.
236 * <p/>This method sends the message to all peers, rendezvous peers and
237 * edge peer. This method of propagation is very expensive and should
238 * be used very cautiously. When rendezvous peers are used in order to
239 * cache index of data, it is more efficient to use the walk() method.
241 * <p/>Only a single HOP at a time is performed. Messages are always
242 * delivered to the destination handler on arrival. This handler
243 * is responsible for repropagating further, if deemed appropriate.
245 * <p/>Loop and TTL control are performed automatically.
247 * <p/>Messages can be propagated via this method for the first time or
248 * can be re-propagated by re-using a message that came in via propagation.
249 * In the later case, the TTL and loop detection parameters CANNOT be
250 * re-initialized. If one wants to "re-propagate" a message with a new TTL
251 * and blank gateways list one must generate a completely new message.
252 * This limits the risk of accidental propagation storms, although they
253 * can always be engineered deliberately.
255 * @param msg is the message to propagate.
256 * @param serviceName is the name of the service.
257 * @param serviceParam is the parameter of the service.
258 * @param ttl The requested TTL for the message.
259 * @exception IOException if an io error occurs
261 public void propagate(Message msg, String serviceName, String serviceParam, int ttl) throws IOException;
264 * Propagates a message to the specified peers.
266 * @param destPeerIds An enumeration of PeerIDs of the peers that are the
267 * intended recipients of the propagated message.
268 * @param msg The message to propagate.
269 * @param serviceName The name of the service.
270 * @param serviceParam The parameter of the service.
271 * @param ttl The requested TTL for the message.
272 * @exception IOException if an io error occurs
274 public void propagate(Enumeration<? extends ID> destPeerIds, Message msg, String serviceName, String serviceParam, int ttl) throws IOException;
277 * Propagates a message to members of the peer group reachable via the
278 * local network. Typically this is accomplished by broadcasting or
281 * <p/>Only a single HOP at a time is performed. Messages are always
282 * delivered to the destination handler on arrival. This handler
283 * is responsible for repropagating further, if deemed appropriate.
285 * <p/>Loop and TTL control are performed automatically.
287 * <p/>Messages can be propagated via this method for the first time or
288 * can be re-propagated by re-using a message that came in via propagation.
289 * In the later case, the TTL and loop detection parameters CANNOT be
290 * re-initialized. If one wants to "re-propagate" a message with a new TTL
291 * and blank gateways list one must generate a completely new message.
292 * This limits the risk of accidental propagation storms, although they
293 * can always be engineered deliberately.
295 * @param msg is the message to propagate.
296 * @param serviceName is the name of the service.
297 * @param serviceParam is the parameter of the service.
298 * @param ttl The requested TTL for the message.
299 * @exception IOException if an io error occurs
301 public void propagateToNeighbors(Message msg, String serviceName, String serviceParam, int ttl) throws IOException;
304 * Propagates a message to as many members of the peer group as possible.
306 * <p/>Only a single HOP at a time is performed. Messages are always
307 * delivered to the destination handler on arrival. This handler
308 * is responsible for repropagating further, if deemed appropriate.
310 * <p/>Loop and TTL control are performed automatically.
312 * <p/>Messages can be propagated via this method for the first time or
313 * can be re-propagated by re-using a message that came in via propagation.
314 * In the later case, the TTL and loop detection parameters CANNOT be
315 * re-initialized. If one wants to "re-propagate" a message with a new TTL
316 * and blank gateways list one must generate a completely new message.
317 * This limits the risk of accidental propagation storms, although they
318 * can always be engineered deliberately.
320 * @param msg is the message to propagate.
321 * @param serviceName is the name of the service
322 * @param serviceParam is the parameter of the service
323 * @param ttl The requested TTL for the message.
324 * @exception IOException if an io error occurs
326 public void propagateInGroup(Message msg, String serviceName, String serviceParam, int ttl) throws IOException;
329 * Return {@code true} if connected to a rendezvous.
331 * @return {@code true} if connected to a rendezvous otherwise {@code false}.
333 public boolean isConnectedToRendezVous();
336 * Returns {@code true} if this peer is acting as a rendezvous peer (per the
337 * implementation definition) within the peer group. {@code false} is
338 * returned for all other peer roles.
340 * @return {@code true} if this peer is acting as a rendezvous peer (per the
341 * implementation definition) within the peer group. {@code false} is
342 * returned for all other peer roles.
344 public boolean isRendezVous();
347 * Returns the current role of this peer within the peergroup.
349 * @return The current role of this peer within the peergroup.
351 public RendezVousStatus getRendezVousStatus();
354 * Enable or disable the automatic switching between an Edge Peer
355 * and a Rendezvous Peer.
357 * @param auto {@code true} will activate automatic role switching.
358 * @return The previous auto start value.
360 public boolean setAutoStart(boolean auto);
363 * Enable or disable the automatic switching between an Edge Peer
364 * and a Rendezvous Peer.
366 * @param auto {@code true} will activate automatic role switching.
367 * @param period The interval in milliseconds at which the peer should
368 * reconsider it's role.
369 * @return The previous auto start value.
371 public boolean setAutoStart(boolean auto, long period);
374 * Walk a message through the rendezvous peers of the network: only
375 * rendezvous peers will receive the message.
377 * <p/>Only a single HOP at a time is performed. Messages are always
378 * delivered to the destination handler on arrival. This handler
379 * is responsible for repropagating further, if deemed appropriate.
381 * <p/>Loop and TTL control are performed automatically.
383 * <p/>Messages can be propagated via this method for the first time or
384 * can be re-propagated by re-using a message that came in via propagation.
385 * In the later case, the TTL and loop detection parameters CANNOT be
386 * re-initialized. If one wants to "re-propagate" a message with a new TTL
387 * and blank gateways list one must generate a completely new message.
388 * This limits the risk of accidental propagation storms, although they
389 * can always be engineered deliberately.
391 * <p/><b>Note</b>: The original msg is not modified and may be reused upon return.
393 * @param msg is the message to walk.
394 * @param serviceName is the name of the service
395 * @param serviceParam is the parameter of the service
396 * @param ttl is the maximum TTL of the message.
397 * @throws IOException when walking the message is impossible (network failure)
399 public void walk(Message msg, String serviceName, String serviceParam, int ttl) throws IOException;
402 * <p/>Walk a message through the rendezvous peers of the network: only
403 * rendezvous peers will receive the message.
405 * <p/>Only a single HOP at a time is performed. Messages are always
406 * delivered to the destination handler on arrival. This handler
407 * is responsible for repropagating further, if deemed appropriate.
409 * <p/>Loop and TTL control are performed automatically.
411 * <p/>Messages can be propagated via this method for the first time or
412 * can be re-propagated by re-using a message that came in via propagation.
413 * In the later case, the TTL and loop detection parameters CANNOT be
414 * re-initialized. If one wants to "re-propagate" a message with a new TTL
415 * and blank gateways list one must generate a completely new message.
416 * This limits the risk of accidental propagation storms, although they
417 * can always be engineered deliberately.
419 * <p/><b>Note</b>: The original msg is not modified and may be reused upon return.
421 * @param destPeerIDs is a Vector of PeerIDs of the peers which are receiving
422 * first the walker. Note that each entry in the Vector will create its own
424 * @param msg is the message to walk.
425 * @param serviceName is the name of the service
426 * @param serviceParam is the parameter of the service
427 * @param ttl is the maximum TTL of the message.
428 * @throws IOException when walking the message is impossible (network failure)
430 public void walk(Vector<? extends ID> destPeerIDs, Message msg, String serviceName, String serviceParam, int ttl) throws IOException;
433 * Returns a vector of RdvAdvertisement of the local view of rendezvous peers.
435 * @deprecated Due to design changes, the list of peers may be empty in
436 * configurations which previously returned a non-empty result. Future
437 * JXTA versions are likely to use a different API.
439 * @return The local view of RDV peers.
442 public Vector<RdvAdvertisement> getLocalWalkView();
445 * Set a new deadline for the rendezvous to be proven alive.
446 * As a result a lease response must be sought and obtained within the
447 * specified delay or the rdv is considered disconnected.
449 * <p/>A timeout of 0 or less triggers immediate disconnection.
451 * @param peer The peer to be challenged
452 * @param timeout The delay
454 public void challengeRendezVous(ID peer, long timeout);