Package javax.jmdns

Examples of javax.jmdns.JmDNS$Delegate


        ServiceResolver.ANNOUNCE_OVERRIDE = true;

        int port = new Random().nextInt(32000);

        System.out.println("Create JmDNS " + port);
        JmDNS jmdns = JmDNS.create();

        System.out.println("Create");
        final ServiceInfo service = ServiceInfo.create("_httpx._tcp.local.", "Port@" + port, port, 0, 0, ":-)");
        System.out.println("Register");
        jmdns.registerService(service);

        for (int i = 0; i < 10; i++) {
            System.out.println("Query:");
            ServiceInfo[] list = jmdns.list("_httpx._tcp.local.");
            for (ServiceInfo serviceInfo : list) {
                System.out.println(serviceInfo);
            }

            Thread.sleep(200);
View Full Code Here


        InetAddress address = event.getInetAddress();
        try {
            synchronized (this) {
                if (_knownMDNS.putIfAbsent(address, JmDNS.create(address)) == null) {
                    // We need to register the services and listeners with the new JmDNS
                    final JmDNS dns = _knownMDNS.get(address);
                    final Collection<String> types = _serviceTypes;
                    final Collection<ServiceInfo> infos = _services.values();
                    final Collection<ServiceTypeListener> typeListeners = _typeListeners;
                    final Map<String, List<ServiceListener>> serviceListeners = _serviceListeners;
                    _jmDNSExecutor.submit(new Runnable() {
                        /**
                         * {@inheritDoc}
                         */
                        @Override
                        public void run() {
                            // Register Types
                            for (String type : types) {
                                dns.registerServiceType(type);
                            }
                            // Register services
                            for (ServiceInfo info : infos) {
                                try {
                                    dns.registerService(info.clone());
                                } catch (IOException exception) {
                                    // logger.warning("Unexpected unhandled exception: " + exception);
                                }
                            }
                            // Add ServiceType Listeners
                            for (ServiceTypeListener listener : typeListeners) {
                                try {
                                    dns.addServiceTypeListener(listener);
                                } catch (IOException exception) {
                                    // logger.warning("Unexpected unhandled exception: " + exception);
                                }
                            }
                            // Add Service Listeners
                            for (String type : serviceListeners.keySet()) {
                                List<ServiceListener> listeners = serviceListeners.get(type);
                                synchronized (listeners) {
                                    for (ServiceListener listener : listeners) {
                                        dns.addServiceListener(type, listener);
                                    }
                                }
                            }
                        }
                    });
View Full Code Here

    public void inetAddressRemoved(NetworkTopologyEvent event) {
        InetAddress address = event.getInetAddress();
        try {
            synchronized (this) {
                if (_knownMDNS.containsKey(address)) {
                    JmDNS mDNS = _knownMDNS.remove(address);
                    mDNS.close();
                    final NetworkTopologyEvent jmdnsEvent = new NetworkTopologyEventImpl(mDNS, address);
                    for (final NetworkTopologyListener listener : this.networkListeners()) {
                        _ListenerExecutor.submit(new Runnable() {
                            /**
                             * {@inheritDoc}
 
View Full Code Here

    }

    @Test
    public void testCreate() throws IOException {
        System.out.println("Unit Test: testCreate()");
        JmDNS registry = JmDNS.create();
        registry.close();
    }
View Full Code Here

    }

    @Test
    public void testCreateINet() throws IOException {
        System.out.println("Unit Test: testCreateINet()");
        JmDNS registry = JmDNS.create(InetAddress.getLocalHost());
        // assertEquals("We did not register on the local host inet:", InetAddress.getLocalHost(), registry.getInterface());
        registry.close();
    }
View Full Code Here

    }

    @Test
    public void testRegisterService() throws IOException {
        System.out.println("Unit Test: testRegisterService()");
        JmDNS registry = null;
        try {
            registry = JmDNS.create();
            registry.registerService(service);
        } finally {
            if (registry != null) registry.close();
        }
    }
View Full Code Here

    }

    @Test
    public void testUnregisterService() throws IOException, InterruptedException {
        System.out.println("Unit Test: testUnregisterService()");
        JmDNS registry = null;
        try {
            registry = JmDNS.create();
            registry.registerService(service);

            ServiceInfo[] services = registry.list(service.getType());
            assertEquals("We should see the service we just registered: ", 1, services.length);
            assertEquals(service, services[0]);

            // now unregister and make sure it's gone
            registry.unregisterService(services[0]);

            // According to the spec the record disappears from the cache 1s after it has been unregistered
            // without sleeping for a while, the service would not be unregistered fully
            Thread.sleep(1500);

            services = registry.list(service.getType());
            assertTrue("We should not see the service we just unregistered: ", services == null || services.length == 0);
        } finally {
            if (registry != null) registry.close();
        }
    }
View Full Code Here

    }

    @Test
    public void testRegisterServiceTwice() throws IOException {
        System.out.println("Unit Test: testRegisterService()");
        JmDNS registry = null;
        try {
            registry = JmDNS.create();
            registry.registerService(service);
            // This should cause an exception
            registry.registerService(service);
            fail("Registering the same service info should fail.");
        } catch (IllegalStateException exception) {
            // Expected exception.
        } finally {
            if (registry != null) registry.close();
        }
    }
View Full Code Here

    }

    @Test
    public void testUnregisterAndReregisterService() throws IOException, InterruptedException {
        System.out.println("Unit Test: testUnregisterAndReregisterService()");
        JmDNS registry = null;
        try {
            registry = JmDNS.create();
            registry.registerService(service);

            ServiceInfo[] services = registry.list(service.getType());
            assertEquals("We should see the service we just registered: ", 1, services.length);
            assertEquals(service, services[0]);

            // now unregister and make sure it's gone
            registry.unregisterService(services[0]);

            // According to the spec the record disappears from the cache 1s after it has been unregistered
            // without sleeping for a while, the service would not be unregistered fully
            Thread.sleep(1500);

            services = registry.list(service.getType());
            assertTrue("We should not see the service we just unregistered: ", services == null || services.length == 0);

            registry.registerService(service);
            Thread.sleep(5000);
            services = registry.list(service.getType());
            assertTrue("We should see the service we just reregistered: ", services != null && services.length > 0);
        } finally {
            if (registry != null) registry.close();
        }
    }
View Full Code Here

    }

    @Test
    public void testQueryMyService() throws IOException {
        System.out.println("Unit Test: testQueryMyService()");
        JmDNS registry = null;
        try {
            registry = JmDNS.create();
            registry.registerService(service);
            ServiceInfo queriedService = registry.getServiceInfo(service.getType(), service.getName());
            assertEquals(service, queriedService);
        } finally {
            if (registry != null) registry.close();
        }
    }
View Full Code Here

TOP

Related Classes of javax.jmdns.JmDNS$Delegate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.