void handleServiceResolved(ServiceInfo info) { List list = (List) serviceListeners.get(info.type.toLowerCase()); if (list != null) { ServiceEvent event = new ServiceEvent(this, info.type, info.getName(), info); // Iterate on a copy in case listeners will modify it final ArrayList listCopy = new ArrayList(list); for (Iterator iterator = listCopy.iterator(); iterator.hasNext();) { ((ServiceListener) iterator.next()).serviceResolved(event); } } }
/** * Register a service type. If this service type was not already known, * all service listeners will be notified of the new service type. Service types * are automatically registered as they are discovered. */ public void registerServiceType(String type) { String name = type.toLowerCase(); if (serviceTypes.get(name) == null) { if ((type.indexOf("._mdns._udp.") < 0) && !type.endsWith(".in-addr.arpa.")) { Collection list; synchronized (this) { serviceTypes.put(name, type); list = new LinkedList(typeListeners); } for (Iterator iterator = list.iterator(); iterator.hasNext();) { ((ServiceTypeListener) iterator.next()).serviceTypeAdded(new ServiceEvent(this, type, null, null)); } } } }
/** * Listen for service types. * * @param listener listener for service types */ public void addServiceTypeListener(ServiceTypeListener listener) throws IOException { synchronized (this) { typeListeners.remove(listener); typeListeners.add(listener); } // report cached service types for (Iterator iterator = serviceTypes.values().iterator(); iterator.hasNext();) { listener.serviceTypeAdded(new ServiceEvent(this, (String) iterator.next(), null, null)); } new TypeResolver().start(); }
ServiceEvent event = new ServiceEvent(this, type, toUnqualifiedName(type, name), null); for (Iterator iterator = serviceListenerList.iterator(); iterator.hasNext();) ServiceEvent event = new ServiceEvent(this, type, toUnqualifiedName(type, name), null); for (Iterator iterator = serviceListenerList.iterator(); iterator.hasNext();)
listener.serviceAdded(new ServiceEvent(this, type, toUnqualifiedName(type, rec.name), null));