/external/jmdns/src/javax/jmdns/JmmDNS.java

https://gitlab.com/brian0218/rk3066_r-box_android4.2.2_sdk · Java · 407 lines · 71 code · 41 blank · 295 comment · 7 complexity · 7f434acd568ee663292520f0589ae8e9 MD5 · raw file

  1. /**
  2. *
  3. */
  4. package javax.jmdns;
  5. import java.io.Closeable;
  6. import java.io.IOException;
  7. import java.net.InetAddress;
  8. import java.util.Map;
  9. import java.util.concurrent.atomic.AtomicReference;
  10. import javax.jmdns.impl.JmmDNSImpl;
  11. /**
  12. * <p>
  13. * Java Multihomed Multicast DNS
  14. * </p>
  15. * Uses an underlying {@link JmDNS} instance for each {@link InetAddress} found on this computer.<br/>
  16. * 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/>
  17. * 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.
  18. * <p>
  19. * <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.
  20. * </p>
  21. *
  22. * @author C&eacute;drik Lime, Pierre Frisch
  23. */
  24. public interface JmmDNS extends Closeable {
  25. /**
  26. * JmmDNS.Factory enable the creation of new instance of JmmDNS.
  27. */
  28. public static final class Factory {
  29. private static volatile JmmDNS _instance;
  30. /**
  31. * This interface defines a delegate to the EOClassDescriptionRegister class to enable subclassing.
  32. */
  33. public static interface ClassDelegate {
  34. /**
  35. * Allows the delegate the opportunity to construct and return a different JmmDNS.
  36. *
  37. * @return Should return a new JmmDNS.
  38. * @see #classDelegate()
  39. * @see #setClassDelegate(ClassDelegate anObject)
  40. */
  41. public JmmDNS newJmmDNS();
  42. }
  43. private static final AtomicReference<ClassDelegate> _databaseClassDelegate = new AtomicReference<ClassDelegate>();
  44. private Factory() {
  45. super();
  46. }
  47. /**
  48. * Assigns <code>delegate</code> as JmmDNS's class delegate. The class delegate is optional.
  49. *
  50. * @param delegate
  51. * The object to set as JmmDNS's class delegate.
  52. * @see #classDelegate()
  53. * @see JmmDNS.Factory.ClassDelegate
  54. */
  55. public static void setClassDelegate(ClassDelegate delegate) {
  56. _databaseClassDelegate.set(delegate);
  57. }
  58. /**
  59. * Returns JmmDNS's class delegate.
  60. *
  61. * @return JmmDNS's class delegate.
  62. * @see #setClassDelegate(ClassDelegate anObject)
  63. * @see JmmDNS.Factory.ClassDelegate
  64. */
  65. public static ClassDelegate classDelegate() {
  66. return _databaseClassDelegate.get();
  67. }
  68. /**
  69. * Returns a new instance of JmmDNS using the class delegate if it exists.
  70. *
  71. * @return new instance of JmmDNS
  72. */
  73. protected static JmmDNS newJmmDNS() {
  74. JmmDNS dns = null;
  75. ClassDelegate delegate = _databaseClassDelegate.get();
  76. if (delegate != null) {
  77. dns = delegate.newJmmDNS();
  78. }
  79. return (dns != null ? dns : new JmmDNSImpl());
  80. }
  81. /**
  82. * Return the instance of the Multihommed Multicast DNS.
  83. *
  84. * @return the JmmDNS
  85. */
  86. public static JmmDNS getInstance() {
  87. if (_instance == null) {
  88. synchronized (Factory.class) {
  89. if (_instance == null) {
  90. _instance = JmmDNS.Factory.newJmmDNS();
  91. }
  92. }
  93. }
  94. return _instance;
  95. }
  96. }
  97. /**
  98. * Return the names of the JmDNS instances.
  99. *
  100. * @return list of name of the JmDNS
  101. * @see javax.jmdns.JmDNS#getName()
  102. */
  103. public abstract String[] getNames();
  104. /**
  105. * Return the list HostName associated with this JmmDNS instance.
  106. *
  107. * @return list of host names
  108. * @see javax.jmdns.JmDNS#getHostName()
  109. */
  110. public abstract String[] getHostNames();
  111. /**
  112. * Return the list of addresses of the interface to which this instance of JmmDNS is bound.
  113. *
  114. * @return list of Internet Address
  115. * @exception IOException
  116. * @see javax.jmdns.JmDNS#getInetAddress()
  117. */
  118. public abstract InetAddress[] getInetAddresses() throws IOException;
  119. /**
  120. * Return the list of addresses of the interface to which this instance of JmmDNS is bound.
  121. *
  122. * @return list of Internet Address
  123. * @exception IOException
  124. * @see javax.jmdns.JmDNS#getInterface()
  125. * @deprecated do not use this implementation yields unpredictable results use {@link #getInetAddresses()}
  126. */
  127. @Deprecated
  128. public abstract InetAddress[] getInterfaces() throws IOException;
  129. /**
  130. * Get service information. If the information is not cached, the method will block until updated information is received on all DNS.
  131. * <p/>
  132. * Usage note: Do not call this method from the AWT event dispatcher thread. You will make the user interface unresponsive.
  133. *
  134. * @param type
  135. * fully qualified service type, such as <code>_http._tcp.local.</code> .
  136. * @param name
  137. * unqualified service name, such as <code>foobar</code> .
  138. * @return list of service info. If no service info is found the list is empty.
  139. * @see javax.jmdns.JmDNS#getServiceInfo(java.lang.String, java.lang.String)
  140. */
  141. public abstract ServiceInfo[] getServiceInfos(String type, String name);
  142. /**
  143. * Get service information. If the information is not cached, the method will block until updated information is received on all DNS.
  144. * <p/>
  145. * 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.
  146. *
  147. * @param type
  148. * full qualified service type, such as <code>_http._tcp.local.</code> .
  149. * @param name
  150. * unqualified service name, such as <code>foobar</code> .
  151. * @param timeout
  152. * timeout in milliseconds. Typical timeout should be 5s.
  153. * @return list of service info. If no service info is found the list is empty.
  154. * @see javax.jmdns.JmDNS#getServiceInfo(java.lang.String, java.lang.String, long)
  155. */
  156. public abstract ServiceInfo[] getServiceInfos(String type, String name, long timeout);
  157. /**
  158. * Get service information. If the information is not cached, the method will block until updated information is received on all DNS.
  159. * <p/>
  160. * 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.
  161. *
  162. * @param type
  163. * full qualified service type, such as <code>_http._tcp.local.</code> .
  164. * @param name
  165. * unqualified service name, such as <code>foobar</code> .
  166. * @param persistent
  167. * if <code>true</code> ServiceListener.resolveService will be called whenever new new information is received.
  168. * @return list of service info. If no service info is found the list is empty.
  169. * @see javax.jmdns.JmDNS#getServiceInfo(java.lang.String, java.lang.String, boolean)
  170. */
  171. public abstract ServiceInfo[] getServiceInfos(String type, String name, boolean persistent);
  172. /**
  173. * Get service information. If the information is not cached, the method will block until updated information is received on all DNS.
  174. * <p/>
  175. * 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.
  176. *
  177. * @param type
  178. * full qualified service type, such as <code>_http._tcp.local.</code> .
  179. * @param name
  180. * unqualified service name, such as <code>foobar</code> .
  181. * @param timeout
  182. * timeout in milliseconds. Typical timeout should be 5s.
  183. * @param persistent
  184. * if <code>true</code> ServiceListener.resolveService will be called whenever new new information is received.
  185. * @return list of service info. If no service info is found the list is empty.
  186. * @see javax.jmdns.JmDNS#getServiceInfo(java.lang.String, java.lang.String, boolean, long)
  187. */
  188. public abstract ServiceInfo[] getServiceInfos(String type, String name, boolean persistent, long timeout);
  189. /**
  190. * Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.
  191. *
  192. * @param type
  193. * full qualified service type, such as <code>_http._tcp.local.</code> .
  194. * @param name
  195. * unqualified service name, such as <code>foobar</code> .
  196. * @see javax.jmdns.JmDNS#requestServiceInfo(java.lang.String, java.lang.String)
  197. */
  198. public abstract void requestServiceInfo(String type, String name);
  199. /**
  200. * Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.
  201. *
  202. * @param type
  203. * full qualified service type, such as <code>_http._tcp.local.</code> .
  204. * @param name
  205. * unqualified service name, such as <code>foobar</code> .
  206. * @param persistent
  207. * if <code>true</code> ServiceListener.resolveService will be called whenever new new information is received.
  208. * @see javax.jmdns.JmDNS#requestServiceInfo(java.lang.String, java.lang.String, boolean)
  209. */
  210. public abstract void requestServiceInfo(String type, String name, boolean persistent);
  211. /**
  212. * Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.
  213. *
  214. * @param type
  215. * full qualified service type, such as <code>_http._tcp.local.</code> .
  216. * @param name
  217. * unqualified service name, such as <code>foobar</code> .
  218. * @param timeout
  219. * timeout in milliseconds
  220. * @see javax.jmdns.JmDNS#requestServiceInfo(java.lang.String, java.lang.String, long)
  221. */
  222. public abstract void requestServiceInfo(String type, String name, long timeout);
  223. /**
  224. * Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.
  225. *
  226. * @param type
  227. * full qualified service type, such as <code>_http._tcp.local.</code> .
  228. * @param name
  229. * unqualified service name, such as <code>foobar</code> .
  230. * @param persistent
  231. * if <code>true</code> ServiceListener.resolveService will be called whenever new new information is received.
  232. * @param timeout
  233. * timeout in milliseconds
  234. * @see javax.jmdns.JmDNS#requestServiceInfo(java.lang.String, java.lang.String, boolean, long)
  235. */
  236. public abstract void requestServiceInfo(String type, String name, boolean persistent, long timeout);
  237. /**
  238. * Listen for service types.
  239. *
  240. * @param listener
  241. * listener for service types
  242. * @exception IOException
  243. * @see javax.jmdns.JmDNS#addServiceTypeListener(javax.jmdns.ServiceTypeListener)
  244. */
  245. public abstract void addServiceTypeListener(ServiceTypeListener listener) throws IOException;
  246. /**
  247. * Remove listener for service types.
  248. *
  249. * @param listener
  250. * listener for service types
  251. * @see javax.jmdns.JmDNS#removeServiceTypeListener(javax.jmdns.ServiceTypeListener)
  252. */
  253. public abstract void removeServiceTypeListener(ServiceTypeListener listener);
  254. /**
  255. * Listen for services of a given type. The type has to be a fully qualified type name such as <code>_http._tcp.local.</code>.
  256. *
  257. * @param type
  258. * full qualified service type, such as <code>_http._tcp.local.</code>.
  259. * @param listener
  260. * listener for service updates
  261. * @see javax.jmdns.JmDNS#addServiceListener(java.lang.String, javax.jmdns.ServiceListener)
  262. */
  263. public abstract void addServiceListener(String type, ServiceListener listener);
  264. /**
  265. * Remove listener for services of a given type.
  266. *
  267. * @param type
  268. * full qualified service type, such as <code>_http._tcp.local.</code>.
  269. * @param listener
  270. * listener for service updates
  271. * @see javax.jmdns.JmDNS#removeServiceListener(java.lang.String, javax.jmdns.ServiceListener)
  272. */
  273. public abstract void removeServiceListener(String type, ServiceListener listener);
  274. /**
  275. * 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>
  276. * <b>Note</b> the Service info is cloned for each network interface.
  277. *
  278. * @param info
  279. * service info to register
  280. * @exception IOException
  281. * @see javax.jmdns.JmDNS#registerService(javax.jmdns.ServiceInfo)
  282. */
  283. public abstract void registerService(ServiceInfo info) throws IOException;
  284. /**
  285. * Unregister a service. The service should have been registered.
  286. *
  287. * @param info
  288. * service info to remove
  289. * @see javax.jmdns.JmDNS#unregisterService(javax.jmdns.ServiceInfo)
  290. */
  291. public abstract void unregisterService(ServiceInfo info);
  292. /**
  293. * Unregister all services.
  294. *
  295. * @see javax.jmdns.JmDNS#unregisterAllServices()
  296. */
  297. public abstract void unregisterAllServices();
  298. /**
  299. * 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.
  300. *
  301. * @param type
  302. * full qualified service type, such as <code>_http._tcp.local.</code>.
  303. * @see javax.jmdns.JmDNS#registerServiceType(java.lang.String)
  304. */
  305. public abstract void registerServiceType(String type);
  306. /**
  307. * Returns a list of service infos of the specified type.
  308. *
  309. * @param type
  310. * Service type name, such as <code>_http._tcp.local.</code>.
  311. * @return An array of service instance.
  312. * @see javax.jmdns.JmDNS#list(java.lang.String)
  313. */
  314. public abstract ServiceInfo[] list(String type);
  315. /**
  316. * Returns a list of service infos of the specified type.
  317. *
  318. * @param type
  319. * Service type name, such as <code>_http._tcp.local.</code>.
  320. * @param timeout
  321. * timeout in milliseconds. Typical timeout should be 6s.
  322. * @return An array of service instance.
  323. * @see javax.jmdns.JmDNS#list(java.lang.String, long)
  324. */
  325. public abstract ServiceInfo[] list(String type, long timeout);
  326. /**
  327. * 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.
  328. *
  329. * @param type
  330. * Service type name, such as <code>_http._tcp.local.</code>.
  331. * @return A dictionary of service info by subtypes.
  332. * @see javax.jmdns.JmDNS#listBySubtype(java.lang.String)
  333. */
  334. public abstract Map<String, ServiceInfo[]> listBySubtype(String type);
  335. /**
  336. * 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.
  337. *
  338. * @param type
  339. * Service type name, such as <code>_http._tcp.local.</code>.
  340. * @param timeout
  341. * timeout in milliseconds. Typical timeout should be 6s.
  342. * @return A dictionary of service info by subtypes.
  343. * @see javax.jmdns.JmDNS#listBySubtype(java.lang.String, long)
  344. */
  345. public abstract Map<String, ServiceInfo[]> listBySubtype(String type, long timeout);
  346. /**
  347. * Listen to network changes.
  348. *
  349. * @param listener
  350. * listener for network changes
  351. */
  352. public abstract void addNetworkTopologyListener(NetworkTopologyListener listener);
  353. /**
  354. * Remove listener for network changes.
  355. *
  356. * @param listener
  357. * listener for network changes
  358. */
  359. public abstract void removeNetworkTopologyListener(NetworkTopologyListener listener);
  360. /**
  361. * Returns list of network change listeners
  362. *
  363. * @return list of network change listeners
  364. */
  365. public abstract NetworkTopologyListener[] networkListeners();
  366. }