当前位置: 首页>>代码示例>>Java>>正文


Java JmDNS.close方法代码示例

本文整理汇总了Java中javax.jmdns.JmDNS.close方法的典型用法代码示例。如果您正苦于以下问题:Java JmDNS.close方法的具体用法?Java JmDNS.close怎么用?Java JmDNS.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jmdns.JmDNS的用法示例。


在下文中一共展示了JmDNS.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: inetAddressRemoved

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Override
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}
                         */
                        @Override
                        public void run() {
                            listener.inetAddressRemoved(jmdnsEvent);
                        }
                    });
                }
            }
        }
    } catch (Exception e) {
        logger.warning("Unexpected unhandled exception: " + e);
    }
}
 
开发者ID:iilxy,项目名称:AndroidmDNS,代码行数:27,代码来源:JmmDNSImpl.java

示例2: testRegisterServiceTwice

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@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();
    }
}
 
开发者ID:DrivenLogic,项目名称:droid-holiday,代码行数:17,代码来源:JmDNSTest.java

示例3: search

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
/**
 * Search for airplay devices within the given timeout, in ms.
 */
public List<AirPlay> search(int timeout) throws IOException {
    JmDNS jmdns = JmDNS.create(InetAddress.getByName("0.0.0.0"), null);
    ServiceInfo[] services = jmdns.list(DNSSD_TYPE, timeout);

    List<AirPlay> airplays = new ArrayList<AirPlay>();
    for(int i = 0; i < services.length; i++) {
        ServiceInfo service = services[i];
        Inet4Address[] addresses = service.getInet4Addresses();
        if(addresses.length >= 1) {
            airplays.add(new AirPlay(service.getName(),
                        addresses[0].getHostAddress(),
                        service.getPort()));
        }
    }
    jmdns.close();
    return airplays;
}
 
开发者ID:bvargo,项目名称:airplay,代码行数:21,代码来源:AirPlayFinder.java

示例4: main

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
/**
 * @param args
 *            the command line arguments
 */
public static void main(String[] args) {
    /*
     * Activate these lines to see log messages of JmDNS Logger logger = Logger.getLogger(JmDNS.class.getName()); ConsoleHandler handler = new ConsoleHandler(); logger.addHandler(handler); logger.setLevel(Level.FINER);
     * handler.setLevel(Level.FINER);
     */

    try {
        JmDNS jmdns = JmDNS.create();
        jmdns.addServiceTypeListener(new SampleListener());

        System.out.println("Press q and Enter, to quit");
        int b;
        while ((b = System.in.read()) != -1 && (char) b != 'q') {
            /* Stub */
        }
        jmdns.close();
        System.out.println("Done");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:26,代码来源:DiscoverServiceTypes.java

示例5: testWaitAndQueryForServiceOnOtherRegistry

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testWaitAndQueryForServiceOnOtherRegistry() throws IOException {
    System.out.println("Unit Test: testWaitAndQueryForServiceOnOtherRegistry()");
    JmDNS registry = null;
    JmDNS newServiceRegistry = null;
    try {
        newServiceRegistry = JmDNS.create();
        registry = JmDNS.create();

        registry.registerService(service);

        ServiceInfo fetchedService = newServiceRegistry.getServiceInfo(service.getType(), service.getName());

        assertEquals("Did not get the expected service info: ", service, fetchedService);
    } finally {
        if (registry != null) registry.close();
        if (newServiceRegistry != null) newServiceRegistry.close();
    }
}
 
开发者ID:DrivenLogic,项目名称:droid-holiday,代码行数:20,代码来源:JmDNSTest.java

示例6: testUnregisterService

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@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();
    }
}
 
开发者ID:DrivenLogic,项目名称:droid-holiday,代码行数:26,代码来源:JmDNSTest.java

示例7: inetAddressRemoved

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Override
public void inetAddressRemoved(NetworkTopologyEvent event) {
    InetAddress address = event.getInetAddress();
    try {
        if (_knownMDNS.containsKey(address)) {
            synchronized (_knownMDNS) {
                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}
                             */
                            @Override
                            public void run() {
                                listener.inetAddressRemoved(jmdnsEvent);
                            }
                        });
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.warning("Unexpected unhandled exception: " + e);
    }
}
 
开发者ID:JMRI,项目名称:EngineDriver,代码行数:29,代码来源:JmmDNSImpl.java

示例8: inetAddressRemoved

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Override
public void inetAddressRemoved(NetworkTopologyEvent event)
{
    InetAddress address = event.getInetAddress();
    try
    {
        synchronized (this)
        {
            if (_knownMDNS.containsKey(address))
            {
                JmDNS mDNS = JmDNS.create(address);
                _knownMDNS.remove(address);
                mDNS.close();
                final NetworkTopologyEvent jmdnsEvent = new NetworkTopologyEventImpl(mDNS, address);
                for (final NetworkTopologyListener listener : this.networkListeners())
                {
                    _ListenerExecutor.submit(new Runnable() {
                        /**
                         * {@inheritDoc}
                         */
                        @Override
                        public void run()
                        {
                            listener.inetAddressRemoved(jmdnsEvent);
                        }
                    });
                }
            }
        }
    }
    catch (Exception e)
    {
        logger.warning("Unexpected unhandled exception: " + e);
    }
}
 
开发者ID:blackshadowwalker,项目名称:log4j-collector,代码行数:36,代码来源:JmmDNSImpl.java

示例9: stop

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
public void stop() {
    if (jmdns != null) {
        for (Iterator<ServiceInfo> iter = serviceInfos.iterator(); iter.hasNext();) {
            ServiceInfo si = iter.next();
            jmdns.unregisterService(si);
        }

        // Close it down async since this could block for a while.
        final JmDNS closeTarget = jmdns;
        Thread thread = new Thread() {
            public void run() {
                try {
                    if (JmDNSFactory.onClose(getLocalAddress())) {
                        closeTarget.close();
                    };
                } catch (IOException e) {
                    LOG.debug("Error closing JmDNS " + getLocalhost() + ". This exception will be ignored.", e);
                }
            }
        };

        thread.setDaemon(true);
        thread.start();

        jmdns = null;
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:28,代码来源:ZeroconfDiscoveryAgent.java

示例10: testListenForMyServiceAndList

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testListenForMyServiceAndList() throws IOException {
    System.out.println("Unit Test: testListenForMyServiceAndList()");
    JmDNS registry = null;
    try {
        Capture<ServiceEvent> capServiceAddedEvent = new Capture<ServiceEvent>();
        Capture<ServiceEvent> capServiceResolvedEvent = new Capture<ServiceEvent>();
        // Expect the listener to be called once and capture the result
        serviceListenerMock.serviceAdded(capture(capServiceAddedEvent));
        serviceListenerMock.serviceResolved(capture(capServiceResolvedEvent));
        replay(serviceListenerMock);

        registry = JmDNS.create();
        registry.addServiceListener(service.getType(), serviceListenerMock);
        registry.registerService(service);

        // We get the service added event when we register the service. However the service has not been resolved at this point.
        // The info associated with the event only has the minimum information i.e. name and type.
        assertTrue("We did not get the service added event.", capServiceAddedEvent.hasCaptured());

        ServiceInfo info = capServiceAddedEvent.getValue().getInfo();
        assertEquals("We did not get the right name for the resolved service:", service.getName(), info.getName());
        assertEquals("We did not get the right type for the resolved service:", service.getType(), info.getType());

        // This will force the resolution of the service which in turn will get the listener called with a service resolved event.
        // The info associated with a service resolved event has all the information available.
        // Which in turn populates the ServiceInfo opbjects returned by JmDNS.list.
        ServiceInfo[] services = registry.list(info.getType());
        assertEquals("We did not get the expected number of services: ", 1, services.length);
        assertEquals("The service returned was not the one expected", service, services[0]);

        assertTrue("We did not get the service resolved event.", capServiceResolvedEvent.hasCaptured());
        verify(serviceListenerMock);
        ServiceInfo resolvedInfo = capServiceResolvedEvent.getValue().getInfo();
        assertEquals("Did not get the expected service info: ", service, resolvedInfo);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:40,代码来源:JmDNSTest.java

示例11: testRegisterAndListServiceOnOtherRegistry

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testRegisterAndListServiceOnOtherRegistry() throws IOException, InterruptedException {
    System.out.println("Unit Test: testRegisterAndListServiceOnOtherRegistry()");
    JmDNS registry = null;
    JmDNS newServiceRegistry = null;
    try {
        registry = JmDNS.create("Registry");
        registry.registerService(service);

        newServiceRegistry = JmDNS.create("Listener");
        Thread.sleep(6000);
        ServiceInfo[] fetchedServices = newServiceRegistry.list(service.getType());
        assertEquals("Did not get the expected services listed:", 1, fetchedServices.length);
        assertEquals("Did not get the expected service type:", service.getType(), fetchedServices[0].getType());
        assertEquals("Did not get the expected service name:", service.getName(), fetchedServices[0].getName());
        assertEquals("Did not get the expected service fully qualified name:", service.getQualifiedName(), fetchedServices[0].getQualifiedName());
        newServiceRegistry.getServiceInfo(service.getType(), service.getName());

        assertEquals("Did not get the expected service info: ", service, fetchedServices[0]);
        registry.close();
        registry = null;
        // 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);
        fetchedServices = newServiceRegistry.list(service.getType());
        assertEquals("The service was not cancelled after the close:", 0, fetchedServices.length);
    } finally {
        if (registry != null) registry.close();
        if (newServiceRegistry != null) newServiceRegistry.close();
    }
}
 
开发者ID:DrivenLogic,项目名称:droid-holiday,代码行数:32,代码来源:JmDNSTest.java

示例12: testListMyServiceWithToLowerCase

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testListMyServiceWithToLowerCase() throws IOException, InterruptedException {
    System.out.println("Unit Test: testListMyServiceWithToLowerCase()");
    String text = "Test hypothetical web server";
    Map<String, byte[]> properties = new HashMap<String, byte[]>();
    properties.put(serviceKey, text.getBytes());
    service = ServiceInfo.create("_HtmL._TcP.lOcAl.", "apache-someUniqueid", 80, 0, 0, true, properties);
    JmDNS registry = null;
    try {
        registry = JmDNS.create();
        registry.registerService(service);

        // with toLowerCase
        ServiceInfo[] services = registry.list(service.getType().toLowerCase());
        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().toLowerCase());
        assertTrue("We should not see the service we just unregistered: ", services == null || services.length == 0);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:28,代码来源:JmDNSTest.java

示例13: testRegisterService

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@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();
    }
}
 
开发者ID:DrivenLogic,项目名称:droid-holiday,代码行数:12,代码来源:JmDNSTest.java

示例14: testListMyServiceWithoutLowerCase

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testListMyServiceWithoutLowerCase() throws IOException, InterruptedException {
    System.out.println("Unit Test: testListMyServiceWithoutLowerCase()");
    String text = "Test hypothetical web server";
    Map<String, byte[]> properties = new HashMap<String, byte[]>();
    properties.put(serviceKey, text.getBytes());
    service = ServiceInfo.create("_HtmL._TcP.lOcAl.", "apache-someUniqueid", 80, 0, 0, true, properties);
    JmDNS registry = null;
    try {
        registry = JmDNS.create();
        registry.registerService(service);

        // without toLowerCase
        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();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:28,代码来源:JmDNSTest.java

示例15: testRegisterService

import javax.jmdns.JmDNS; //导入方法依赖的package包/类
@Test
public void testRegisterService() throws IOException {
    System.out.println("Unit Test: testRegisterService()");
    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]);
    } finally {
        if (registry != null) registry.close();
    }
}
 
开发者ID:josephw,项目名称:jmdns,代码行数:16,代码来源:JmDNSTest.java


注:本文中的javax.jmdns.JmDNS.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。