Search in sources :

Example 31 with ServiceInfo

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

the class ChromecastMgr method serviceAdded.

@Override
public void serviceAdded(ServiceEvent event) {
    if (event.getInfo() == null) {
        LOGGER.debug("Bad Chromcast event: {}", event.toString());
        return;
    }
    LOGGER.debug("Found chromecast: {}", event.getInfo().getName());
    ServiceInfo serviceInfo = mDNS.getServiceInfo(ChromeCast.SERVICE_TYPE, event.getInfo().getName());
    ChromeCast chromeCast = new ChromeCast(serviceInfo.getInet4Addresses()[0].getHostAddress(), serviceInfo.getPort());
    chromeCast.setName(event.getInfo().getName());
    chromeCast.setAppsURL(serviceInfo.getURLs().length == 0 ? null : serviceInfo.getURLs()[0]);
    chromeCast.setApplication(serviceInfo.getApplication());
    try {
        chromeCast.connect();
        chromeCasts.add(new ChromeDevice(chromeCast, renderer, InetAddress.getByName(chromeCast.getAddress())));
    } catch (IOException | GeneralSecurityException | ConfigurationException e) {
        LOGGER.error("Chromecast registration failed with the following error: {}", e);
        LOGGER.trace("", e);
    }
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ChromeCast(su.litvak.chromecast.api.v2.ChromeCast) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException)

Example 32 with ServiceInfo

use of javax.jmdns.ServiceInfo in project arduino-eclipse-plugin by Sloeber.

the class NetworkDiscovery method serviceResolved.

@SuppressWarnings("nls")
@Override
public void serviceResolved(ServiceEvent serviceEvent) {
    ServiceInfo info = serviceEvent.getInfo();
    for (InetAddress inetAddress : info.getInet4Addresses()) {
        String address = inetAddress.getHostAddress();
        String name = serviceEvent.getName();
        BoardPort port = new BoardPort();
        String board = null;
        String description = null;
        if (info.hasData()) {
            board = info.getPropertyString("board");
            description = info.getPropertyString("description");
            port.getPrefs().put("board", board);
            port.getPrefs().put("distro_version", info.getPropertyString("distro_version"));
            port.getPrefs().put("port", "" + info.getPort());
            // Add additional fields to permit generic ota updates
            // and make sure we do not intefere with Arduino boards
            // define "ssh_upload=no" TXT property to use generic uploader
            // define "tcp_check=no" TXT property if you are not using TCP
            // define "auth_upload=yes" TXT property if you want to use authenticated generic upload
            String useSSH = info.getPropertyString("ssh_upload");
            String checkTCP = info.getPropertyString("tcp_check");
            String useAuth = info.getPropertyString("auth_upload");
            if (useSSH == null || !useSSH.contentEquals("no"))
                useSSH = "yes";
            if (checkTCP == null || !checkTCP.contentEquals("no"))
                checkTCP = "yes";
            if (useAuth == null || !useAuth.contentEquals("yes"))
                useAuth = "no";
            port.getPrefs().put("ssh_upload", useSSH);
            port.getPrefs().put("tcp_check", checkTCP);
            port.getPrefs().put("auth_upload", useAuth);
        }
        String label = name + " at " + address;
        // if (board != null && BaseNoGui.packages != null) {
        // String boardName = BaseNoGui.getPlatform().resolveDeviceByBoardID(BaseNoGui.packages, board);
        // if (boardName != null) {
        // label += " (" + boardName + ")";
        // }
        // } else if (description != null) {
        label += " (" + description + ")";
        // }
        port.setAddress(address);
        port.setBoardName(name);
        port.setProtocol("network");
        port.setLabel(label);
        synchronized (this.boardPortsDiscoveredWithJmDNS) {
            removeDuplicateBoards(port);
            this.boardPortsDiscoveredWithJmDNS.add(port);
        }
    }
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) BoardPort(cc.arduino.packages.BoardPort) InetAddress(java.net.InetAddress)

Example 33 with ServiceInfo

use of javax.jmdns.ServiceInfo in project webthing-java by mozilla-iot.

the class WebThingServer method start.

/**
 * Start listening for incoming connections.
 *
 * @param daemon Whether or not to daemonize the server
 * @throws IOException on failure to listen on port
 */
public void start(boolean daemon) throws IOException {
    this.jmdns = JmDNS.create(InetAddress.getLocalHost());
    String url = String.format("url=%s://%s:%d/", this.isTls ? "https" : "http", this.ip, this.port);
    ServiceInfo serviceInfo = ServiceInfo.create("_http._tcp.local", this.name, "_webthing", this.port, url);
    this.jmdns.registerService(serviceInfo);
    super.start(NanoHTTPD.SOCKET_READ_TIMEOUT, daemon);
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo)

Example 34 with ServiceInfo

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

the class MDNSClientImpl method unregisterService.

@Override
public void unregisterService(ServiceDescription description) {
    for (JmDNS instance : jmdnsInstances) {
        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 35 with ServiceInfo

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

the class JmDNSImpl method updateRecord.

// Remind: Method updateRecord should receive a better name.
/**
 * Notify all listeners that a record was updated.
 *
 * @param now
 *            update date
 * @param rec
 *            DNS record
 * @param operation
 *            DNS cache operation
 */
public void updateRecord(long now, DNSRecord rec, Operation operation) {
    // We do not want to block the entire DNS while we are updating the record for each listener (service info)
    {
        List<DNSListener> listenerList = null;
        synchronized (_listeners) {
            listenerList = new ArrayList<DNSListener>(_listeners);
        }
        for (DNSListener listener : listenerList) {
            listener.updateRecord(this.getCache(), now, rec);
        }
    }
    if (DNSRecordType.TYPE_PTR.equals(rec.getRecordType())) // if (DNSRecordType.TYPE_PTR.equals(rec.getRecordType()) || DNSRecordType.TYPE_SRV.equals(rec.getRecordType()))
    {
        ServiceEvent event = rec.getServiceEvent(this);
        if ((event.getInfo() == null) || !event.getInfo().hasData()) {
            // We do not care about the subtype because the info is only used if complete and the subtype will then be included.
            ServiceInfo info = this.getServiceInfoFromCache(event.getType(), event.getName(), "", false);
            if (info.hasData()) {
                event = new ServiceEventImpl(this, event.getType(), event.getName(), info);
            }
        }
        List<ServiceListenerStatus> list = _serviceListeners.get(event.getType().toLowerCase());
        final List<ServiceListenerStatus> serviceListenerList;
        if (list != null) {
            synchronized (list) {
                serviceListenerList = new ArrayList<ServiceListenerStatus>(list);
            }
        } else {
            serviceListenerList = Collections.emptyList();
        }
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest(this.getName() + ".updating record for event: " + event + " list " + serviceListenerList + " operation: " + operation);
        }
        if (!serviceListenerList.isEmpty()) {
            final ServiceEvent localEvent = event;
            switch(operation) {
                case Add:
                    for (final ServiceListenerStatus listener : serviceListenerList) {
                        if (listener.isSynchronous()) {
                            listener.serviceAdded(localEvent);
                        } else {
                            _executor.submit(new Runnable() {

                                /**
                                 * {@inheritDoc}
                                 */
                                @Override
                                public void run() {
                                    listener.serviceAdded(localEvent);
                                }
                            });
                        }
                    }
                    break;
                case Remove:
                    for (final ServiceListenerStatus listener : serviceListenerList) {
                        if (listener.isSynchronous()) {
                            listener.serviceRemoved(localEvent);
                        } else {
                            _executor.submit(new Runnable() {

                                /**
                                 * {@inheritDoc}
                                 */
                                @Override
                                public void run() {
                                    listener.serviceRemoved(localEvent);
                                }
                            });
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) ServiceListenerStatus(javax.jmdns.impl.ListenerStatus.ServiceListenerStatus) ServiceEvent(javax.jmdns.ServiceEvent) ArrayList(java.util.ArrayList) 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