org.apache.activemq.jmdns
Class JmDNS

java.lang.Object
  extended by org.apache.activemq.jmdns.JmDNS

public class JmDNS
extends java.lang.Object

mDNS implementation in Java.

Version:
%I%, %G%
Author:
Arthur van Hoff, Rick Blair, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Scott Lewis

Field Summary
protected  boolean closed
          Used to fix live lock problem on unregester.
static java.lang.String VERSION
          The version of JmDNS.
 
Constructor Summary
JmDNS()
          Create an instance of JmDNS.
JmDNS(java.net.InetAddress addr)
          Create an instance of JmDNS and bind it to a specific network interface given its IP-address.
 
Method Summary
 void addServiceListener(java.lang.String type, ServiceListener listener)
          Listen for services of a given type.
 void addServiceTypeListener(ServiceTypeListener listener)
          Listen for service types.
 void close()
          Close down jmdns.
 java.lang.String getHostName()
          Return the HostName associated with this JmDNS instance.
 java.net.InetAddress getInterface()
          Return the address of the interface to which this instance of JmDNS is bound.
 org.apache.activemq.jmdns.HostInfo getLocalHost()
           
 ServiceInfo getServiceInfo(java.lang.String type, java.lang.String name)
          Get service information.
 ServiceInfo getServiceInfo(java.lang.String type, java.lang.String name, int timeout)
          Get service information.
 ServiceInfo[] list(java.lang.String type)
          Returns a list of service infos of the specified type.
 void printServices()
          List Services and serviceTypes.
protected  void recover()
          Recover jmdns when there is an error.
 void registerService(ServiceInfo info)
          Register a service.
 void registerServiceType(java.lang.String type)
          Register a service type.
 void removeServiceListener(java.lang.String type, ServiceListener listener)
          Remove listener for services of a given type.
 void removeServiceTypeListener(ServiceTypeListener listener)
          Remove listener for service types.
 void requestServiceInfo(java.lang.String type, java.lang.String name)
          Request service information.
 void requestServiceInfo(java.lang.String type, java.lang.String name, int timeout)
          Request service information.
 java.lang.String toString()
           
 void unregisterAllServices()
          Unregister all services.
 void unregisterService(ServiceInfo info)
          Unregister a service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static java.lang.String VERSION
The version of JmDNS.


closed

protected boolean closed
Used to fix live lock problem on unregester.

Constructor Detail

JmDNS

public JmDNS()
      throws java.io.IOException
Create an instance of JmDNS.

Throws:
java.io.IOException

JmDNS

public JmDNS(java.net.InetAddress addr)
      throws java.io.IOException
Create an instance of JmDNS and bind it to a specific network interface given its IP-address.

Throws:
java.io.IOException
Method Detail

getHostName

public java.lang.String getHostName()
Return the HostName associated with this JmDNS instance. Note: May not be the same as what started. The host name is subject to negotiation.


getLocalHost

public org.apache.activemq.jmdns.HostInfo getLocalHost()

getInterface

public java.net.InetAddress getInterface()
                                  throws java.io.IOException
Return the address of the interface to which this instance of JmDNS is bound.

Throws:
java.io.IOException

getServiceInfo

public ServiceInfo getServiceInfo(java.lang.String type,
                                  java.lang.String name)
Get service information. If the information is not cached, the method will block until updated information is received.

Usage note: Do not call this method from the AWT event dispatcher thread. You will make the user interface unresponsive.

Parameters:
type - fully qualified service type, such as _http._tcp.local. .
name - unqualified service name, such as foobar .
Returns:
null if the service information cannot be obtained

getServiceInfo

public ServiceInfo getServiceInfo(java.lang.String type,
                                  java.lang.String name,
                                  int timeout)
Get service information. If the information is not cached, the method will block for the given timeout until updated information is received.

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.

Parameters:
type - full qualified service type, such as _http._tcp.local. .
name - unqualified service name, such as foobar .
timeout - timeout in milliseconds
Returns:
null if the service information cannot be obtained

requestServiceInfo

public void requestServiceInfo(java.lang.String type,
                               java.lang.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.

Usage note: Do not call this method from the AWT event dispatcher thread. You will make the user interface unresponsive.

Parameters:
type - full qualified service type, such as _http._tcp.local. .
name - unqualified service name, such as foobar .

requestServiceInfo

public void requestServiceInfo(java.lang.String type,
                               java.lang.String name,
                               int timeout)
Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.

Parameters:
type - full qualified service type, such as _http._tcp.local. .
name - unqualified service name, such as foobar .
timeout - timeout in milliseconds

addServiceTypeListener

public void addServiceTypeListener(ServiceTypeListener listener)
                            throws java.io.IOException
Listen for service types.

Parameters:
listener - listener for service types
Throws:
java.io.IOException

removeServiceTypeListener

public void removeServiceTypeListener(ServiceTypeListener listener)
Remove listener for service types.

Parameters:
listener - listener for service types

addServiceListener

public void addServiceListener(java.lang.String type,
                               ServiceListener listener)
Listen for services of a given type. The type has to be a fully qualified type name such as _http._tcp.local..

Parameters:
type - full qualified service type, such as _http._tcp.local..
listener - listener for service updates

removeServiceListener

public void removeServiceListener(java.lang.String type,
                                  ServiceListener listener)
Remove listener for services of a given type.

Parameters:
listener - listener for service updates

registerService

public void registerService(ServiceInfo info)
                     throws java.io.IOException
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.

Throws:
java.io.IOException

unregisterService

public void unregisterService(ServiceInfo info)
Unregister a service. The service should have been registered.


unregisterAllServices

public void unregisterAllServices()
Unregister all services.


registerServiceType

public void registerServiceType(java.lang.String type)
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.


recover

protected void recover()
Recover jmdns when there is an error.


close

public void close()
Close down jmdns. Release all resources and unregister all services.


printServices

public void printServices()
List Services and serviceTypes. Debugging Only


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

list

public ServiceInfo[] list(java.lang.String type)
Returns a list of service infos of the specified type.

Parameters:
type - Service type name, such as _http._tcp.local..
Returns:
An array of service instance names.


Copyright © 2005-2011 FuseSource, Corp.. All Rights Reserved.