public class JmDNSImpl extends JmDNS implements DNSStatefulObject, DNSTaskStarter
| 限定符和类型 | 类和说明 |
|---|---|
static class |
JmDNSImpl.Operation |
static class |
JmDNSImpl.ServiceTypeEntry
This is used to store type entries.
|
protected class |
JmDNSImpl.Shutdown
Shutdown operations.
|
JmDNS.DelegateDNSStatefulObject.DefaultImplementation, DNSStatefulObject.DNSStatefulObjectSemaphoreDNSTaskStarter.DNSTaskStarterImpl, DNSTaskStarter.Factory| 限定符和类型 | 字段和说明 |
|---|---|
protected java.lang.Thread |
_shutdown
This is the shutdown hook, we registered with the java runtime.
|
protected long |
_threadSleepDurationMs |
| 构造器和说明 |
|---|
JmDNSImpl(java.net.InetAddress address,
java.lang.String name)
Create an instance of JmDNS and bind it to a specific network interface given its IP-address.
|
JmDNSImpl(java.net.InetAddress address,
java.lang.String name,
long threadSleepDurationMs)
Create an instance of JmDNS and bind it to a specific network interface given its IP-address.
|
| 限定符和类型 | 方法和说明 |
|---|---|
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.
|
boolean |
advanceState(DNSTask task)
Sets the state and notifies all objects that wait on the ServiceInfo.
|
void |
associateWithTask(DNSTask task,
DNSState state)
Sets the task associated with this Object.
|
boolean |
cancelState()
Sets the state and notifies all objects that wait on the ServiceInfo.
|
void |
cancelStateTimer()
Cancel the state task timer
|
void |
cancelTimer()
Cancel the generals task timer
|
void |
cleanCache()
Checks the cache of expired records and removes them.
|
void |
close() |
boolean |
closeState()
Sets the state and notifies all objects that wait on the ServiceInfo.
|
DNSCache |
getCache()
Return the DNSCache associated with the cache variable
|
JmDNS.Delegate |
getDelegate()
Returns the instance delegate
|
JmDNSImpl |
getDns()
Returns the DNS associated with this object.
|
java.net.InetAddress |
getGroup() |
java.lang.String |
getHostName()
Return the HostName associated with this JmDNS instance.
|
java.net.InetAddress |
getInetAddress()
Return the address of the interface to which this instance of JmDNS is bound.
|
java.net.InetAddress |
getInterface()
已过时。
|
long |
getLastThrottleIncrement() |
HostInfo |
getLocalHost()
Returns the local host info
|
java.lang.String |
getName()
Return the name of the JmDNS instance.
|
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,
boolean persistent)
Get service information.
|
ServiceInfo |
getServiceInfo(java.lang.String type,
java.lang.String name,
boolean persistent,
long timeout)
Get service information.
|
ServiceInfo |
getServiceInfo(java.lang.String type,
java.lang.String name,
long timeout)
Get service information.
|
java.util.Map<java.lang.String,ServiceInfo> |
getServices() |
java.util.Map<java.lang.String,JmDNSImpl.ServiceTypeEntry> |
getServiceTypes() |
java.net.MulticastSocket |
getSocket() |
int |
getThrottle() |
void |
ioLock() |
void |
ioUnlock() |
boolean |
isAnnounced()
Returns true, if this is an announced state.
|
boolean |
isAnnouncing()
Returns true, if this is an announcing state.
|
boolean |
isAssociatedWithTask(DNSTask task,
DNSState state)
Checks if this object is associated with the task and in the same state.
|
boolean |
isCanceled()
Returns true, if this is a canceled state.
|
boolean |
isCanceling()
Returns true, if this is a canceling state.
|
boolean |
isClosed()
Returns true, if this is a closed state.
|
boolean |
isClosing()
Returns true, if this is a closing state.
|
boolean |
isProbing()
Returns true, if this is a probing state.
|
ServiceInfo[] |
list(java.lang.String type)
Returns a list of service infos of the specified type.
|
ServiceInfo[] |
list(java.lang.String type,
long timeout)
Returns a list of service infos of the specified type.
|
java.util.Map<java.lang.String,ServiceInfo[]> |
listBySubtype(java.lang.String type)
Returns a list of service infos of the specified type sorted by subtype.
|
java.util.Map<java.lang.String,ServiceInfo[]> |
listBySubtype(java.lang.String type,
long timeout)
Returns a list of service infos of the specified type sorted by subtype.
|
static void |
main(java.lang.String[] argv)
Main method to display API information if run from java -jar
|
void |
printServices()
已过时。
|
void |
purgeStateTimer()
Purge the state task timer
|
void |
purgeTimer()
Purge the general task timer
|
void |
recover()
Recover jmDNS when there is an error.
|
boolean |
recoverState()
Sets the state and notifies all objects that wait on the ServiceInfo.
|
void |
registerService(ServiceInfo infoAbstract)
Register a service.
|
boolean |
registerServiceType(java.lang.String type)
Register a service type.
|
void |
removeAssociationWithTask(DNSTask task)
Remove the association of the task with this Object.
|
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 |
renewServiceCollector(java.lang.String type)
Renew a service when the record become stale.
|
void |
requestServiceInfo(java.lang.String type,
java.lang.String name)
Request service information.
|
void |
requestServiceInfo(java.lang.String type,
java.lang.String name,
boolean persistent)
Request service information.
|
void |
requestServiceInfo(java.lang.String type,
java.lang.String name,
boolean persistent,
long timeout)
Request service information.
|
void |
requestServiceInfo(java.lang.String type,
java.lang.String name,
long timeout)
Request service information.
|
void |
respondToQuery(DNSIncoming in) |
boolean |
revertState()
Sets the state and notifies all objects that wait on the ServiceInfo.
|
void |
send(DNSOutgoing out)
Send an outgoing multicast DNS message.
|
JmDNS.Delegate |
setDelegate(JmDNS.Delegate delegate)
Sets the instance delegate
|
void |
setLastThrottleIncrement(long lastThrottleIncrement) |
void |
setPlannedAnswer(DNSIncoming plannedAnswer) |
void |
setThrottle(int throttle) |
void |
startAnnouncer()
Start a new announcer task
|
void |
startCanceler()
Start a new canceler task
|
void |
startProber()
Start a new prober task
|
void |
startReaper()
Start a new reaper task.
|
void |
startRenewer()
Start a new renewer task
|
void |
startResponder(DNSIncoming in,
java.net.InetAddress addr,
int port)
Start a new responder task
|
void |
startServiceInfoResolver(ServiceInfoImpl info)
Start a new service info resolver task
|
void |
startServiceResolver(java.lang.String type)
Start a new service resolver task
|
void |
startTypeResolver()
Start a new service type resolver task
|
java.lang.String |
toString() |
void |
unregisterAllServices()
Unregister all services.
|
void |
unregisterService(ServiceInfo infoAbstract)
Unregister a service.
|
void |
updateRecord(long now,
DNSRecord rec,
JmDNSImpl.Operation operation)
Notify all listeners that a record was updated.
|
boolean |
waitForAnnounced(long timeout)
Waits for the object to be announced.
|
boolean |
waitForCanceled(long timeout)
Waits for the object to be canceled.
|
protected final long _threadSleepDurationMs
protected java.lang.Thread _shutdown
public JmDNSImpl(java.net.InetAddress address,
java.lang.String name)
throws java.io.IOException
address - IP address to bind to.name - name of the newly created JmDNSjava.io.IOExceptionpublic JmDNSImpl(java.net.InetAddress address,
java.lang.String name,
long threadSleepDurationMs)
throws java.io.IOException
address - IP address to bind to.name - name of the newly created JmDNSthreadSleepDurationMs - time in milliseconds that the JmDNS listener thread should sleep between multicast receivesjava.io.IOExceptionpublic static void main(java.lang.String[] argv)
argv - the command line argumentspublic boolean advanceState(DNSTask task)
advanceState 在接口中 DNSStatefulObjecttask - associated tasktrue if the state was changed by this thread, false otherwise.DNSState.advance()public boolean revertState()
revertState 在接口中 DNSStatefulObjecttrue if the state was changed by this thread, false otherwise.DNSState.revert()public boolean cancelState()
cancelState 在接口中 DNSStatefulObjecttrue if the state was changed by this thread, false otherwise.public boolean closeState()
closeState 在接口中 DNSStatefulObjecttrue if the state was changed by this thread, false otherwise.public boolean recoverState()
recoverState 在接口中 DNSStatefulObjecttrue if the state was changed by this thread, false otherwise.public JmDNSImpl getDns()
getDns 在接口中 DNSStatefulObjectpublic void associateWithTask(DNSTask task, DNSState state)
associateWithTask 在接口中 DNSStatefulObjecttask - associated taskstate - state of the taskpublic void removeAssociationWithTask(DNSTask task)
removeAssociationWithTask 在接口中 DNSStatefulObjecttask - associated taskpublic boolean isAssociatedWithTask(DNSTask task, DNSState state)
isAssociatedWithTask 在接口中 DNSStatefulObjecttask - associated taskstate - state of the tasktrue is the task is associated with this object, false otherwise.public boolean isProbing()
isProbing 在接口中 DNSStatefulObjecttrue if probing state, false otherwisepublic boolean isAnnouncing()
isAnnouncing 在接口中 DNSStatefulObjecttrue if announcing state, false otherwisepublic boolean isAnnounced()
isAnnounced 在接口中 DNSStatefulObjecttrue if announced state, false otherwisepublic boolean isCanceling()
isCanceling 在接口中 DNSStatefulObjecttrue if canceling state, false otherwisepublic boolean isCanceled()
isCanceled 在接口中 DNSStatefulObjecttrue if canceled state, false otherwisepublic boolean isClosing()
isClosing 在接口中 DNSStatefulObjecttrue if closing state, false otherwisepublic boolean isClosed()
isClosed 在接口中 DNSStatefulObjecttrue if closed state, false otherwisepublic boolean waitForAnnounced(long timeout)
waitForAnnounced 在接口中 DNSStatefulObjecttimeout - the maximum time to wait in milliseconds.true if the object is announced, false otherwisepublic boolean waitForCanceled(long timeout)
waitForCanceled 在接口中 DNSStatefulObjecttimeout - the maximum time to wait in milliseconds.true if the object is canceled, false otherwisepublic DNSCache getCache()
public java.lang.String getName()
public java.lang.String getHostName()
getHostName 在类中 JmDNSpublic HostInfo getLocalHost()
public java.net.InetAddress getInetAddress()
throws java.io.IOException
getInetAddress 在类中 JmDNSjava.io.IOException - if there is an error in the underlying protocol, such as a TCP error.@Deprecated
public java.net.InetAddress getInterface()
throws java.io.IOException
getInterface 在类中 JmDNSjava.io.IOException - if there is an error in the underlying protocol, such as a TCP error.public ServiceInfo getServiceInfo(java.lang.String type, java.lang.String name)
getServiceInfo 在类中 JmDNStype - fully qualified service type, such as _http._tcp.local. .name - unqualified service name, such as foobar .public ServiceInfo getServiceInfo(java.lang.String type, java.lang.String name, long timeout)
getServiceInfo 在类中 JmDNStype - full qualified service type, such as _http._tcp.local. .name - unqualified service name, such as foobar .timeout - timeout in milliseconds. Typical timeout should be 5s.public ServiceInfo getServiceInfo(java.lang.String type, java.lang.String name, boolean persistent)
getServiceInfo 在类中 JmDNStype - fully qualified service type, such as _http._tcp.local. .name - unqualified service name, such as foobar .persistent - if true ServiceListener.resolveService will be called whenever new new information is received.public ServiceInfo getServiceInfo(java.lang.String type, java.lang.String name, boolean persistent, long timeout)
getServiceInfo 在类中 JmDNStype - full qualified service type, such as _http._tcp.local. .name - unqualified service name, such as foobar .persistent - if true ServiceListener.resolveService will be called whenever new new information is received.timeout - timeout in milliseconds. Typical timeout should be 5s.public void requestServiceInfo(java.lang.String type,
java.lang.String name)
requestServiceInfo 在类中 JmDNStype - full qualified service type, such as _http._tcp.local. .name - unqualified service name, such as foobar .public void requestServiceInfo(java.lang.String type,
java.lang.String name,
boolean persistent)
requestServiceInfo 在类中 JmDNStype - full qualified service type, such as _http._tcp.local. .name - unqualified service name, such as foobar .persistent - if true ServiceListener.resolveService will be called whenever new new information is received.public void requestServiceInfo(java.lang.String type,
java.lang.String name,
long timeout)
requestServiceInfo 在类中 JmDNStype - full qualified service type, such as _http._tcp.local. .name - unqualified service name, such as foobar .timeout - timeout in millisecondspublic void requestServiceInfo(java.lang.String type,
java.lang.String name,
boolean persistent,
long timeout)
requestServiceInfo 在类中 JmDNStype - full qualified service type, such as _http._tcp.local. .name - unqualified service name, such as foobar .persistent - if true ServiceListener.resolveService will be called whenever new new information is received.timeout - timeout in millisecondspublic void addServiceTypeListener(ServiceTypeListener listener) throws java.io.IOException
addServiceTypeListener 在类中 JmDNSlistener - listener for service typesjava.io.IOException - if there is an error in the underlying protocol, such as a TCP error.public void removeServiceTypeListener(ServiceTypeListener listener)
removeServiceTypeListener 在类中 JmDNSlistener - listener for service typespublic void addServiceListener(java.lang.String type,
ServiceListener listener)
_http._tcp.local..addServiceListener 在类中 JmDNStype - full qualified service type, such as _http._tcp.local..listener - listener for service updatespublic void removeServiceListener(java.lang.String type,
ServiceListener listener)
removeServiceListener 在类中 JmDNStype - full qualified service type, such as _http._tcp.local..listener - listener for service updatespublic void registerService(ServiceInfo infoAbstract) throws java.io.IOException
ServiceInfo is bound to this JmDNS instance, and should not be reused for any other JmDNS.registerService(ServiceInfo).registerService 在类中 JmDNSinfoAbstract - service info to registerjava.io.IOException - if there is an error in the underlying protocol, such as a TCP error.public void unregisterService(ServiceInfo infoAbstract)
Note: Unregistered services will not disappear form the list of services immediately. According to the specification, when unregistering services we send goodbye packets and then wait 1s before purging the cache.
This is support for shared records that can be rescued by some other cooperation DNS.
Clients receiving a Multicast DNS Response with a TTL of zero SHOULD NOT immediately delete the record from the cache, but instead record a TTL of 1 and then delete the record one second later.
unregisterService 在类中 JmDNSinfoAbstract - service info to removepublic void unregisterAllServices()
unregisterAllServices 在类中 JmDNSpublic boolean registerServiceType(java.lang.String type)
Service types are automatically registered as they are discovered.
registerServiceType 在类中 JmDNStype - full qualified service type, such as _http._tcp.local..true if the type or subtype was added, false if the type was already registered.public void addListener(javax.jmdns.impl.DNSListener listener,
DNSQuestion question)
listener - DSN listenerquestion - DNS querypublic void removeListener(javax.jmdns.impl.DNSListener listener)
listener - DSN listenerpublic void renewServiceCollector(java.lang.String type)
type - Service Typepublic void updateRecord(long now,
DNSRecord rec,
JmDNSImpl.Operation operation)
now - update daterec - DNS recordoperation - DNS cache operationpublic void respondToQuery(DNSIncoming in)
public DNSOutgoing addAnswer(DNSIncoming in, java.net.InetAddress addr, int port, DNSOutgoing out, DNSRecord rec) throws java.io.IOException
in - addr - port - out - rec - java.io.IOExceptionpublic void send(DNSOutgoing out) throws java.io.IOException
out - java.io.IOExceptionpublic void purgeTimer()
DNSTaskStarterpurgeTimer 在接口中 DNSTaskStarterpublic void purgeStateTimer()
DNSTaskStarterpurgeStateTimer 在接口中 DNSTaskStarterpublic void cancelTimer()
DNSTaskStartercancelTimer 在接口中 DNSTaskStarterpublic void cancelStateTimer()
DNSTaskStartercancelStateTimer 在接口中 DNSTaskStarterpublic void startProber()
DNSTaskStarterstartProber 在接口中 DNSTaskStarterpublic void startAnnouncer()
DNSTaskStarterstartAnnouncer 在接口中 DNSTaskStarterpublic void startRenewer()
DNSTaskStarterstartRenewer 在接口中 DNSTaskStarterpublic void startCanceler()
DNSTaskStarterstartCanceler 在接口中 DNSTaskStarterpublic void startReaper()
DNSTaskStarterstartReaper 在接口中 DNSTaskStarterpublic void startServiceInfoResolver(ServiceInfoImpl info)
DNSTaskStarterstartServiceInfoResolver 在接口中 DNSTaskStarterinfo - service info to resolvepublic void startTypeResolver()
DNSTaskStarterstartTypeResolver 在接口中 DNSTaskStarterpublic void startServiceResolver(java.lang.String type)
DNSTaskStarterstartServiceResolver 在接口中 DNSTaskStartertype - service type to resolvepublic void startResponder(DNSIncoming in, java.net.InetAddress addr, int port)
DNSTaskStarterstartResponder 在接口中 DNSTaskStarterin - incoming messageaddr - incoming addressport - incoming portpublic void recover()
public void cleanCache()
Implementation note:
This method is called by the RecordReaper every DNSConstants.RECORD_REAPER_INTERVAL milliseconds.
DNSRecord,
RecordReaperpublic void close()
close 在接口中 java.io.Closeableclose 在接口中 java.lang.AutoCloseable@Deprecated public void printServices()
printServices 在类中 JmDNSpublic java.lang.String toString()
toString 在类中 java.lang.Objectpublic ServiceInfo[] list(java.lang.String type)
public ServiceInfo[] list(java.lang.String type, long timeout)
public java.util.Map<java.lang.String,ServiceInfo[]> listBySubtype(java.lang.String type)
listBySubtype 在类中 JmDNStype - Service type name, such as _http._tcp.local..public java.util.Map<java.lang.String,ServiceInfo[]> listBySubtype(java.lang.String type, long timeout)
listBySubtype 在类中 JmDNStype - Service type name, such as _http._tcp.local..timeout - timeout in milliseconds. Typical timeout should be 6s.public java.util.Map<java.lang.String,ServiceInfo> getServices()
public void setLastThrottleIncrement(long lastThrottleIncrement)
public long getLastThrottleIncrement()
public void setThrottle(int throttle)
public int getThrottle()
public static java.util.Random getRandom()
public void ioLock()
public void ioUnlock()
public void setPlannedAnswer(DNSIncoming plannedAnswer)
public DNSIncoming getPlannedAnswer()
public java.util.Map<java.lang.String,JmDNSImpl.ServiceTypeEntry> getServiceTypes()
public java.net.MulticastSocket getSocket()
public java.net.InetAddress getGroup()
public JmDNS.Delegate getDelegate()
JmDNSgetDelegate 在类中 JmDNSpublic JmDNS.Delegate setDelegate(JmDNS.Delegate delegate)
JmDNSsetDelegate 在类中 JmDNSdelegate - new instance delegate