2 * Copyright (c) 2004-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.impl.protocol;
60 import net.jxta.document.Advertisement;
61 import net.jxta.document.AdvertisementFactory;
62 import net.jxta.document.Attributable;
63 import net.jxta.document.Attribute;
64 import net.jxta.document.Document;
65 import net.jxta.document.Element;
66 import net.jxta.document.ExtendableAdvertisement;
67 import net.jxta.document.MimeMediaType;
68 import net.jxta.document.StructuredDocument;
69 import net.jxta.document.XMLElement;
70 import net.jxta.endpoint.EndpointAddress;
71 import net.jxta.id.ID;
72 import net.jxta.impl.util.TimeUtils;
73 import java.util.logging.Level;
74 import net.jxta.logging.Logging;
75 import java.util.logging.Logger;
78 import java.util.Enumeration;
79 import java.util.HashSet;
84 * Contains parameters for configuration of the Reference Implemenation
91 public final class RelayConfigAdv extends ExtendableAdvertisement implements Cloneable {
96 private static final Logger LOG = Logger.getLogger(RelayConfigAdv.class.getName());
101 private static final String advType = "jxta:RelayConfig";
103 private static final String RELAY_CLIENT_ATTR = "client";
104 private static final String RELAY_SERVER_ATTR = "server";
106 private static final String RELAY_CLIENT_ELEMENT = "client";
107 private static final String RELAY_CLIENT_SERVERS_ATTR = "maxRelays";
108 private static final String RELAY_CLIENT_LEASE_ATTR = "maxLease";
109 private static final String RELAY_CLIENT_POLL_ATTR = "messengerPollInterval";
111 private static final String RELAY_CLIENT_SEEDS_ELEMENT = "seeds";
112 private static final String USE_ONLY_SEEDS_ATTR = "useOnlySeeds";
114 private static final String SEED_RELAY_ADDR_ELEMENT = "addr";
115 private static final String SEED_RELAY_ADDR_SEEDING_ATTR = "seeding";
117 private static final String RELAY_SERVER_ELEMENT = "server";
118 private static final String RELAY_SERVER_CLIENTS_ATTR = "maxClients";
119 private static final String RELAY_SERVER_QUEUE_ATTR = "clientQueue";
120 private static final String RELAY_SERVER_LEASE_ATTR = "leaseDuration";
121 private static final String RELAY_SERVER_STALL_ATTR = "stallTimeout";
122 private static final String RELAY_SERVER_ANNOUNCE_ATTR = "announceInterval";
123 private static final String ACL_URI = "acl";
125 private static final String[] fields = {};
128 * Are we configured as a relay client?
130 private boolean clientEnabled = false;
135 private int maxRelays = -1;
138 * Max clients lease in relative milliseconds.
140 private long maxClientLeaseDuration = -1;
143 * Messenger poll interval in relative milliseconds.
145 private long messengerPollInterval = -1;
148 * Use only seeded relays.
150 private boolean useOnlySeeds = false;
156 * <li>Elements are {@link net.jxta.endpoint.EndpointAddress}</li>
159 private Set<EndpointAddress> seedRelays = new HashSet<EndpointAddress>();
162 * The list of seeding resources.
165 * <li>The values are {@link java.net.URI}.</li>
168 private Set<URI> seedingURIs = new HashSet<URI>();
171 * Are we configured as a relay server?
173 private boolean serverEnabled = false;
178 private int maxClients = -1;
182 private int maxClientMessageQueue = -1;
185 * Max Lease offered by server in relative milliseconds.
187 private long maxServerLeaseDuration = -1;
190 * Stall timeout in relative milliseconds.
192 private long stallTimeout = -1;
195 * Announce interval in relative milliseconds.
197 private long announceInterval = -1;
202 private URI aclURI = null;
205 * Instantiator for RelayConfigAdv
207 public static class Instantiator implements AdvertisementFactory.Instantiator {
212 public String getAdvertisementType() {
219 public Advertisement newInstance() {
220 return new RelayConfigAdv();
226 public Advertisement newInstance(Element root) {
227 return new RelayConfigAdv(root);
232 * Returns the identifying type of this Advertisement.
234 * <p/><b>Note:</b> This is a static method. It cannot be used to determine
235 * the runtime type of an advertisment. ie.
237 * Advertisement adv = module.getSomeAdv();
238 * String advType = adv.getAdvertisementType();
241 * <p/><b>This is wrong and does not work the way you might expect.</b>
242 * This call is not polymorphic and calls
243 * Advertiement.getAdvertisementType() no matter what the real type of the
246 * @return String the type of advertisement
248 public static String getAdvertisementType() {
252 private RelayConfigAdv() {}
254 private RelayConfigAdv(Element root) {
255 if (!XMLElement.class.isInstance(root)) {
256 throw new IllegalArgumentException(getClass().getName() + " only supports XLMElement");
259 XMLElement doc = (XMLElement) root;
261 String doctype = doc.getName();
263 String typedoctype = "";
264 Attribute itsType = doc.getAttribute("type");
266 if (null != itsType) {
267 typedoctype = itsType.getValue();
270 if (!doctype.equals(getAdvertisementType()) && !getAdvertisementType().equals(typedoctype)) {
271 throw new IllegalArgumentException(
272 "Could not construct : " + getClass().getName() + "from doc containing a " + doc.getName());
275 Enumeration eachAttr = doc.getAttributes();
277 while (eachAttr.hasMoreElements()) {
278 Attribute aRelayAttr = (Attribute) eachAttr.nextElement();
280 if (super.handleAttribute(aRelayAttr)) {
283 } else if (RELAY_CLIENT_ATTR.equals(aRelayAttr.getName())) {
284 clientEnabled = Boolean.valueOf(aRelayAttr.getValue().trim());
285 } else if (RELAY_SERVER_ATTR.equals(aRelayAttr.getName())) {
286 serverEnabled = Boolean.valueOf(aRelayAttr.getValue().trim());
288 if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {
289 LOG.warning("Unhandled Attribute: " + aRelayAttr.getName());
294 Enumeration elements = doc.getChildren();
296 while (elements.hasMoreElements()) {
297 XMLElement elem = (XMLElement) elements.nextElement();
299 if (!handleElement(elem)) {
300 if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {
301 LOG.warning("Unhandled Element: " + elem.toString());
307 if ((-1 != maxRelays) && (maxRelays <= 0)) {
308 throw new IllegalArgumentException("Max relays must not be negative or zero.");
311 if ((-1 != maxClientLeaseDuration) && (maxClientLeaseDuration <= 0)) {
312 throw new IllegalArgumentException("Max lease duration must not be negative or zero.");
315 if ((-1 != messengerPollInterval) && (messengerPollInterval <= 0)) {
316 throw new IllegalArgumentException("Messenger poll interval must not be negative or zero.");
319 if (useOnlySeeds && clientEnabled && seedRelays.isEmpty() && seedingURIs.isEmpty()) {
320 throw new IllegalArgumentException("Cannot specify 'useOnlySeeds' and no seed relays");
323 if ((-1 != maxClients) && (maxClients <= 0)) {
324 throw new IllegalArgumentException("Max clients must not be negative or zero.");
327 if ((-1 != maxClientMessageQueue) && (maxClientMessageQueue <= 0)) {
328 throw new IllegalArgumentException("Max client queue must not be negative or zero.");
331 if ((-1 != maxServerLeaseDuration) && (maxServerLeaseDuration <= 0)) {
332 throw new IllegalArgumentException("Max lease duration must not be negative or zero.");
335 if ((-1 != stallTimeout) && (stallTimeout <= 0)) {
336 throw new IllegalArgumentException("Client stall timeout duration must not be negative or zero.");
339 if ((-1 != announceInterval) && (announceInterval <= 0)) {
340 throw new IllegalArgumentException("Announce interval must not be negative or zero.");
348 public RelayConfigAdv clone() {
350 RelayConfigAdv result;
353 result = (RelayConfigAdv) super.clone();
354 } catch (CloneNotSupportedException impossible) {
355 throw new Error("Object.clone() threw CloneNotSupportedException", impossible);
358 result.setAnnounceInterval(getAnnounceInterval());
359 result.setClientEnabled(isClientEnabled());
360 result.setClientLeaseDuration(getClientLeaseDuration());
361 result.setClientMessageQueueSize(getClientMessageQueueSize());
362 result.setMaxClients(getMaxClients());
363 result.setMaxRelays(getMaxRelays());
364 result.setMessengerPollInterval(getMessengerPollInterval());
365 result.setServerEnabled(isServerEnabled());
366 result.setServerLeaseDuration(getServerLeaseDuration());
367 result.setStallTimeout(getStallTimeout());
368 result.setUseOnlySeeds(getUseOnlySeeds());
377 public String getAdvType() {
378 return getAdvertisementType();
385 public final String getBaseAdvType() {
386 return getAdvertisementType();
401 protected boolean handleElement(Element raw) {
403 if (super.handleElement(raw)) {
407 XMLElement elem = (XMLElement) raw;
409 if (RELAY_CLIENT_ELEMENT.equals(elem.getName())) {
410 Enumeration eachAttr = elem.getAttributes();
412 while (eachAttr.hasMoreElements()) {
413 Attribute aRelayAttr = (Attribute) eachAttr.nextElement();
415 if (RELAY_CLIENT_SERVERS_ATTR.equals(aRelayAttr.getName())) {
416 maxRelays = Integer.parseInt(aRelayAttr.getValue().trim());
417 } else if (RELAY_CLIENT_LEASE_ATTR.equals(aRelayAttr.getName())) {
418 maxClientLeaseDuration = Long.parseLong(aRelayAttr.getValue().trim());
419 } else if (RELAY_CLIENT_POLL_ATTR.equals(aRelayAttr.getName())) {
420 messengerPollInterval = Long.parseLong(aRelayAttr.getValue().trim());
422 if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {
423 LOG.warning("Unhandled Attribute: " + aRelayAttr.getName());
428 Enumeration elements = elem.getChildren();
430 while (elements.hasMoreElements()) {
431 XMLElement seedsElem = (XMLElement) elements.nextElement();
433 if (RELAY_CLIENT_SEEDS_ELEMENT.equals(seedsElem.getName())) {
434 Enumeration eachSeedsAttr = seedsElem.getAttributes();
436 while (eachSeedsAttr.hasMoreElements()) {
437 Attribute aRelayAttr = (Attribute) eachSeedsAttr.nextElement();
439 if (USE_ONLY_SEEDS_ATTR.equals(aRelayAttr.getName())) {
440 useOnlySeeds = Boolean.valueOf(aRelayAttr.getValue().trim());
442 if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {
443 LOG.warning("Unhandled Attribute: " + aRelayAttr.getName());
448 Enumeration addrElements = seedsElem.getChildren();
450 while (addrElements.hasMoreElements()) {
451 XMLElement addrElem = (XMLElement) addrElements.nextElement();
453 if (SEED_RELAY_ADDR_ELEMENT.equals(addrElem.getName())) {
454 String endpAddrString = addrElem.getTextValue();
456 if (null != endpAddrString) {
457 URI endpURI = URI.create(endpAddrString.trim());
459 Attribute seedingAttr = addrElem.getAttribute(SEED_RELAY_ADDR_SEEDING_ATTR);
461 if ((null != seedingAttr) && Boolean.valueOf(seedingAttr.getValue().trim())) {
462 seedingURIs.add(endpURI);
464 seedRelays.add(new EndpointAddress(endpURI));
468 if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {
469 LOG.warning("Unhandled Element: " + elem.toString());
474 if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {
475 LOG.warning("Unhandled Element: " + elem.toString());
481 } else if (RELAY_SERVER_ELEMENT.equals(elem.getName())) {
482 Enumeration eachAttr = elem.getAttributes();
484 while (eachAttr.hasMoreElements()) {
485 Attribute aRelayAttr = (Attribute) eachAttr.nextElement();
487 if (RELAY_SERVER_CLIENTS_ATTR.equals(aRelayAttr.getName())) {
488 maxClients = Integer.parseInt(aRelayAttr.getValue().trim());
489 } else if (RELAY_SERVER_QUEUE_ATTR.equals(aRelayAttr.getName())) {
490 maxClientMessageQueue = Integer.parseInt(aRelayAttr.getValue().trim());
491 } else if (RELAY_SERVER_LEASE_ATTR.equals(aRelayAttr.getName())) {
492 maxServerLeaseDuration = Long.parseLong(aRelayAttr.getValue().trim());
493 } else if (RELAY_SERVER_STALL_ATTR.equals(aRelayAttr.getName())) {
494 stallTimeout = Long.parseLong(aRelayAttr.getValue().trim());
495 } else if (RELAY_SERVER_ANNOUNCE_ATTR.equals(aRelayAttr.getName())) {
496 announceInterval = Long.parseLong(aRelayAttr.getValue().trim());
498 if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {
499 LOG.warning("Unhandled Attribute: " + aRelayAttr.getName());
505 } else if (ACL_URI.equals(elem.getName())) {
506 String addrElement = elem.getTextValue();
508 if (null != addrElement) {
509 aclURI = URI.create(addrElement.trim());
522 public Document getDocument(MimeMediaType encodeAs) {
523 StructuredDocument adv = (StructuredDocument) super.getDocument(encodeAs);
525 if (!(adv instanceof Attributable)) {
526 throw new IllegalStateException("Only Attributable documents are supported.");
529 if ((-1 != maxRelays) && (maxRelays <= 0)) {
530 throw new IllegalStateException("Max relays must not be negative or zero.");
533 if ((-1 != maxClientLeaseDuration) && (maxClientLeaseDuration <= 0)) {
534 throw new IllegalStateException("Max lease duration must not be negative or zero.");
537 if ((-1 != messengerPollInterval) && (messengerPollInterval <= 0)) {
538 throw new IllegalStateException("Messenger poll interval must not be negative or zero.");
541 if (useOnlySeeds && clientEnabled && seedRelays.isEmpty() && seedingURIs.isEmpty()) {
542 throw new IllegalStateException("Cannot specify 'useOnlySeeds' and no seed relays");
545 if ((-1 != maxClients) && (maxClients <= 0)) {
546 throw new IllegalStateException("Max clients must not be negative or zero.");
549 if ((-1 != maxClientMessageQueue) && (maxClientMessageQueue <= 0)) {
550 throw new IllegalStateException("Max client queue must not be negative or zero.");
553 if ((-1 != maxServerLeaseDuration) && (maxServerLeaseDuration <= 0)) {
554 throw new IllegalStateException("Max lease duration must not be negative or zero.");
557 if ((-1 != stallTimeout) && (stallTimeout <= 0)) {
558 throw new IllegalStateException("Client stall timeout duration must not be negative or zero.");
561 if ((-1 != announceInterval) && (announceInterval <= 0)) {
562 throw new IllegalStateException("Announce interval must not be negative or zero.");
565 Attributable attrDoc = (Attributable) adv;
568 attrDoc.addAttribute(RELAY_CLIENT_ATTR, Boolean.TRUE.toString());
572 attrDoc.addAttribute(RELAY_SERVER_ATTR, Boolean.TRUE.toString());
575 Element clientElem = adv.createElement(RELAY_CLIENT_ELEMENT);
577 adv.appendChild(clientElem);
579 Attributable attrElem = (Attributable) clientElem;
581 if (-1 != maxRelays) {
582 attrElem.addAttribute(RELAY_CLIENT_SERVERS_ATTR, Integer.toString(maxRelays));
585 if (-1 != maxClientLeaseDuration) {
586 attrElem.addAttribute(RELAY_CLIENT_LEASE_ATTR, Long.toString(maxClientLeaseDuration));
589 if (-1 != messengerPollInterval) {
590 attrElem.addAttribute(RELAY_CLIENT_POLL_ATTR, Long.toString(messengerPollInterval));
593 if (!seedRelays.isEmpty() || !seedingURIs.isEmpty()) {
594 Element seedsElem = adv.createElement(RELAY_CLIENT_SEEDS_ELEMENT);
596 clientElem.appendChild(seedsElem);
598 attrElem = (Attributable) seedsElem;
601 attrElem.addAttribute(USE_ONLY_SEEDS_ATTR, Boolean.TRUE.toString());
604 for (EndpointAddress seedRelay : seedRelays) {
605 Element addrElement = adv.createElement(SEED_RELAY_ADDR_ELEMENT, seedRelay.toString());
607 seedsElem.appendChild(addrElement);
610 for (URI seedingURI : seedingURIs) {
611 Element addrElement = adv.createElement(SEED_RELAY_ADDR_ELEMENT, seedingURI.toString());
613 seedsElem.appendChild(addrElement);
615 ((Attributable) addrElement).addAttribute(SEED_RELAY_ADDR_SEEDING_ATTR, Boolean.TRUE.toString());
619 Element serverElem = adv.createElement(RELAY_SERVER_ELEMENT);
621 adv.appendChild(serverElem);
623 attrElem = (Attributable) serverElem;
625 if (-1 != maxClients) {
626 attrElem.addAttribute(RELAY_SERVER_CLIENTS_ATTR, Integer.toString(maxClients));
629 if (-1 != maxClientMessageQueue) {
630 attrElem.addAttribute(RELAY_SERVER_QUEUE_ATTR, Integer.toString(maxClientMessageQueue));
633 if (-1 != maxServerLeaseDuration) {
634 attrElem.addAttribute(RELAY_SERVER_LEASE_ATTR, Long.toString(maxServerLeaseDuration));
637 if (-1 != stallTimeout) {
638 attrElem.addAttribute(RELAY_SERVER_STALL_ATTR, Long.toString(stallTimeout));
641 if (-1 != announceInterval) {
642 attrElem.addAttribute(RELAY_SERVER_ANNOUNCE_ATTR, Long.toString(announceInterval));
644 if (aclURI != null) {
645 Element acl = adv.createElement(ACL_URI, aclURI.toString());
647 adv.appendChild(acl);
656 public String[] getIndexFields() {
661 * If true then this peer will act as a relay client.
663 * @return If true then this peer will act as a relay client.
665 public boolean isClientEnabled() {
666 return clientEnabled;
670 * If true then this peer will act as a relay client.
672 * @param enabled If true then this peer will act as a relay client.
674 public void setClientEnabled(boolean enabled) {
675 clientEnabled = enabled;
679 * Return the maximum number of relay clients.
681 * @return The maximum number of relay clients or <code>-1</code> for
684 public int getMaxRelays() {
689 * Sets the maximum number of relay clients.
691 * @param newvalue The maximum number of relay clients or <code>-1</code>
692 * for default value or <code>-1</code> for default value.
694 public void setMaxRelays(int newvalue) {
695 if ((-1 != newvalue) && (newvalue <= 0)) {
696 throw new IllegalArgumentException("Max Relays must be > 0");
699 maxRelays = newvalue;
703 * The interval in relative milliseconds of leases accepted by clients.
705 * @return The interval in relative milliseconds of leases accepted by
706 * clients or <code>-1</code> for default value.
708 public long getClientLeaseDuration() {
709 return maxClientLeaseDuration;
713 * Sets interval in relative milliseconds of leases accepted by clients.
715 * @param newvalue The interval in relative milliseconds of leases accepted
716 * by clients or <code>-1</code> for default value.
718 public void setClientLeaseDuration(long newvalue) {
719 if ((-1 != newvalue) && (newvalue <= 0)) {
720 throw new IllegalArgumentException("Lease Duration must be > 0");
723 maxClientLeaseDuration = newvalue;
727 * The interval in relative milliseconds of at which clients will poll for
730 * @return The interval in relative milliseconds of at which clients will
731 * poll for messengers or <code>-1</code> for default value.
733 public long getMessengerPollInterval() {
734 return messengerPollInterval;
738 * Sets interval in relative milliseconds of at which clients will poll for
741 * @param newvalue The interval in relative milliseconds of at which clients
742 * will poll for messengers or <code>-1</code> for default value.
744 public void setMessengerPollInterval(long newvalue) {
745 if ((-1 != newvalue) && (newvalue <= 0)) {
746 throw new IllegalArgumentException("Poll interval must be > 0");
749 messengerPollInterval = newvalue;
753 * If true then this peer will use only seed rendezvous when configured as
756 * @return If true then this peer will use only seed rendezvous when configured as
759 public boolean getUseOnlySeeds() {
764 * Set whether this peer will use only seed rendezvous when configured as
767 * @param onlySeeds If true then this peer will use only seed rendezvous when configured as
770 public void setUseOnlySeeds(boolean onlySeeds) {
771 useOnlySeeds = onlySeeds;
774 public EndpointAddress[] getSeedRelays() {
775 return seedRelays.toArray(new EndpointAddress[seedRelays.size()]);
778 public void addSeedRelay(EndpointAddress addr) {
780 throw new IllegalArgumentException("addr may not be null");
783 seedRelays.add(addr);
786 public void addSeedRelay(String addr) {
788 throw new IllegalArgumentException("addr may not be null");
791 seedRelays.add(new EndpointAddress(addr));
794 public boolean removeSeedRelay(EndpointAddress addr) {
796 throw new IllegalArgumentException("addr may not be null");
799 return seedRelays.remove(addr);
802 public void clearSeedRelays() {
806 public URI[] getSeedingURIs() {
807 return seedingURIs.toArray(new URI[seedingURIs.size()]);
810 public void addSeedingURI(URI addr) {
812 throw new IllegalArgumentException("addr may not be null");
815 seedingURIs.add(addr);
818 public void addSeedingURI(String addr) {
820 throw new IllegalArgumentException("addr may not be null");
823 seedingURIs.add(URI.create(addr));
826 public boolean removeSeedingURI(URI addr) {
828 throw new IllegalArgumentException("addr may not be null");
831 return seedingURIs.remove(addr);
834 public void clearSeedingURIs() {
839 * If true then this peer will act as a relay server.
841 * @return If true then this peer will act as a relay server.
843 public boolean isServerEnabled() {
844 return serverEnabled;
848 * If true then this peer will act as a relay server.
850 * @param enabled If true then this peer will act as a relay server.
852 public void setServerEnabled(boolean enabled) {
853 serverEnabled = enabled;
857 * Return the maximum number of relay clients.
859 * @return The maximum number of relay clients or <code>-1</code> for
862 public int getMaxClients() {
867 * Sets he maximum number of relay clients.
869 * @param newvalue The maximum number of relay clients or <code>-1</code>
872 public void setMaxClients(int newvalue) {
873 if ((-1 != newvalue) && (newvalue <= 0)) {
874 throw new IllegalArgumentException("Max Clients must be > 0");
877 maxClients = newvalue;
881 * Return the client message queue length size.
883 * @return The client message queue length size or <code>-1</code> for default value.
885 public int getClientMessageQueueSize() {
886 return maxClientMessageQueue;
890 * Sets the client message queue length size.
892 * @param newvalue The client message queue length size or <code>-1</code>
895 public void setClientMessageQueueSize(int newvalue) {
896 if ((-1 != newvalue) && (newvalue <= 0)) {
897 throw new IllegalArgumentException("Client Message Queue Size must be > 0");
900 maxClientMessageQueue = newvalue;
904 * The interval in relative milliseconds of leases offered by servers.
906 * @return The interval in relative milliseconds of leases offered by servers.
908 public long getServerLeaseDuration() {
909 return maxServerLeaseDuration;
913 * Sets interval in relative milliseconds of leases offered by servers.
915 * @param newvalue The interval in relative milliseconds of leases offered
916 * by servers or <code>-1</code> for default value.
918 public void setServerLeaseDuration(long newvalue) {
919 if ((-1 != newvalue) && (newvalue <= 0)) {
920 throw new IllegalArgumentException("Lease Duration must be >= 0");
923 maxServerLeaseDuration = newvalue;
927 * The interval in relative milliseconds after which a client is assumed to
928 * no longer be connected if it fails to request messages.
930 * @return The interval in relative milliseconds after which a client is
931 * assumed to no longer be connected if it fails to request messages or
932 * <code>-1</code> for default value.
934 public long getStallTimeout() {
939 * Sets interval in relative milliseconds after which a client is assumed to
940 * no longer be connected if it fails to request messages.
942 * @param newvalue The interval in relative milliseconds after which a
943 * client is assumed to no longer be connected if it fails to request
944 * messages or <code>-1</code> for default value.
946 public void setStallTimeout(long newvalue) {
947 if ((-1 != newvalue) && (newvalue <= 0)) {
948 throw new IllegalArgumentException("Stall timeout must be > 0");
951 stallTimeout = newvalue;
955 * The interval in relative milliseconds at which relay server will
956 * announce its presence.
958 * @return The interval in relative milliseconds at which relay server will
959 * broadcast its presence or <code>-1</code> for default value.
961 public long getAnnounceInterval() {
962 return announceInterval;
966 * Sets interval in relative milliseconds at which relay server will
967 * announce its presence or <code>-1</code> for default value.
969 * @param newvalue The interval in relative milliseconds at which relay server will
970 * announce its presence.
972 public void setAnnounceInterval(long newvalue) {
973 if ((-1 != newvalue) && (newvalue <= 0)) {
974 throw new IllegalArgumentException("Announce Interval must be > 0");
977 announceInterval = newvalue;
981 * Return ACL URI if set
983 * @return ACL URI if set, null otherwise
985 public URI getAclUri() {
992 * @param uri URI if set, null otherwise
994 public void setAclUri(URI uri) {