javax.jmdns.impl
Class JmDNSImpl

java.lang.Object
  extended by javax.jmdns.JmDNS
      extended by javax.jmdns.impl.JmDNSImpl

public class JmDNSImpl
extends JmDNS

mDNS implementation in Java.


Nested Class Summary
protected  class JmDNSImpl.Shutdown
          Shutdown operations.
 
Field Summary
protected  java.lang.Thread _shutdown
          This is the shutdown hook, we registered with the java runtime.
 
Fields inherited from class javax.jmdns.JmDNS
VERSION
 
Constructor Summary
JmDNSImpl()
          Create an instance of JmDNS.
JmDNSImpl(java.net.InetAddress address)
          Create an instance of JmDNS and bind it to a specific network interface given its IP-address.
 
Method Summary
 DNSOutgoing addAnswer(DNSIncoming in, java.net.InetAddress addr, int port, DNSOutgoing out, DNSRecord rec)
          Add an answer to a question.
 void addListener(javax.jmdns.impl.DNSListener listener, DNSQuestion question)
          Add a listener for a question.
 void addServiceListener(java.lang.String type, ServiceListener listener)
          Listen for services of a given type.
 void addServiceTypeListener(ServiceTypeListener listener)
          Listen for service types.
 void advanceState()
          Sets the state and notifies all objects that wait on JmDNS.
 void close()
          Close down jmdns.
 DNSCache getCache()
          Return the DNSCache associated with the cache variable
 java.net.InetAddress getGroup()
           
 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.
 java.lang.Object getIoLock()
           
 long getLastThrottleIncrement()
           
 HostInfo getLocalHost()
          Returns the local host info
 DNSIncoming getPlannedAnswer()
           
static java.util.Random getRandom()
           
 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.
 java.util.Map<java.lang.String,ServiceInfo> getServices()
           
 java.util.Map<java.lang.String,java.lang.String> getServiceTypes()
           
 java.net.MulticastSocket getSocket()
           
 javax.jmdns.impl.constants.DNSState getState()
          Returns the current state of this info.
 java.util.TimerTask getTask()
           
 int getThrottle()
           
 boolean isClosed()
           
 ServiceInfo[] list(java.lang.String type)
          Returns a list of service infos of the specified type.
 void printServices()
          List Services and serviceTypes.
 void recover()
          Recover jmdns when there is an error.
 void registerService(ServiceInfo infoAbstract)
          Register a service.
 void registerServiceType(java.lang.String type)
          Register a service type.
 void removeListener(javax.jmdns.impl.DNSListener listener)
          Remove a listener from all outstanding questions.
 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.
 void schedule(java.util.TimerTask task, int delay)
           
 void send(DNSOutgoing out)
          Send an outgoing multicast DNS message.
 void setClosed(boolean closed)
           
 void setIoLock(java.lang.Object ioLock)
           
 void setLastThrottleIncrement(long lastThrottleIncrement)
           
 void setPlannedAnswer(DNSIncoming plannedAnswer)
           
 void setState(javax.jmdns.impl.constants.DNSState state)
           
 void setTask(java.util.TimerTask task)
           
 void setThrottle(int throttle)
           
 void startAnnouncer()
           
 void startRenewer()
           
 java.lang.String toString()
           
 void unregisterAllServices()
          Unregister all services.
 void unregisterService(ServiceInfo infoAbstract)
          Unregister a service.
 void updateRecord(long now, DNSRecord rec)
          Notify all listeners that a record was updated.
 
Methods inherited from class javax.jmdns.JmDNS
create, create
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_shutdown

protected java.lang.Thread _shutdown
This is the shutdown hook, we registered with the java runtime.

Constructor Detail

JmDNSImpl

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

Throws:
java.io.IOException

JmDNSImpl

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

Parameters:
address -
Throws:
java.io.IOException
Method Detail

advanceState

public void advanceState()
Sets the state and notifies all objects that wait on JmDNS.


getState

public javax.jmdns.impl.constants.DNSState getState()
Returns the current state of this info.

Returns:
Info state

getCache

public DNSCache getCache()
Return the DNSCache associated with the cache variable

Returns:
DNS cache

getHostName

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

Specified by:
getHostName in class JmDNS
Returns:
Host name

getLocalHost

public HostInfo getLocalHost()
Returns the local host info

Returns:
local host info

getInterface

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

Specified by:
getInterface in class JmDNS
Returns:
Internet Address
Throws:
java.io.IOException

getServiceInfo

public ServiceInfo getServiceInfo(java.lang.String type,
                                  java.lang.String name)
Description copied from class: JmDNS
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.

Specified by:
getServiceInfo in class JmDNS
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)
Description copied from class: JmDNS
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.

Specified by:
getServiceInfo in class JmDNS
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)
Description copied from class: JmDNS
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.

Specified by:
requestServiceInfo in class JmDNS
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)
Description copied from class: JmDNS
Request service information. The information about the service is requested and the ServiceListener.resolveService method is called as soon as it is available.

Specified by:
requestServiceInfo in class JmDNS
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
Description copied from class: JmDNS
Listen for service types.

Specified by:
addServiceTypeListener in class JmDNS
Parameters:
listener - listener for service types
Throws:
java.io.IOException
See Also:
JmDNS.addServiceTypeListener(javax.jmdns.ServiceTypeListener )

removeServiceTypeListener

public void removeServiceTypeListener(ServiceTypeListener listener)
Description copied from class: JmDNS
Remove listener for service types.

Specified by:
removeServiceTypeListener in class JmDNS
Parameters:
listener - listener for service types

addServiceListener

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

Specified by:
addServiceListener in class JmDNS
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)
Description copied from class: JmDNS
Remove listener for services of a given type.

Specified by:
removeServiceListener in class JmDNS
Parameters:
type - full qualified service type, such as _http._tcp.local..
listener - listener for service updates

registerService

public void registerService(ServiceInfo infoAbstract)
                     throws java.io.IOException
Description copied from class: JmDNS
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.

Specified by:
registerService in class JmDNS
Parameters:
infoAbstract - service info to register
Throws:
java.io.IOException

unregisterService

public void unregisterService(ServiceInfo infoAbstract)
Description copied from class: JmDNS
Unregister a service. The service should have been registered.

Specified by:
unregisterService in class JmDNS
Parameters:
infoAbstract - service info to remove

unregisterAllServices

public void unregisterAllServices()
Description copied from class: JmDNS
Unregister all services.

Specified by:
unregisterAllServices in class JmDNS

registerServiceType

public void registerServiceType(java.lang.String type)
Description copied from class: JmDNS
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.

Specified by:
registerServiceType in class JmDNS
Parameters:
type - full qualified service type, such as _http._tcp.local..

addListener

public void addListener(javax.jmdns.impl.DNSListener listener,
                        DNSQuestion question)
Add a listener for a question. The listener will receive updates of answers to the question as they arrive, or from the cache if they are already available.

Parameters:
listener - DSN listener
question - DNS query

removeListener

public void removeListener(javax.jmdns.impl.DNSListener listener)
Remove a listener from all outstanding questions. The listener will no longer receive any updates.

Parameters:
listener - DSN listener

updateRecord

public void updateRecord(long now,
                         DNSRecord rec)
Notify all listeners that a record was updated.

Parameters:
now - update date
rec - DNS record

addAnswer

public DNSOutgoing addAnswer(DNSIncoming in,
                             java.net.InetAddress addr,
                             int port,
                             DNSOutgoing out,
                             DNSRecord rec)
                      throws java.io.IOException
Add an answer to a question. Deal with the case when the outgoing packet overflows

Parameters:
in -
addr -
port -
out -
rec -
Returns:
outgoing answer
Throws:
java.io.IOException

send

public void send(DNSOutgoing out)
          throws java.io.IOException
Send an outgoing multicast DNS message.

Parameters:
out -
Throws:
java.io.IOException

startAnnouncer

public void startAnnouncer()

startRenewer

public void startRenewer()

schedule

public void schedule(java.util.TimerTask task,
                     int delay)

recover

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


close

public void close()
Description copied from class: JmDNS
Close down jmdns. Release all resources and unregister all services.

Specified by:
close in class JmDNS
See Also:
JmDNS.close()

printServices

public void printServices()
Description copied from class: JmDNS
List Services and serviceTypes. Debugging Only

Specified by:
printServices in class JmDNS
See Also:
JmDNS.printServices()

toString

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

list

public ServiceInfo[] list(java.lang.String type)
Description copied from class: JmDNS
Returns a list of service infos of the specified type.

Specified by:
list in class JmDNS
Parameters:
type - Service type name, such as _http._tcp.local..
Returns:
An array of service instance names.

setState

public void setState(javax.jmdns.impl.constants.DNSState state)

setTask

public void setTask(java.util.TimerTask task)

getTask

public java.util.TimerTask getTask()

getServices

public java.util.Map<java.lang.String,ServiceInfo> getServices()

setLastThrottleIncrement

public void setLastThrottleIncrement(long lastThrottleIncrement)

getLastThrottleIncrement

public long getLastThrottleIncrement()

setThrottle

public void setThrottle(int throttle)

getThrottle

public int getThrottle()

getRandom

public static java.util.Random getRandom()

setIoLock

public void setIoLock(java.lang.Object ioLock)

getIoLock

public java.lang.Object getIoLock()

setPlannedAnswer

public void setPlannedAnswer(DNSIncoming plannedAnswer)

getPlannedAnswer

public DNSIncoming getPlannedAnswer()

getServiceTypes

public java.util.Map<java.lang.String,java.lang.String> getServiceTypes()

setClosed

public void setClosed(boolean closed)

isClosed

public boolean isClosed()

getSocket

public java.net.MulticastSocket getSocket()

getGroup

public java.net.InetAddress getGroup()