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


Java ServiceListener類代碼示例

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


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

示例1: testStopZeroConfService

import javax.jmdns.ServiceListener; //導入依賴的package包/類
@Test
public void testStopZeroConfService() throws Exception {
    // Test Desc. : Verify if on stop() of ZeroConfDiscoveryProvider
    // Service, implicitly invoke the removeServiceListener() on JmDns
    // instance,

    DiscoveryFilter filter = new DiscoveryFilter("Apple TV", "_testservicetype._tcp.local.");
    dp.serviceFilters.add(filter);

    ServiceListener listener = dp.jmdnsListener;

    verify(mDNS, Mockito.never()).removeServiceListener(
            filter.getServiceFilter(), listener);
    dp.stop();
    verify(mDNS, Mockito.times(1)).removeServiceListener(
            filter.getServiceFilter(), listener);
}
 
開發者ID:david-fenton,項目名稱:Connect-SDK-Cordova-Plugin,代碼行數:18,代碼來源:ZeroConfDiscoveryPrividerTest.java

示例2: JmmDNSImpl

import javax.jmdns.ServiceListener; //導入依賴的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.ServiceListener; //導入依賴的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.ServiceListener; //導入依賴的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: JmmDNSImpl

import javax.jmdns.ServiceListener; //導入依賴的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

示例6: addServiceListener

import javax.jmdns.ServiceListener; //導入依賴的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

示例7: removeServiceListener

import javax.jmdns.ServiceListener; //導入依賴的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

示例8: removeServiceListener

import javax.jmdns.ServiceListener; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void removeServiceListener(String type, ServiceListener listener)
{
    String aType = type.toLowerCase();
    List<ServiceListenerStatus> list = _serviceListeners.get(aType);
    if (list != null)
    {
        synchronized (list)
        {
            ServiceListenerStatus status = new ServiceListenerStatus(listener);
            list.remove(status);
            if (list.isEmpty())
            {
                _serviceListeners.remove(aType, list);
            }
        }
    }
}
 
開發者ID:blackshadowwalker,項目名稱:log4j-collector,代碼行數:22,代碼來源:JmDNSImpl.java

示例9: setup

import javax.jmdns.ServiceListener; //導入依賴的package包/類
@Before
public void setup() {
    boolean log = false;
    if (log) {
        ConsoleHandler handler = new ConsoleHandler();
        handler.setLevel(Level.FINEST);
        for (Enumeration<String> enumerator = LogManager.getLogManager().getLoggerNames(); enumerator.hasMoreElements();) {
            String loggerName = enumerator.nextElement();
            Logger logger = Logger.getLogger(loggerName);
            logger.addHandler(handler);
            logger.setLevel(Level.FINEST);
        }
    }

    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);
    typeListenerMock = createMock(ServiceTypeListener.class);
    serviceListenerMock = createNiceMock("ServiceListener", ServiceListener.class);
}
 
開發者ID:josephw,項目名稱:jmdns,代碼行數:22,代碼來源:JmmDNSTest.java

示例10: addServiceListener

import javax.jmdns.ServiceListener; //導入依賴的package包/類
private void addServiceListener(String type, ServiceListener listener, boolean synch) {
    ServiceListenerStatus status = new ServiceListenerStatus(listener, synch);
    final String loType = type.toLowerCase();
    List<ServiceListenerStatus> list = _serviceListeners.get(loType);
    if (list == null) {
        if (_serviceListeners.putIfAbsent(loType, new LinkedList<ServiceListenerStatus>()) == null) {
            if (_serviceCollectors.putIfAbsent(loType, new ServiceCollector(type)) == null) {
                // We have a problem here. The service collectors must be called synchronously so that their cache get cleaned up immediately or we will report .
                this.addServiceListener(loType, _serviceCollectors.get(loType), ListenerStatus.SYNCHONEOUS);
            }
        }
        list = _serviceListeners.get(loType);
    }
    if (list != null) {
        synchronized (list) {
            if (!list.contains(listener)) {
                list.add(status);
            }
        }
    }
    // report cached service types
    final List<ServiceEvent> serviceEvents = new ArrayList<ServiceEvent>();
    Collection<DNSEntry> dnsEntryLits = this.getCache().allValues();
    for (DNSEntry entry : dnsEntryLits) {
        final DNSRecord record = (DNSRecord) entry;
        if (record.getRecordType() == DNSRecordType.TYPE_SRV) {
            if (record.getKey().endsWith(loType)) {
                // Do not used the record embedded method for generating event this will not work.
                // serviceEvents.add(record.getServiceEvent(this));
                serviceEvents.add(new ServiceEventImpl(this, record.getType(), toUnqualifiedName(record.getType(), record.getName()), record.getServiceInfo()));
            }
        }
    }
    // Actually call listener with all service events added above
    for (ServiceEvent serviceEvent : serviceEvents) {
        status.serviceAdded(serviceEvent);
    }
    // Create/start ServiceResolver
    this.startServiceResolver(type);
}
 
開發者ID:iilxy,項目名稱:AndroidmDNS,代碼行數:41,代碼來源:JmDNSImpl.java

示例11: removeServiceListener

import javax.jmdns.ServiceListener; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void removeServiceListener(String type, ServiceListener listener) {
    String loType = type.toLowerCase();
    List<ServiceListenerStatus> list = _serviceListeners.get(loType);
    if (list != null) {
        synchronized (list) {
            ServiceListenerStatus status = new ServiceListenerStatus(listener, ListenerStatus.ASYNCHONEOUS);
            list.remove(status);
            if (list.isEmpty()) {
                _serviceListeners.remove(loType, list);
            }
        }
    }
}
 
開發者ID:iilxy,項目名稱:AndroidmDNS,代碼行數:18,代碼來源:JmDNSImpl.java

示例12: addServiceListener

import javax.jmdns.ServiceListener; //導入依賴的package包/類
@Override
public void addServiceListener(String type, ServiceListener listener)
{
    for (JmDNS mDNS : _knownMDNS.values())
    {
        mDNS.addServiceListener(type, listener);
    }
}
 
開發者ID:blackshadowwalker,項目名稱:log4j-collector,代碼行數:9,代碼來源:JmmDNSImpl.java

示例13: removeServiceListener

import javax.jmdns.ServiceListener; //導入依賴的package包/類
@Override
public void removeServiceListener(String type, ServiceListener listener)
{
    for (JmDNS mDNS : _knownMDNS.values())
    {
        mDNS.removeServiceListener(type, listener);
    }
}
 
開發者ID:blackshadowwalker,項目名稱:log4j-collector,代碼行數:9,代碼來源:JmmDNSImpl.java

示例14: addServiceListener

import javax.jmdns.ServiceListener; //導入依賴的package包/類
private void addServiceListener(final String type, final ServiceListener listener, final boolean synch) {
    final ServiceListenerStatus status = new ServiceListenerStatus(listener, synch);
    final String loType = type.toLowerCase();
    List<ServiceListenerStatus> list = this._serviceListeners.get(loType);
    if (list == null) {
        if (this._serviceListeners.putIfAbsent(loType, new LinkedList<ServiceListenerStatus>()) == null) {
            if (this._serviceCollectors.putIfAbsent(loType, new ServiceCollector(type)) == null) {
                // We have a problem here. The service collectors must be called synchronously so that their cache get cleaned up immediately or we will report .
                this.addServiceListener(loType, this._serviceCollectors.get(loType), ListenerStatus.SYNCHONEOUS);
            }
        }
        list = this._serviceListeners.get(loType);
    }
    if (list != null) {
        synchronized (list) {
            if (!list.contains(listener)) {
                list.add(status);
            }
        }
    }
    // report cached service types
    final List<ServiceEvent> serviceEvents = new ArrayList<ServiceEvent>();
    final Collection<DNSEntry> dnsEntryLits = this.getCache().allValues();
    for (final DNSEntry entry : dnsEntryLits) {
        final DNSRecord record = (DNSRecord) entry;
        if (record.getRecordType() == DNSRecordType.TYPE_SRV) {
            if (record.getKey().endsWith(loType)) {
                // Do not used the record embedded method for generating event this will not work.
                // serviceEvents.add(record.getServiceEvent(this));
                serviceEvents.add(new ServiceEventImpl(this, record.getType(), toUnqualifiedName(record.getType(), record.getName()), record.getServiceInfo()));
            }
        }
    }
    // Actually call listener with all service events added above
    for (final ServiceEvent serviceEvent : serviceEvents) {
        status.serviceAdded(serviceEvent);
    }
    // Create/start ServiceResolver
    this.startServiceResolver(type);
}
 
開發者ID:mwaylabs,項目名稱:JmDNS,代碼行數:41,代碼來源:JmDNSImpl.java

示例15: removeServiceListener

import javax.jmdns.ServiceListener; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void removeServiceListener(final String type, final ServiceListener listener) {
    final String loType = type.toLowerCase();
    final List<ServiceListenerStatus> list = this._serviceListeners.get(loType);
    if (list != null) {
        synchronized (list) {
            final ServiceListenerStatus status = new ServiceListenerStatus(listener, ListenerStatus.ASYNCHONEOUS);
            list.remove(status);
            if (list.isEmpty()) {
                this._serviceListeners.remove(loType, list);
            }
        }
    }
}
 
開發者ID:mwaylabs,項目名稱:JmDNS,代碼行數:18,代碼來源:JmDNSImpl.java


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