summaryrefslogtreecommitdiff
path: root/src/javax/jmdns/JmmDNS.java
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@google.com>2012-03-21 12:26:23 -0700
committerMike Lockwood <lockwood@google.com>2012-03-21 12:26:23 -0700
commitf4eb7466d5c09098f9dc54137ed3235e3c43fc9f (patch)
tree56e1bf5e433e60e3a18d5a9d08b7d55a64d8ae1d /src/javax/jmdns/JmmDNS.java
parent19376825c9e562c188aef9ccd09a7220bd3c0a20 (diff)
parent76f0067cea0428b683cba2f187d81e723658f964 (diff)
downloadjmdns-android-cts-5.1_r7.tar.gz
Merge remote-tracking branch 'goog/ics-aah-exp'android-wear-n-preview-3android-wear-n-preview-2android-wear-n-preview-1android-wear-7.1.1_r1android-wear-5.1.1_r1android-wear-5.1.0_r1android-wear-5.0.0_r1android-sdk-support_r11android-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1android-n-preview-5android-n-preview-4android-n-preview-3android-n-preview-2android-n-preview-1android-n-iot-preview-2android-m-preview-2android-m-preview-1android-m-previewandroid-l-preview_r2android-cts-6.0_r9android-cts-6.0_r8android-cts-6.0_r7android-cts-6.0_r6android-cts-6.0_r5android-cts-6.0_r4android-cts-6.0_r32android-cts-6.0_r31android-cts-6.0_r30android-cts-6.0_r3android-cts-6.0_r29android-cts-6.0_r28android-cts-6.0_r27android-cts-6.0_r26android-cts-6.0_r25android-cts-6.0_r24android-cts-6.0_r23android-cts-6.0_r22android-cts-6.0_r21android-cts-6.0_r20android-cts-6.0_r2android-cts-6.0_r19android-cts-6.0_r18android-cts-6.0_r17android-cts-6.0_r16android-cts-6.0_r15android-cts-6.0_r14android-cts-6.0_r13android-cts-6.0_r12android-cts-6.0_r1android-cts-5.1_r9android-cts-5.1_r8android-cts-5.1_r7android-cts-5.1_r6android-cts-5.1_r5android-cts-5.1_r4android-cts-5.1_r3android-cts-5.1_r28android-cts-5.1_r27android-cts-5.1_r26android-cts-5.1_r25android-cts-5.1_r24android-cts-5.1_r23android-cts-5.1_r22android-cts-5.1_r21android-cts-5.1_r20android-cts-5.1_r2android-cts-5.1_r19android-cts-5.1_r18android-cts-5.1_r17android-cts-5.1_r16android-cts-5.1_r15android-cts-5.1_r14android-cts-5.1_r13android-cts-5.1_r10android-cts-5.1_r1android-cts-5.0_r9android-cts-5.0_r8android-cts-5.0_r7android-cts-5.0_r6android-cts-5.0_r5android-cts-5.0_r4android-cts-5.0_r3android-cts-4.4_r4android-cts-4.4_r1android-cts-4.2_r2android-cts-4.2_r1android-cts-4.1_r4android-cts-4.1_r2android-cts-4.1_r1android-6.0.1_r9android-6.0.1_r81android-6.0.1_r80android-6.0.1_r8android-6.0.1_r79android-6.0.1_r78android-6.0.1_r77android-6.0.1_r74android-6.0.1_r73android-6.0.1_r72android-6.0.1_r70android-6.0.1_r7android-6.0.1_r69android-6.0.1_r68android-6.0.1_r67android-6.0.1_r66android-6.0.1_r65android-6.0.1_r63android-6.0.1_r62android-6.0.1_r61android-6.0.1_r60android-6.0.1_r59android-6.0.1_r58android-6.0.1_r57android-6.0.1_r56android-6.0.1_r55android-6.0.1_r54android-6.0.1_r53android-6.0.1_r52android-6.0.1_r51android-6.0.1_r50android-6.0.1_r5android-6.0.1_r49android-6.0.1_r48android-6.0.1_r47android-6.0.1_r46android-6.0.1_r45android-6.0.1_r43android-6.0.1_r42android-6.0.1_r41android-6.0.1_r40android-6.0.1_r4android-6.0.1_r33android-6.0.1_r32android-6.0.1_r31android-6.0.1_r30android-6.0.1_r3android-6.0.1_r28android-6.0.1_r27android-6.0.1_r26android-6.0.1_r25android-6.0.1_r24android-6.0.1_r22android-6.0.1_r21android-6.0.1_r20android-6.0.1_r18android-6.0.1_r17android-6.0.1_r16android-6.0.1_r13android-6.0.1_r12android-6.0.1_r11android-6.0.1_r10android-6.0.1_r1android-6.0.0_r7android-6.0.0_r6android-6.0.0_r5android-6.0.0_r41android-6.0.0_r4android-6.0.0_r3android-6.0.0_r26android-6.0.0_r25android-6.0.0_r24android-6.0.0_r23android-6.0.0_r2android-6.0.0_r13android-6.0.0_r12android-6.0.0_r11android-6.0.0_r1android-5.1.1_r9android-5.1.1_r8android-5.1.1_r7android-5.1.1_r6android-5.1.1_r5android-5.1.1_r4android-5.1.1_r38android-5.1.1_r37android-5.1.1_r36android-5.1.1_r35android-5.1.1_r34android-5.1.1_r33android-5.1.1_r30android-5.1.1_r3android-5.1.1_r29android-5.1.1_r28android-5.1.1_r26android-5.1.1_r25android-5.1.1_r24android-5.1.1_r23android-5.1.1_r22android-5.1.1_r20android-5.1.1_r2android-5.1.1_r19android-5.1.1_r18android-5.1.1_r17android-5.1.1_r16android-5.1.1_r15android-5.1.1_r14android-5.1.1_r13android-5.1.1_r12android-5.1.1_r10android-5.1.1_r1android-5.1.0_r5android-5.1.0_r4android-5.1.0_r3android-5.1.0_r1android-5.0.2_r3android-5.0.2_r1android-5.0.1_r1android-5.0.0_r7android-5.0.0_r6android-5.0.0_r5.1android-5.0.0_r5android-5.0.0_r4android-5.0.0_r3android-5.0.0_r2android-5.0.0_r1android-4.4w_r1android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.4_r0.7android-4.4.4_r2.0.1android-4.4.4_r2android-4.4.4_r1.0.1android-4.4.4_r1android-4.4.3_r1.1.0.1android-4.4.3_r1.1android-4.4.3_r1.0.1android-4.4.3_r1android-4.4.2_r2.0.1android-4.4.2_r2android-4.4.2_r1.0.1android-4.4.2_r1android-4.4.1_r1.0.1android-4.4.1_r1android-4.3_r3.1android-4.3_r3android-4.3_r2.3android-4.3_r2.2android-4.3_r2.1android-4.3_r2android-4.3_r1.1android-4.3_r1android-4.3_r0.9.1android-4.3_r0.9android-4.3.1_r1android-4.2_r1android-4.2.2_r1.2android-4.2.2_r1.1android-4.2.2_r1android-4.2.1_r1.2android-4.2.1_r1.1android-4.2.1_r1android-4.1.2_r2.1android-4.1.2_r2android-4.1.2_r1android-4.1.1_r6.1android-4.1.1_r6android-4.1.1_r5android-4.1.1_r4android-4.1.1_r3android-4.1.1_r2android-4.1.1_r1.1android-4.1.1_r1tools_r22.2tools_r22tools_r21nougat-mr1-wear-releasen-iot-preview-2master-soongmarshmallow-releasemarshmallow-mr3-releasemarshmallow-mr2-releasemarshmallow-mr1-releasemarshmallow-mr1-devmarshmallow-dr1.6-releasemarshmallow-dr1.5-releasemarshmallow-dr1.5-devmarshmallow-dr-releasemarshmallow-dr-dragon-releasemarshmallow-dr-devmarshmallow-devmarshmallow-cts-releaselollipop-wear-releaselollipop-releaselollipop-mr1-wfc-releaselollipop-mr1-releaselollipop-mr1-fi-releaselollipop-mr1-devlollipop-mr1-cts-releaselollipop-devlollipop-cts-releasel-previewkitkat-wearkitkat-releasekitkat-mr2.2-releasekitkat-mr2.1-releasekitkat-mr2-releasekitkat-mr1.1-releasekitkat-mr1-releasekitkat-devkitkat-cts-releasekitkat-cts-devjb-releasejb-mr2.0.0-releasejb-mr2.0-releasejb-mr2-releasejb-mr2-devjb-mr1.1-releasejb-mr1.1-dev-plus-aospjb-mr1.1-devjb-mr1-releasejb-mr1-dev-plus-aospjb-mr1-devjb-mr0-releasejb-devidea133-weekly-releaseidea133
Diffstat (limited to 'src/javax/jmdns/JmmDNS.java')
-rw-r--r--src/javax/jmdns/JmmDNS.java407
1 files changed, 407 insertions, 0 deletions
diff --git a/src/javax/jmdns/JmmDNS.java b/src/javax/jmdns/JmmDNS.java
new file mode 100644
index 0000000..1d4d85a
--- /dev/null
+++ b/src/javax/jmdns/JmmDNS.java
@@ -0,0 +1,407 @@
+/**
+ *
+ */
+package javax.jmdns;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.jmdns.impl.JmmDNSImpl;
+
+/**
+ * <p>
+ * Java Multihomed Multicast DNS
+ * </p>
+ * Uses an underlying {@link JmDNS} instance for each {@link InetAddress} found on this computer.<br/>
+ * This class will monitor network topology changes, and will create or destroy JmDNS instances as required. It is your responsibility to maintain services registration (hint: use a {@link NetworkTopologyListener}).<br/>
+ * Most of this class methods have no notion of transaction: if an Exception is raised in the middle of execution, you may be in an incoherent state.
+ * <p>
+ * <b>Note:</b> This API is experimental and may change in the future please let us know what work and what does not work in you application.
+ * </p>
+ *
+ * @author C&eacute;drik Lime, Pierre Frisch
+ */
+public interface JmmDNS extends Closeable {
+
+ /**
+ * JmmDNS.Factory enable the creation of new instance of JmmDNS.
+ */
+ public static final class Factory {
+ private static volatile JmmDNS _instance;
+
+ /**
+ * This interface defines a delegate to the EOClassDescriptionRegister class to enable subclassing.
+ */
+ public static interface ClassDelegate {
+
+ /**
+ * Allows the delegate the opportunity to construct and return a different JmmDNS.
+ *
+ * @return Should return a new JmmDNS.
+ * @see #classDelegate()
+ * @see #setClassDelegate(ClassDelegate anObject)
+ */
+ public JmmDNS newJmmDNS();
+
+ }
+
+ private static final AtomicReference<ClassDelegate> _databaseClassDelegate = new AtomicReference<ClassDelegate>();
+
+ private Factory() {
+ super();
+ }
+
+ /**
+ * Assigns <code>delegate</code> as JmmDNS's class delegate. The class delegate is optional.
+ *
+ * @param delegate
+ * The object to set as JmmDNS's class delegate.
+ * @see #classDelegate()
+ * @see JmmDNS.Factory.ClassDelegate
+ */
+ public static void setClassDelegate(ClassDelegate delegate) {
+ _databaseClassDelegate.set(delegate);
+ }
+
+ /**
+ * Returns JmmDNS's class delegate.
+ *
+ * @return JmmDNS's class delegate.
+ * @see #setClassDelegate(ClassDelegate anObject)
+ * @see JmmDNS.Factory.ClassDelegate
+ */
+ public static ClassDelegate classDelegate() {
+ return _databaseClassDelegate.get();
+ }
+
+ /**
+ * Returns a new instance of JmmDNS using the class delegate if it exists.
+ *
+ * @return new instance of JmmDNS
+ */
+ protected static JmmDNS newJmmDNS() {
+ JmmDNS dns = null;
+ ClassDelegate delegate = _databaseClassDelegate.get();
+ if (delegate != null) {
+ dns = delegate.newJmmDNS();
+ }
+ return (dns != null ? dns : new JmmDNSImpl());
+ }
+
+ /**
+ * Return the instance of the Multihommed Multicast DNS.
+ *
+ * @return the JmmDNS
+ */
+ public static JmmDNS getInstance() {
+ if (_instance == null) {
+ synchronized (Factory.class) {
+ if (_instance == null) {
+ _instance = JmmDNS.Factory.newJmmDNS();
+ }
+ }
+ }
+ return _instance;
+ }
+ }
+
+ /**
+ * Return the names of the JmDNS instances.
+ *
+ * @return list of name of the JmDNS
+ * @see javax.jmdns.JmDNS#getName()
+ */
+ public abstract String[] getNames();
+
+ /**
+ * Return the list HostName associated with this JmmDNS instance.
+ *
+ * @return list of host names
+ * @see javax.jmdns.JmDNS#getHostName()
+ */
+ public abstract String[] getHostNames();
+
+ /**
+ * Return the list of addresses of the interface to which this instance of JmmDNS is bound.
+ *
+ * @return list of Internet Address
+ * @exception IOException
+ * @see javax.jmdns.JmDNS#getInetAddress()
+ */
+ public abstract InetAddress[] getInetAddresses() throws IOException;
+
+ /**
+ * Return the list of addresses of the interface to which this instance of JmmDNS is bound.
+ *
+ * @return list of Internet Address
+ * @exception IOException
+ * @see javax.jmdns.JmDNS#getInterface()
+ * @deprecated do not use this implementation yields unpredictable results use {@link #getInetAddresses()}
+ */
+ @Deprecated
+ public abstract InetAddress[] getInterfaces() throws IOException;
+
+ /**
+ * Get service information. If the information is not cached, the method will block until updated information is received on all DNS.
+ * <p/>
+ * Usage note: Do not call this method from the AWT event dispatcher thread. You will make the user interface unresponsive.
+ *
+ * @param type
+ * fully qualified service type, such as <code>_http._tcp.local.</code> .
+ * @param name
+ * unqualified service name, such as <code>foobar</code> .
+ * @return list of service info. If no service info is found the list is empty.
+ * @see javax.jmdns.JmDNS#getServiceInfo(java.lang.String, java.lang.String)
+ */
+ public abstract ServiceInfo[] getServiceInfos(String type, String name);
+
+ /**
+ * Get service information. If the information is not cached, the method will block until updated information is received on all DNS.
+ * <p/>
+ * Usage note: If you call this method from the AWT event dispatcher thread, use a small timeout, or you will make the user interface unresponsive.
+ *
+ * @param type
+ * full qualified service type, such as <code>_http._tcp.local.</code> .
+ * @param name
+ * unqualified service name, such as <code>foobar</code> .
+ * @param timeout
+ * timeout in milliseconds. Typical timeout should be 5s.
+ * @return list of service info. If no service info is found the list is empty.
+ * @see javax.jmdns.JmDNS#getServiceInfo(java.lang.String, java.lang.String, long)
+ */
+ public abstract ServiceInfo[] getServiceInfos(String type, String name, long timeout);
+
+ /**
+ * Get service information. If the information is not cached, the method will block until updated information is received on all DNS.
+ * <p/>
+ * Usage note: If you call this method from the AWT event dispatcher thread, use a small timeout, or you will make the user interface unresponsive.
+ *
+ * @param type
+ * full qualified service type, such as <code>_http._tcp.local.</code> .
+ * @param name
+ * unqualified service name, such as <code>foobar</code> .
+ * @param persistent
+ * if <code>true</code> ServiceListener.resolveService will be called whenever new new information is received.
+ * @return list of service info. If no service info is found the list is empty.
+ * @see javax.jmdns.JmDNS#getServiceInfo(java.lang.String, java.lang.String, boolean)
+ */
+ public abstract ServiceInfo[] getServiceInfos(String type, String name, boolean persistent);
+
+ /**
+ * Get service information. If the information is not cached, the method will block until updated information is received on all DNS.
+ * <p/>
+ * Usage note: If you call this method from the AWT event dispatcher thread, use a small timeout, or you will make the user interface unresponsive.
+ *
+ * @param type
+ * full qualified service type, such as <code>_http._tcp.local.</code> .
+ * @param name
+ * unqualified service name, such as <code>foobar</code> .
+ * @param timeout
+ * timeout in milliseconds. Typical timeout should be 5s.
+ * @param persistent
+ * if <code>true</code> ServiceListener.resolveService will be called whenever new new information is received.
+ * @return list of service info. If no service info is found the list is empty.
+ * @see javax.jmdns.JmDNS#getServiceInfo(java.lang.String, java.lang.String, boolean, long)
+ */
+ public abstract ServiceInfo[] getServiceInfos(String type, String name, boolean persistent, long timeout);
+
+ /**
+ * Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.
+ *
+ * @param type
+ * full qualified service type, such as <code>_http._tcp.local.</code> .
+ * @param name
+ * unqualified service name, such as <code>foobar</code> .
+ * @see javax.jmdns.JmDNS#requestServiceInfo(java.lang.String, java.lang.String)
+ */
+ public abstract void requestServiceInfo(String type, String name);
+
+ /**
+ * Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.
+ *
+ * @param type
+ * full qualified service type, such as <code>_http._tcp.local.</code> .
+ * @param name
+ * unqualified service name, such as <code>foobar</code> .
+ * @param persistent
+ * if <code>true</code> ServiceListener.resolveService will be called whenever new new information is received.
+ * @see javax.jmdns.JmDNS#requestServiceInfo(java.lang.String, java.lang.String, boolean)
+ */
+ public abstract void requestServiceInfo(String type, String name, boolean persistent);
+
+ /**
+ * Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.
+ *
+ * @param type
+ * full qualified service type, such as <code>_http._tcp.local.</code> .
+ * @param name
+ * unqualified service name, such as <code>foobar</code> .
+ * @param timeout
+ * timeout in milliseconds
+ * @see javax.jmdns.JmDNS#requestServiceInfo(java.lang.String, java.lang.String, long)
+ */
+ public abstract void requestServiceInfo(String type, String name, long timeout);
+
+ /**
+ * Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.
+ *
+ * @param type
+ * full qualified service type, such as <code>_http._tcp.local.</code> .
+ * @param name
+ * unqualified service name, such as <code>foobar</code> .
+ * @param persistent
+ * if <code>true</code> ServiceListener.resolveService will be called whenever new new information is received.
+ * @param timeout
+ * timeout in milliseconds
+ * @see javax.jmdns.JmDNS#requestServiceInfo(java.lang.String, java.lang.String, boolean, long)
+ */
+ public abstract void requestServiceInfo(String type, String name, boolean persistent, long timeout);
+
+ /**
+ * Listen for service types.
+ *
+ * @param listener
+ * listener for service types
+ * @exception IOException
+ * @see javax.jmdns.JmDNS#addServiceTypeListener(javax.jmdns.ServiceTypeListener)
+ */
+ public abstract void addServiceTypeListener(ServiceTypeListener listener) throws IOException;
+
+ /**
+ * Remove listener for service types.
+ *
+ * @param listener
+ * listener for service types
+ * @see javax.jmdns.JmDNS#removeServiceTypeListener(javax.jmdns.ServiceTypeListener)
+ */
+ public abstract void removeServiceTypeListener(ServiceTypeListener listener);
+
+ /**
+ * Listen for services of a given type. The type has to be a fully qualified type name such as <code>_http._tcp.local.</code>.
+ *
+ * @param type
+ * full qualified service type, such as <code>_http._tcp.local.</code>.
+ * @param listener
+ * listener for service updates
+ * @see javax.jmdns.JmDNS#addServiceListener(java.lang.String, javax.jmdns.ServiceListener)
+ */
+ public abstract void addServiceListener(String type, ServiceListener listener);
+
+ /**
+ * Remove listener for services of a given type.
+ *
+ * @param type
+ * full qualified service type, such as <code>_http._tcp.local.</code>.
+ * @param listener
+ * listener for service updates
+ * @see javax.jmdns.JmDNS#removeServiceListener(java.lang.String, javax.jmdns.ServiceListener)
+ */
+ public abstract void removeServiceListener(String type, ServiceListener listener);
+
+ /**
+ * Register a service. The service is registered for access by other jmdns clients. The name of the service may be changed to make it unique.<br>
+ * <b>Note</b> the Service info is cloned for each network interface.
+ *
+ * @param info
+ * service info to register
+ * @exception IOException
+ * @see javax.jmdns.JmDNS#registerService(javax.jmdns.ServiceInfo)
+ */
+ public abstract void registerService(ServiceInfo info) throws IOException;
+
+ /**
+ * Unregister a service. The service should have been registered.
+ *
+ * @param info
+ * service info to remove
+ * @see javax.jmdns.JmDNS#unregisterService(javax.jmdns.ServiceInfo)
+ */
+ public abstract void unregisterService(ServiceInfo info);
+
+ /**
+ * Unregister all services.
+ *
+ * @see javax.jmdns.JmDNS#unregisterAllServices()
+ */
+ public abstract void unregisterAllServices();
+
+ /**
+ * Register a service type. If this service type was not already known, all service listeners will be notified of the new service type. Service types are automatically registered as they are discovered.
+ *
+ * @param type
+ * full qualified service type, such as <code>_http._tcp.local.</code>.
+ * @see javax.jmdns.JmDNS#registerServiceType(java.lang.String)
+ */
+ public abstract void registerServiceType(String type);
+
+ /**
+ * Returns a list of service infos of the specified type.
+ *
+ * @param type
+ * Service type name, such as <code>_http._tcp.local.</code>.
+ * @return An array of service instance.
+ * @see javax.jmdns.JmDNS#list(java.lang.String)
+ */
+ public abstract ServiceInfo[] list(String type);
+
+ /**
+ * Returns a list of service infos of the specified type.
+ *
+ * @param type
+ * Service type name, such as <code>_http._tcp.local.</code>.
+ * @param timeout
+ * timeout in milliseconds. Typical timeout should be 6s.
+ * @return An array of service instance.
+ * @see javax.jmdns.JmDNS#list(java.lang.String, long)
+ */
+ public abstract ServiceInfo[] list(String type, long timeout);
+
+ /**
+ * Returns a list of service infos of the specified type sorted by subtype. Any service that do not register a subtype is listed in the empty subtype section.
+ *
+ * @param type
+ * Service type name, such as <code>_http._tcp.local.</code>.
+ * @return A dictionary of service info by subtypes.
+ * @see javax.jmdns.JmDNS#listBySubtype(java.lang.String)
+ */
+ public abstract Map<String, ServiceInfo[]> listBySubtype(String type);
+
+ /**
+ * Returns a list of service infos of the specified type sorted by subtype. Any service that do not register a subtype is listed in the empty subtype section.
+ *
+ * @param type
+ * Service type name, such as <code>_http._tcp.local.</code>.
+ * @param timeout
+ * timeout in milliseconds. Typical timeout should be 6s.
+ * @return A dictionary of service info by subtypes.
+ * @see javax.jmdns.JmDNS#listBySubtype(java.lang.String, long)
+ */
+ public abstract Map<String, ServiceInfo[]> listBySubtype(String type, long timeout);
+
+ /**
+ * Listen to network changes.
+ *
+ * @param listener
+ * listener for network changes
+ */
+ public abstract void addNetworkTopologyListener(NetworkTopologyListener listener);
+
+ /**
+ * Remove listener for network changes.
+ *
+ * @param listener
+ * listener for network changes
+ */
+ public abstract void removeNetworkTopologyListener(NetworkTopologyListener listener);
+
+ /**
+ * Returns list of network change listeners
+ *
+ * @return list of network change listeners
+ */
+ public abstract NetworkTopologyListener[] networkListeners();
+
+}