use of javax.jmdns.JmDNS in project JAirPort by froks.
the class JmmDNSImpl method getServiceInfos.
/*
* (non-Javadoc)
* @see javax.jmdns.JmmDNS#getServiceInfos(java.lang.String, java.lang.String, boolean, long)
*/
@Override
public ServiceInfo[] getServiceInfos(final String type, final String name, final boolean persistent, final long timeout) {
// We need to run this in parallel to respect the timeout.
final Set<ServiceInfo> result = Collections.synchronizedSet(new HashSet<ServiceInfo>(_knownMDNS.size()));
ExecutorService executor = Executors.newCachedThreadPool();
for (final JmDNS mDNS : _knownMDNS.values()) {
executor.submit(new Runnable() {
/**
* {@inheritDoc}
*/
@Override
public void run() {
result.add(mDNS.getServiceInfo(type, name, persistent, timeout));
}
});
}
executor.shutdown();
try {
executor.awaitTermination(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException exception) {
logger.log(Level.WARNING, "Exception ", exception);
}
return result.toArray(new ServiceInfo[result.size()]);
}
use of javax.jmdns.JmDNS in project JAirPort by froks.
the class JmmDNSImpl method registerService.
/*
* (non-Javadoc)
* @see javax.jmdns.JmmDNS#registerService(javax.jmdns.ServiceInfo)
*/
@Override
public void registerService(ServiceInfo info) throws IOException {
// This is really complex. We need to clone the service info for each DNS but then we loose the ability to update it.
synchronized (_services) {
for (JmDNS mDNS : _knownMDNS.values()) {
mDNS.registerService(info.clone());
}
((ServiceInfoImpl) info).setDelegate(this);
_services.put(info.getQualifiedName(), info);
}
}
use of javax.jmdns.JmDNS in project JAirPort by froks.
the class JmmDNSImpl method close.
/*
* (non-Javadoc)
* @see java.io.Closeable#close()
*/
@Override
public void close() throws IOException {
if (logger.isLoggable(Level.FINER)) {
logger.finer("Cancelling JmmDNS: " + this);
}
_timer.cancel();
_ListenerExecutor.shutdown();
// We need to cancel all the DNS
ExecutorService executor = Executors.newCachedThreadPool();
for (final JmDNS mDNS : _knownMDNS.values()) {
executor.submit(new Runnable() {
/**
* {@inheritDoc}
*/
@Override
public void run() {
try {
mDNS.close();
} catch (IOException exception) {
// JmDNS never throws this is only because of the closeable interface
}
}
});
}
executor.shutdown();
try {
executor.awaitTermination(DNSConstants.CLOSE_TIMEOUT, TimeUnit.MILLISECONDS);
} catch (InterruptedException exception) {
logger.log(Level.WARNING, "Exception ", exception);
}
_knownMDNS.clear();
}
Aggregations