Search in sources :

Example 21 with JmDNS

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()]);
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) JmDNS(javax.jmdns.JmDNS) ExecutorService(java.util.concurrent.ExecutorService)

Example 22 with JmDNS

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();
}
Also used : JmDNS(javax.jmdns.JmDNS) ExecutorService(java.util.concurrent.ExecutorService) IOException(java.io.IOException)

Example 23 with JmDNS

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);
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) ConnectionManager(org.jivesoftware.openfire.ConnectionManager) JmDNS(javax.jmdns.JmDNS) TimerTask(java.util.TimerTask) IOException(java.io.IOException)

Example 24 with JmDNS

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);
    }
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) JmDNS(javax.jmdns.JmDNS) IOException(java.io.IOException)

Example 25 with JmDNS

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());
    }
}
Also used : JmDNS(javax.jmdns.JmDNS) IOException(java.io.IOException)

Aggregations

JmDNS (javax.jmdns.JmDNS)25 IOException (java.io.IOException)14 ServiceInfo (javax.jmdns.ServiceInfo)12 ExecutorService (java.util.concurrent.ExecutorService)6 InetAddress (java.net.InetAddress)4 ArrayList (java.util.ArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)4 List (java.util.List)3 NetworkTopologyEvent (javax.jmdns.NetworkTopologyEvent)3 NetworkTopologyListener (javax.jmdns.NetworkTopologyListener)3 ServiceListener (javax.jmdns.ServiceListener)3 NamedThreadFactory (javax.jmdns.impl.util.NamedThreadFactory)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Callable (java.util.concurrent.Callable)2 Future (java.util.concurrent.Future)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 BigInteger (java.math.BigInteger)1 Inet4Address (java.net.Inet4Address)1