本文整理汇总了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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}
}
示例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);
}
示例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);
}
示例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);
}
}
}
}
示例12: addServiceListener
import javax.jmdns.ServiceListener; //导入依赖的package包/类
@Override
public void addServiceListener(String type, ServiceListener listener)
{
for (JmDNS mDNS : _knownMDNS.values())
{
mDNS.addServiceListener(type, listener);
}
}
示例13: removeServiceListener
import javax.jmdns.ServiceListener; //导入依赖的package包/类
@Override
public void removeServiceListener(String type, ServiceListener listener)
{
for (JmDNS mDNS : _knownMDNS.values())
{
mDNS.removeServiceListener(type, listener);
}
}
示例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);
}
示例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);
}
}
}
}