Search in sources :

Example 6 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 7 with JmDNS

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

Example 8 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)

Aggregations

JmDNS (javax.jmdns.JmDNS)8 IOException (java.io.IOException)4 ServiceInfo (javax.jmdns.ServiceInfo)4 ExecutorService (java.util.concurrent.ExecutorService)3 Inet4Address (java.net.Inet4Address)1 Inet6Address (java.net.Inet6Address)1 InetAddress (java.net.InetAddress)1 TimerTask (java.util.TimerTask)1 NetworkTopologyEvent (javax.jmdns.NetworkTopologyEvent)1 NetworkTopologyListener (javax.jmdns.NetworkTopologyListener)1 ConnectionManager (org.jivesoftware.openfire.ConnectionManager)1