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 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();
}
use of javax.jmdns.JmDNS in project Openfire by igniterealtime.
the class MulticastDNSService method start.
@Override
public void start() throws IllegalStateException {
// If the service isn't enabled, return.
if (!JiveGlobals.getBooleanProperty("multicastDNS.enabled", false)) {
return;
}
TimerTask startService = new TimerTask() {
@Override
public void run() {
int clientPortNum = -1;
int componentPortNum = -1;
final ConnectionManager connectionManager = XMPPServer.getInstance().getConnectionManager();
if (connectionManager != null) {
clientPortNum = connectionManager.getClientListenerPort();
componentPortNum = connectionManager.getComponentListenerPort();
}
try {
if (jmdns == null) {
jmdns = new JmDNS();
}
String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
if (clientPortNum != -1) {
ServiceInfo clientService = new ServiceInfo("_xmpp-client._tcp.local.", serverName + "._xmpp-client._tcp.local.", clientPortNum, "XMPP Server");
jmdns.registerService(clientService);
}
if (componentPortNum != -1) {
ServiceInfo componentService = new ServiceInfo("_xmpp-component._tcp.local.", serverName + "._xmpp-component._tcp.local.", componentPortNum, "XMPP Component Server");
jmdns.registerService(componentService);
}
} catch (IOException ioe) {
Log.error(ioe.getMessage(), ioe);
}
}
};
// Schedule the task to run in 5 seconds, to give Wildire time to start the ports.
TaskEngine.getInstance().schedule(startService, 5000);
}
use of javax.jmdns.JmDNS in project smarthome by eclipse.
the class MDNSClientImpl method unregisterService.
@Override
public void unregisterService(ServiceDescription description) {
activeServices.remove(description);
for (JmDNS instance : jmdnsInstances.values()) {
try {
logger.debug("Unregistering service {} at {}:{} ({})", description.serviceType, instance.getInetAddress().getHostAddress(), description.servicePort, instance.getName());
} catch (IOException e) {
logger.debug("Unregistering service {} ({})", description.serviceType, instance.getName());
}
ServiceInfo serviceInfo = ServiceInfo.create(description.serviceType, description.serviceName, description.servicePort, 0, 0, description.serviceProperties);
instance.unregisterService(serviceInfo);
}
}
use of javax.jmdns.JmDNS in project smarthome by eclipse.
the class MDNSClientImpl method createJmDNSByAddress.
private void createJmDNSByAddress(InetAddress address) {
try {
JmDNS jmdns = JmDNS.create(address, "JmDNS-" + address.toString());
jmdnsInstances.put(address, jmdns);
logger.debug("mDNS service has been started ({} for IP {})", jmdns.getName(), address.getHostAddress());
} catch (IOException e) {
logger.debug("JmDNS instantiation failed ({})!", address.getHostAddress());
}
}
Aggregations