当前位置: 首页>>代码示例>>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;未经允许,请勿转载。