Search in sources :

Example 6 with ServiceInfo

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

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) LinkedList(java.util.LinkedList) List(java.util.List)

Example 7 with ServiceInfo

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

the class ServiceResolver method addAnswers.

/*
     * (non-Javadoc)
     * @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing)
     */
@Override
protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException {
    DNSOutgoing newOut = out;
    long now = System.currentTimeMillis();
    for (ServiceInfo info : this.getDns().getServices().values()) {
        newOut = this.addAnswer(newOut, new DNSRecord.Pointer(info.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getQualifiedName()), now);
    // newOut = this.addAnswer(newOut, new DNSRecord.Service(info.getQualifiedName(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getPriority(), info.getWeight(), info.getPort(),
    // this.getDns().getLocalHost().getName()), now);
    }
    return newOut;
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) DNSOutgoing(javax.jmdns.impl.DNSOutgoing)

Example 8 with ServiceInfo

use of javax.jmdns.ServiceInfo in project smarthome by eclipse.

the class MDNSDiscoveryService method scan.

private void scan() {
    for (MDNSDiscoveryParticipant participant : participants) {
        ServiceInfo[] services = mdnsClient.list(participant.getServiceType());
        logger.debug("{} services found for {}", services.length, participant.getServiceType());
        for (ServiceInfo service : services) {
            DiscoveryResult result = participant.createResult(service);
            if (result != null) {
                thingDiscovered(result);
            }
        }
    }
    for (org.eclipse.smarthome.io.transport.mdns.discovery.MDNSDiscoveryParticipant participant : oldParticipants) {
        ServiceInfo[] services = mdnsClient.list(participant.getServiceType());
        logger.debug("{} services found for {}", services.length, participant.getServiceType());
        for (ServiceInfo service : services) {
            DiscoveryResult result = participant.createResult(service);
            if (result != null) {
                thingDiscovered(result);
            }
        }
    }
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) MDNSDiscoveryParticipant(org.eclipse.smarthome.config.discovery.mdns.MDNSDiscoveryParticipant)

Example 9 with ServiceInfo

use of javax.jmdns.ServiceInfo in project smarthome by eclipse.

the class MDNSClientImpl method registerService.

@Override
public void registerService(ServiceDescription description) throws IOException {
    for (JmDNS instance : jmdnsInstances) {
        logger.debug("Registering new service {} at {}:{} ({})", description.serviceType, instance.getInetAddress().getHostAddress(), description.servicePort, instance.getName());
        // Create one ServiceInfo object for each JmDNS instance
        ServiceInfo serviceInfo = ServiceInfo.create(description.serviceType, description.serviceName, description.servicePort, 0, 0, description.serviceProperties);
        instance.registerService(serviceInfo);
    }
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) JmDNS(javax.jmdns.JmDNS)

Example 10 with ServiceInfo

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

the class JmDNSImpl method listBySubtype.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, ServiceInfo[]> listBySubtype(String type, long timeout) {
    Map<String, List<ServiceInfo>> map = new HashMap<String, List<ServiceInfo>>(5);
    for (ServiceInfo info : this.list(type, timeout)) {
        String subtype = info.getSubtype().toLowerCase();
        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) LinkedList(java.util.LinkedList) List(java.util.List)

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