當前位置: 首頁>>代碼示例>>Java>>正文


Java JmDNS.create方法代碼示例

本文整理匯總了Java中javax.jmdns.JmDNS.create方法的典型用法代碼示例。如果您正苦於以下問題:Java JmDNS.create方法的具體用法?Java JmDNS.create怎麽用?Java JmDNS.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.jmdns.JmDNS的用法示例。


在下文中一共展示了JmDNS.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updated

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
	try {
		if (config != null) {
			String bindAddress = (String)config.get("bind_address");
			if (bindAddress != null && StringUtils.isNotBlank(bindAddress)) {
				jmdns = JmDNS.create(InetAddress.getByName(bindAddress));
				logger.info("Service Discovery initialization completed (bound to address: {}).", bindAddress);
				return;
			}
		}
		jmdns = JmDNS.create();
		logger.info("Service Discovery initialization completed.");
	} catch (IOException e) {
		logger.error(e.getMessage());
	}
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:18,代碼來源:DiscoveryServiceImpl.java

示例2: WabitSessionContextImpl

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
/**
 * Creates a new Wabit session context.
 * 
 * @param terminateWhenLastSessionCloses
 *            If this flag is true, this session context will halt the VM
 *            when its last session closes.
 * @param useJmDNS
 *            If this flag is true, then this session will create a JmDNS
 *            instance for searching for Wabit servers.
 * @param initialCollection
 *            The default collection of data sources for this context.
 * @param dataSourceCollectionPath
 *            The path to the file representing the data source collection.
 *            This will be used to write changes to the collection to save
 *            the collection's state. If this is null then no data source
 *            collection files will be modified.
 * @param writeDSCollectionPathToPrefs
 *            If true the location of the data source collection file will
 *            be saved to Java Prefs. If false the current location of the
 *            data source collection file will be left as is.
 * @throws IOException
 *             If the startup configuration files can't be read
 * @throws SQLObjectException
 *             If the pl.ini is invalid.
 */
public WabitSessionContextImpl(boolean terminateWhenLastSessionCloses, boolean useJmDNS, 
		DataSourceCollection<SPDataSource> initialCollection,
		String dataSourceCollectionPath, boolean writeDSCollectionPathToPrefs) 
		throws IOException, SQLObjectException {
	this.terminateWhenLastSessionCloses = terminateWhenLastSessionCloses;
	dataSources = initialCollection;
	this.writeDSCollectionPathToPrefs = writeDSCollectionPathToPrefs;
	setPlDotIniPath(dataSourceCollectionPath);
	
	if (useJmDNS) {
		try {
			jmdns = JmDNS.create();
		} catch (Exception e) {
			jmdns = null;
		}
	} else {
		jmdns = null;
	}
	
       try {
           manuallyConfiguredServers.addAll(readServersFromPrefs());
       } catch (BackingStoreException ex) {
           logger.error("Preferences unavailable! Not reading server infos from prefs.", ex);
       }
}
 
開發者ID:SQLPower,項目名稱:wabit,代碼行數:51,代碼來源:WabitSessionContextImpl.java

示例3: startDiscovery

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
public void startDiscovery() {
	if (isDiscovering )
		return;
	InetAddress deviceIpAddress = getDeviceIpAddress(wm);
	if (!multicastLock.isHeld()){
		multicastLock.acquire();
	} else {
		System.out.println(" Muticast lock already held...");
	}
	try {    		
		jmdns = JmDNS.create(deviceIpAddress, "SmartConfig");
		jmdns.addServiceTypeListener(this);
	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		if (jmdns != null) {
			isDiscovering = true;
			System.out.println("discovering services");
		}
	}
}
 
開發者ID:vidding,項目名稱:Cordova-Plugin-TI-WIFI,代碼行數:22,代碼來源:finddevice.java

示例4: runStartScan

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
private void runStartScan() {

        // inform the callback that we have started
        callbacklistener.scanStarted("looking for Holiday...");

        try {

            String ipAddress = new NetworkInfrastructure().getLocalInetAddress().getHostAddress();
            log.info("Local IP Address is: " + ipAddress);

            jmdns = JmDNS.create(new NetworkInfrastructure().getLocalInetAddress(), ipAddress);
            jmdns.addServiceListener(MDNS_SERVICE_TYPE, mdnsServiceListener);

        }
        catch (IOException ex) {
            ex.printStackTrace();
            log.error("Error on jmDNS setup", ex);
        }
    }
 
開發者ID:DrivenLogic,項目名稱:droid-holiday,代碼行數:20,代碼來源:MdnsScanner.java

示例5: 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

示例6: 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:josephw,項目名稱:jmdns,代碼行數:17,代碼來源:JmDNSTest.java

示例7: init

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
/**
 * Initialize and run the mDNS Service discovery. Will start advertising
 */
private void init() {
    try {
        jmDNS = JmDNS.create();
        serviceInfo = ServiceInfo.create("_http._tcp.local.",
                "Shooflers-Dashboard", port,
                "An awesome webapp to handle your monitor dashboards");
        jmDNS.registerService(serviceInfo);
    } catch (IOException e) {
        LOGGER.error("Couldn't initialize mDNS for service discovery.", e);
        throw new IllegalStateException(e);
    }
}
 
開發者ID:resourcepool,項目名稱:dashboard,代碼行數:16,代碼來源:ServiceDiscovery.java

示例8: scan

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
private void scan() {

        Utils.debugLog(TAG, "Requested Bonjour (mDNS) scan for peers.");

        if (wifiManager == null) {
            wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            mMulticastLock = wifiManager.createMulticastLock(context.getPackageName());
            mMulticastLock.setReferenceCounted(false);
        }

        if (isScanning) {
            Utils.debugLog(TAG, "Requested Bonjour scan, but already scanning. But we will still try to explicitly scan for services.");
            return;
        }

        isScanning = true;
        mMulticastLock.acquire();

        try {
            Utils.debugLog(TAG, "Searching for Bonjour (mDNS) clients...");
            jmdns = JmDNS.create(InetAddress.getByName(FDroidApp.ipAddressString));
        } catch (IOException e) {
            subscriber.onError(e);
            return;
        }

        Utils.debugLog(TAG, "Adding mDNS service listeners for " + HTTP_SERVICE_TYPE + " and " + HTTPS_SERVICE_TYPE);
        jmdns.addServiceListener(HTTP_SERVICE_TYPE, this);
        jmdns.addServiceListener(HTTPS_SERVICE_TYPE, this);
        listServices();
    }
 
開發者ID:CmDnoEdition,項目名稱:fdroid,代碼行數:32,代碼來源:BonjourFinder.java

示例9: start

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
@Override
public void start() {

    Utils.debugLog(TAG, "Preparing to start Bonjour service.");
    sendBroadcast(SwapService.EXTRA_STARTING);

    /*
     * a ServiceInfo can only be registered with a single instance
     * of JmDNS, and there is only ever a single LocalHTTPD port to
     * advertise anyway.
     */
    if (pairService != null || jmdns != null)
        clearCurrentMDNSService();
    String repoName = Preferences.get().getLocalRepoName();
    HashMap<String, String> values = new HashMap<>();
    values.put("path", "/fdroid/repo");
    values.put("name", repoName);
    values.put("fingerprint", FDroidApp.repo.fingerprint);
    String type;
    if (Preferences.get().isLocalRepoHttpsEnabled()) {
        values.put("type", "fdroidrepos");
        type = "_https._tcp.local.";
    } else {
        values.put("type", "fdroidrepo");
        type = "_http._tcp.local.";
    }
    try {
        Utils.debugLog(TAG, "Starting bonjour service...");
        pairService = ServiceInfo.create(type, repoName, FDroidApp.port, 0, 0, values);
        jmdns = JmDNS.create(InetAddress.getByName(FDroidApp.ipAddressString));
        jmdns.registerService(pairService);
        setConnected(true);
        Utils.debugLog(TAG, "... Bounjour service started.");
    } catch (IOException e) {
        Log.e(TAG, "Error while registering jmdns service", e);
        setConnected(false);
    }
}
 
開發者ID:nutellarlz,項目名稱:AppHub,代碼行數:39,代碼來源:BonjourBroadcast.java

示例10: start_jmdns

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
void start_jmdns() {
    //Set up to find a WiThrottle service via ZeroConf
    try {
        getWifiInfo();
        if (client_address != null) {
            WifiManager wifi = (WifiManager) threaded_application.this.getSystemService(Context.WIFI_SERVICE);

            if (multicast_lock == null) {  //do this only as needed
                multicast_lock = wifi.createMulticastLock("engine_driver");
                multicast_lock.setReferenceCounted(true);
            }

            Log.d("Engine_Driver", "start_jmdns: local IP addr " + client_address);

            jmdns = JmDNS.create(client_address_inet4, client_address);  //pass ip as name to avoid hostname lookup attempt

            listener = new withrottle_listener();
            Log.d("Engine_Driver", "start_jmdns: listener created");

        } else {
            show_toast_message("No local IP Address found.\nCheck your WiFi connection.", Toast.LENGTH_SHORT);
        }
    } catch (Exception except) {
        Log.e("Engine_Driver", "start_jmdns - Error creating withrottle listener: " + except.getMessage());
        show_toast_message("Error creating withrottle zeroconf listener: IOException: \n" + except.getMessage(), Toast.LENGTH_SHORT);
    }
}
 
開發者ID:JMRI,項目名稱:EngineDriver,代碼行數:28,代碼來源:threaded_application.java

示例11: inetAddressAdded

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
@Override
public void inetAddressAdded(NetworkTopologyEvent event)
{
    InetAddress address = event.getInetAddress();
    try
    {
        synchronized (this)
        {
            if (!_knownMDNS.containsKey(address))
            {
                JmDNS mDNS = JmDNS.create(address);
                _knownMDNS.put(address, mDNS);
                final NetworkTopologyEvent jmdnsEvent = new NetworkTopologyEventImpl(mDNS, address);
                for (final NetworkTopologyListener listener : this.networkListeners())
                {
                    _ListenerExecutor.submit(new Runnable() {
                        /**
                         * {@inheritDoc}
                         */
                        @Override
                        public void run()
                        {
                            listener.inetAddressAdded(jmdnsEvent);
                        }
                    });
                }
            }
        }
    }
    catch (Exception e)
    {
        logger.warning("Unexpected unhandled exception: " + e);
    }
}
 
開發者ID:blackshadowwalker,項目名稱:log4j-collector,代碼行數:35,代碼來源:JmmDNSImpl.java

示例12: 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

示例13: __discoverIOTDevices

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
private static List<IOTAddress> __discoverIOTDevices()
{
    log.debug("__discoverIOTDevices() entrance");
    try
    {
        final JmDNS mdnsService = JmDNS.create();
        log.debug("__discoverIOTDevices() JmDNS.create() finished");
        ServiceInfo[] serviceInfoArray = mdnsService.list(IOT_SERVICE_TYPE, timeout);
        List<IOTAddress> iotAddressList = __parseSeviceInfoArray2IOTAddressList(serviceInfoArray);
        // close the JmDNS asyn, for close() will take too much time, so we close it asyn
        EspBaseApiUtil.submit(new Runnable()
        {
            @Override
            public void run()
            {
                try
                {
                    mdnsService.close();
                }
                catch (IOException igrnoeException)
                {
                }
            }
        });
        return iotAddressList;
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    log.debug("__discoverIOTDevices() exit with emptyList");
    return Collections.emptyList();
}
 
開發者ID:EspressifApp,項目名稱:IOT-Espressif-Android,代碼行數:34,代碼來源:MdnsDiscoverUtil.java

示例14: create

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
static synchronized JmDNS create(final InetAddress address) throws IOException {
    UsageTracker tracker = registry.get(address);
    if (tracker == null) {
        tracker = new UsageTracker();
        tracker.jmDNS = JmDNS.create(address);
        registry.put(address, tracker);
    }
    tracker.count.incrementAndGet();
    return tracker.jmDNS;
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:11,代碼來源:JmDNSFactory.java

示例15: publishService

import javax.jmdns.JmDNS; //導入方法依賴的package包/類
@Override
public void publishService(String name, String type, int port, HashMap<String, String> values) {

    try {
        JmDNS jmDNS = JmDNS.create();
        String fullyQualitifed = type + ".local.";
        jmDNS.registerService(ServiceInfo.create(fullyQualitifed, name, port, 0, 0, values));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:crsmoro,項目名稱:scplayer,代碼行數:12,代碼來源:ZeroConfServiceJmdns.java


注:本文中的javax.jmdns.JmDNS.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。