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


Java JmDNS類代碼示例

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


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

示例1: getServiceInfos

import javax.jmdns.JmDNS; //導入依賴的package包/類
@Override
public ServiceInfo[] getServiceInfos(final String type, final String name, final boolean persistent, final long timeout) {
    // We need to run this in parallel to respect the timeout.
    final Set<ServiceInfo> result = Collections.synchronizedSet(new HashSet<ServiceInfo>(_knownMDNS.size()));
    ExecutorService executor = Executors.newCachedThreadPool();
    for (final JmDNS mDNS : _knownMDNS.values()) {
        executor.submit(new Runnable() {
            /**
             * {@inheritDoc}
             */
            @Override
            public void run() {
                result.add(mDNS.getServiceInfo(type, name, persistent, timeout));
            }
        });
    }
    executor.shutdown();
    try {
        executor.awaitTermination(timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException exception) {
        logger.log(Level.WARNING, "Exception ", exception);
    }
    return result.toArray(new ServiceInfo[result.size()]);
}
 
開發者ID:DeviceConnect,項目名稱:DeviceConnect-Android,代碼行數:25,代碼來源:JmmDNSImpl.java

示例2: JmmDNSImpl

import javax.jmdns.JmDNS; //導入依賴的package包/類
/**
 *
 */
public JmmDNSImpl() {
    super();
    _networkListeners = Collections.synchronizedSet(new HashSet<NetworkTopologyListener>());
    _knownMDNS = new ConcurrentHashMap<InetAddress, JmDNS>();
    _services = new ConcurrentHashMap<String, ServiceInfo>(20);
    _ListenerExecutor = Executors.newSingleThreadExecutor();
    _jmDNSExecutor = Executors.newCachedThreadPool();
    _timer = new Timer("Multihommed mDNS.Timer", true);
    _serviceListeners = new ConcurrentHashMap<String, List<ServiceListener>>();
    _typeListeners = Collections.synchronizedSet(new HashSet<ServiceTypeListener>());
    _serviceTypes = Collections.synchronizedSet(new HashSet<String>());
    (new NetworkChecker(this, NetworkTopologyDiscovery.Factory.getInstance())).start(_timer);
    _isClosing = new AtomicBoolean(false);
    _closed = new AtomicBoolean(false);
}
 
開發者ID:iilxy,項目名稱:AndroidmDNS,代碼行數:19,代碼來源:JmmDNSImpl.java

示例3: addServiceListener

import javax.jmdns.JmDNS; //導入依賴的package包/類
@Override
public void addServiceListener(String type, ServiceListener listener) {
    final String loType = type.toLowerCase();
    List<ServiceListener> list = _serviceListeners.get(loType);
    if (list == null) {
        _serviceListeners.putIfAbsent(loType, new LinkedList<ServiceListener>());
        list = _serviceListeners.get(loType);
    }
    if (list != null) {
        synchronized (list) {
            if (!list.contains(listener)) {
                list.add(listener);
            }
        }
    }
    for (JmDNS mDNS : _knownMDNS.values()) {
        mDNS.addServiceListener(type, listener);
    }
}
 
開發者ID:iilxy,項目名稱:AndroidmDNS,代碼行數:20,代碼來源:JmmDNSImpl.java

示例4: removeServiceListener

import javax.jmdns.JmDNS; //導入依賴的package包/類
@Override
public void removeServiceListener(String type, ServiceListener listener) {
    String loType = type.toLowerCase();
    List<ServiceListener> list = _serviceListeners.get(loType);
    if (list != null) {
        synchronized (list) {
            list.remove(listener);
            if (list.isEmpty()) {
                _serviceListeners.remove(loType, list);
            }
        }
    }
    for (JmDNS mDNS : _knownMDNS.values()) {
        mDNS.removeServiceListener(type, listener);
    }
}
 
開發者ID:iilxy,項目名稱:AndroidmDNS,代碼行數:17,代碼來源:JmmDNSImpl.java

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

示例6: listServices

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

        // The member variable is likely to get set to null if a swap process starts, thus we hold
        // a reference for the benefit of the background task so it doesn't have to synchronoize on it.
        final JmDNS mdns = jmdns;

        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                Utils.debugLog(TAG, "Explicitly querying for services, in addition to waiting for notifications.");
                addFDroidServices(mdns.list(HTTP_SERVICE_TYPE));
                addFDroidServices(mdns.list(HTTPS_SERVICE_TYPE));
                return null;
            }
        }.execute();
    }
 
開發者ID:nutellarlz,項目名稱:AppHub,代碼行數:18,代碼來源:BonjourFinder.java

示例7: serviceAdded

import javax.jmdns.JmDNS; //導入依賴的package包/類
@Override
public void serviceAdded(final ServiceEvent event) {
    // TODO: Get clarification, but it looks like this is:
    //   1) Identifying that there is _a_ bonjour service available
    //   2) Adding it to the list to give some sort of feedback to the user
    //   3) Requesting more detailed info in an async manner
    //   4) If that is in fact an fdroid repo (after requesting info), then add it again
    //      so that more detailed info can be shown to the user.
    //
    //    If so, when is the old one removed?
    addFDroidService(event.getInfo());

    // The member variable is likely to get set to null if a swap process starts, thus we hold
    // a reference for the benefit of the background task so it doesn't have to synchronoize on it.
    final JmDNS mdns = jmdns;
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            mdns.requestServiceInfo(event.getType(), event.getName(), true);
            return null;
        }
    }.execute();
}
 
開發者ID:nutellarlz,項目名稱:AppHub,代碼行數:24,代碼來源:BonjourFinder.java

示例8: list

import javax.jmdns.JmDNS; //導入依賴的package包/類
@Override
public ServiceInfo[] list(final String type, final long timeout) {
    // We need to run this in parallel to respect the timeout.
    final Set<ServiceInfo> result = Collections.synchronizedSet(new HashSet<ServiceInfo>(_knownMDNS.size() * 5));
    ExecutorService executor = Executors.newCachedThreadPool();
    for (final JmDNS mDNS : _knownMDNS.values()) {
        executor.submit(new Runnable() {
            /**
             * {@inheritDoc}
             */
            @Override
            public void run() {
                result.addAll(Arrays.asList(mDNS.list(type, timeout)));
            }
        });
    }
    executor.shutdown();
    try {
        executor.awaitTermination(timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException exception) {
        logger.log(Level.WARNING, "Exception ", exception);
    }
    return result.toArray(new ServiceInfo[result.size()]);
}
 
開發者ID:DeviceConnect,項目名稱:DeviceConnect-Android,代碼行數:25,代碼來源:JmmDNSImpl.java

示例9: inetAddressAdded

import javax.jmdns.JmDNS; //導入依賴的package包/類
@Override
public void inetAddressAdded(NetworkTopologyEvent event) {
    InetAddress address = event.getInetAddress();
    try {
        synchronized (this) {
            if (!_knownMDNS.containsKey(address)) {
                _knownMDNS.put(address, JmDNS.create(address));
                final NetworkTopologyEvent jmdnsEvent = new NetworkTopologyEventImpl(_knownMDNS.get(address), 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:DeviceConnect,項目名稱:DeviceConnect-Android,代碼行數:26,代碼來源:JmmDNSImpl.java

示例10: JmmDNSImpl

import javax.jmdns.JmDNS; //導入依賴的package包/類
/**
 *
 */
public JmmDNSImpl() {
    super();
    _networkListeners = Collections.synchronizedSet(new HashSet<NetworkTopologyListener>());
    _knownMDNS = new ConcurrentHashMap<InetAddress, JmDNS>();
    _services = new ConcurrentHashMap<String, ServiceInfo>(20);
    _listenerExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("JmmDNS Listeners"));
    _jmDNSExecutor = Executors.newCachedThreadPool(new NamedThreadFactory("JmmDNS"));
    _timer = new Timer("Multihomed mDNS.Timer", true);
    _serviceListeners = new ConcurrentHashMap<String, List<ServiceListener>>();
    _typeListeners = Collections.synchronizedSet(new HashSet<ServiceTypeListener>());
    _serviceTypes = Collections.synchronizedSet(new HashSet<String>());
    (new NetworkChecker(this, NetworkTopologyDiscovery.Factory.getInstance())).start(_timer);
    _isClosing = new AtomicBoolean(false);
    _closed = new AtomicBoolean(false);
}
 
開發者ID:JMRI,項目名稱:EngineDriver,代碼行數:19,代碼來源:JmmDNSImpl.java

示例11: addServiceListener

import javax.jmdns.JmDNS; //導入依賴的package包/類
@Override
public void addServiceListener(String type, ServiceListener listener) {
    final String loType = type.toLowerCase();
    List<ServiceListener> list = _serviceListeners.get(loType);
    if (list == null) {
        _serviceListeners.putIfAbsent(loType, new LinkedList<ServiceListener>());
        list = _serviceListeners.get(loType);
    }
    if (list != null) {
        synchronized (list) {
            if (!list.contains(listener)) {
                list.add(listener);
            }
        }
    }
    for (JmDNS mDNS : this.getDNS()) {
        mDNS.addServiceListener(type, listener);
    }
}
 
開發者ID:JMRI,項目名稱:EngineDriver,代碼行數:20,代碼來源:JmmDNSImpl.java

示例12: removeServiceListener

import javax.jmdns.JmDNS; //導入依賴的package包/類
@Override
public void removeServiceListener(String type, ServiceListener listener) {
    String loType = type.toLowerCase();
    List<ServiceListener> list = _serviceListeners.get(loType);
    if (list != null) {
        synchronized (list) {
            list.remove(listener);
            if (list.isEmpty()) {
                _serviceListeners.remove(loType, list);
            }
        }
    }
    for (JmDNS mDNS : this.getDNS()) {
        mDNS.removeServiceListener(type, listener);
    }
}
 
開發者ID:JMRI,項目名稱:EngineDriver,代碼行數:17,代碼來源:JmmDNSImpl.java

示例13: requestServiceInfo

import javax.jmdns.JmDNS; //導入依賴的package包/類
@Override
public void requestServiceInfo(final String type, final String name, final boolean persistent, final long timeout)
{
    // We need to run this in parallel to respect the timeout.
    for (final JmDNS mDNS : _knownMDNS.values())
    {
        _jmDNSExecutor.submit(new Runnable() {
            /**
             * {@inheritDoc}
             */
            @Override
            public void run()
            {
                mDNS.requestServiceInfo(type, name, persistent, timeout);
            }
        });
    }
}
 
開發者ID:blackshadowwalker,項目名稱:log4j-collector,代碼行數:19,代碼來源:JmmDNSImpl.java

示例14: textValueUpdated

import javax.jmdns.JmDNS; //導入依賴的package包/類
@Override
public void textValueUpdated(ServiceInfo target, byte[] value)
{
    synchronized (_services)
    {
        for (JmDNS mDNS : _knownMDNS.values())
        {
            ServiceInfo info = ((JmDNSImpl) mDNS).getServices().get(target.getQualifiedName());
            if (info != null)
            {
                info.setText(value);
            }
            else
            {
                logger.warning("We have a mDNS that does not know about the service info being updated.");
            }
        }
    }
}
 
開發者ID:blackshadowwalker,項目名稱:log4j-collector,代碼行數:20,代碼來源:JmmDNSImpl.java

示例15: register

import javax.jmdns.JmDNS; //導入依賴的package包/類
public ServiceInfo register(String type, String domain, String name, int port, JSONObject props) throws JSONException, IOException {

            HashMap<String, String> txtRecord = new HashMap<String, String>();
            if (props != null) {
                Iterator<String> iter = props.keys();
                while (iter.hasNext()) {
                    String key = iter.next();
                    txtRecord.put(key, props.getString(key));
                }
            }

            ServiceInfo aService = null;
            for (JmDNS publisher : publishers) {
                ServiceInfo service = ServiceInfo.create(type + domain, name, port, 0, 0, txtRecord);
                try {
                    publisher.registerService(service);
                    aService = service;
                } catch (IOException e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }
            // returns only one of the ServiceInfo instances!
            return aService;
        }
 
開發者ID:becvert,項目名稱:cordova-plugin-zeroconf,代碼行數:25,代碼來源:ZeroConf.java


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