Search in sources :

Example 16 with ServiceInfo

use of javax.jmdns.ServiceInfo in project JAirPort by froks.

the class JmDNSImpl method start.

private void start(Collection<? extends ServiceInfo> serviceInfos) {
    if (_incomingListener == null) {
        _incomingListener = new SocketListener(this);
        _incomingListener.start();
    }
    this.startProber();
    for (ServiceInfo info : serviceInfos) {
        try {
            this.registerService(new ServiceInfoImpl(info));
        } catch (final Exception exception) {
            logger.log(Level.WARNING, "start() Registration exception ", exception);
        }
    }
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) SocketException(java.net.SocketException) IOException(java.io.IOException)

Example 17 with ServiceInfo

use of javax.jmdns.ServiceInfo in project JAirPort by froks.

the class JmmDNSImpl method listBySubtype.

/*
     * (non-Javadoc)
     * @see javax.jmdns.JmmDNS#listBySubtype(java.lang.String, long)
     */
@Override
public Map<String, ServiceInfo[]> listBySubtype(final String type, final long timeout) {
    Map<String, List<ServiceInfo>> map = new HashMap<String, List<ServiceInfo>>(5);
    for (ServiceInfo info : this.list(type, timeout)) {
        String subtype = info.getSubtype();
        if (!map.containsKey(subtype)) {
            map.put(subtype, new ArrayList<ServiceInfo>(10));
        }
        map.get(subtype).add(info);
    }
    Map<String, ServiceInfo[]> result = new HashMap<String, ServiceInfo[]>(map.size());
    for (String subtype : map.keySet()) {
        List<ServiceInfo> infoForSubType = map.get(subtype);
        result.put(subtype, infoForSubType.toArray(new ServiceInfo[infoForSubType.size()]));
    }
    return result;
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with ServiceInfo

use of javax.jmdns.ServiceInfo in project JAirPort by froks.

the class DNSStateTask method run.

@Override
public void run() {
    DNSOutgoing out = this.createOugoing();
    try {
        if (!this.checkRunCondition()) {
            this.cancel();
            return;
        }
        List<DNSStatefulObject> stateObjects = new ArrayList<DNSStatefulObject>();
        // send probes for JmDNS itself
        synchronized (this.getDns()) {
            if (this.getDns().isAssociatedWithTask(this, this.getTaskState())) {
                logger1.finer(this.getName() + ".run() JmDNS " + this.getTaskDescription() + " " + this.getDns().getName());
                stateObjects.add(this.getDns());
                out = this.buildOutgoingForDNS(out);
            }
        }
        // send probes for services
        for (ServiceInfo serviceInfo : this.getDns().getServices().values()) {
            ServiceInfoImpl info = (ServiceInfoImpl) serviceInfo;
            synchronized (info) {
                if (info.isAssociatedWithTask(this, this.getTaskState())) {
                    logger1.fine(this.getName() + ".run() JmDNS " + this.getTaskDescription() + " " + info.getQualifiedName());
                    stateObjects.add(info);
                    out = this.buildOutgoingForInfo(info, out);
                }
            }
        }
        if (!out.isEmpty()) {
            logger1.finer(this.getName() + ".run() JmDNS " + this.getTaskDescription() + " #" + this.getTaskState());
            this.getDns().send(out);
            // Advance the state of objects.
            this.advanceObjectsState(stateObjects);
        } else {
            // Advance the state of objects.
            this.advanceObjectsState(stateObjects);
            // If we have nothing to send, another timer taskState ahead of us has done the job for us. We can cancel.
            cancel();
            return;
        }
    } catch (Throwable e) {
        logger1.log(Level.WARNING, this.getName() + ".run() exception ", e);
        this.recoverTask(e);
    }
    this.advanceTask();
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) ServiceInfoImpl(javax.jmdns.impl.ServiceInfoImpl) DNSOutgoing(javax.jmdns.impl.DNSOutgoing) ArrayList(java.util.ArrayList) DNSStatefulObject(javax.jmdns.impl.DNSStatefulObject)

Example 19 with ServiceInfo

use of javax.jmdns.ServiceInfo in project JMRI by JMRI.

the class ZeroConfServiceTest method testServiceInfo.

/**
     * Test of serviceInfo method, of class ZeroConfService.
     */
@Test
public void testServiceInfo() {
    ZeroConfService instance = ZeroConfService.create(HTTP, 9999);
    ServiceInfo result = instance.serviceInfo();
    Assert.assertNotNull(result);
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) Test(org.junit.Test)

Example 20 with ServiceInfo

use of javax.jmdns.ServiceInfo in project coprhd-controller by CoprHD.

the class MulticastUtil method list.

/**
 * List published node(s) configuration in the network via multicast
 *
 * @param serviceName name of service published. (e.g. release version for installation)
 * @return node(s) configuration list
 */
public Map<String, Map<String, String>> list(String serviceName) {
    Map<String, Map<String, String>> results = new HashMap<String, Map<String, String>>();
    ServiceInfo[] infos = jmdns.list("_" + serviceName + "._tcp.local.");
    for (ServiceInfo info : infos) {
        _log.info("ServiceInfo:{}", info);
        // Construct the key
        final String[] hostAddrs = info.getHostAddresses();
        final StringBuffer buf = new StringBuffer();
        for (String hostAddr : hostAddrs) {
            buf.append(hostAddr);
            buf.append(';');
        }
        final String key = buf.toString();
        _log.info("\tkey:{}", key);
        // Construct the values
        final Map<String, String> values = new HashMap<String, String>();
        for (Enumeration<String> e = info.getPropertyNames(); e.hasMoreElements(); ) {
            final String prop = e.nextElement();
            final String value = new String(info.getPropertyBytes(prop));
            _log.info("\tprop:{}, value:{}", prop, value);
            values.put(prop, value);
        }
        // Put <key,values> into the results
        if (values.isEmpty()) {
            _log.warn("values are empty for key: {}", key);
        }
        results.put(key, values.isEmpty() ? null : values);
    }
    return results;
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ServiceInfo (javax.jmdns.ServiceInfo)43 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 JmDNS (javax.jmdns.JmDNS)11 List (java.util.List)10 LinkedList (java.util.LinkedList)7 HashMap (java.util.HashMap)6 ExecutorService (java.util.concurrent.ExecutorService)6 SocketException (java.net.SocketException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 DNSOutgoing (javax.jmdns.impl.DNSOutgoing)4 Inet4Address (java.net.Inet4Address)3 Inet6Address (java.net.Inet6Address)3 InetAddress (java.net.InetAddress)3 URI (java.net.URI)3 ExecutionException (java.util.concurrent.ExecutionException)3 HashSet (java.util.HashSet)2 Callable (java.util.concurrent.Callable)2 Future (java.util.concurrent.Future)2 ServiceEvent (javax.jmdns.ServiceEvent)2