@Override public @Nullable Collection<ThingUID> run() { return listener.removeOlderResults(source, timestamp, thingTypeUIDs, bridgeUID); } });
@Override public @Nullable Void run() { listener.thingDiscovered(source, result); return null; } });
@Override public @Nullable Void run() { listener.thingRemoved(source, thingUID); return null; } });
@Override public @Nullable Void run() { listener.thingDiscovered(source, result); return null; } });
@Override public @Nullable Collection<ThingUID> run() { return listener.removeOlderResults(source, timestamp, thingTypeUIDs); } });
@Override public @Nullable Void run() { listener.thingRemoved(source, thingUID); return null; } });
@Override public void addDiscoveryListener(@Nullable DiscoveryListener listener) { if (listener == null) { return; } synchronized (cachedResults) { for (DiscoveryResult cachedResult : cachedResults.values()) { listener.thingDiscovered(this, cachedResult); } } discoveryListeners.add(listener); }
/** * Removes all results belonging to one of the given types that are older * than the given timestamp. * * @param source the discovery service which is the source of this event (not * null) * @param timestamp timestamp, all <b>older</b> results will be removed * @param thingTypeUIDs collection of {@code ThingType}s, only results of these * {@code ThingType}s will be removed; if {@code null} then * {@link DiscoveryService#getSupportedThingTypes()} will be used * instead * @return collection of thing UIDs of all removed things * @deprecated use {@link #removeOlderResults(DiscoveryService, long, Collection, ThingUID)} instead */ @Deprecated @Nullable default Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, @Nullable Collection<ThingTypeUID> thingTypeUIDs) { return removeOlderResults(source, timestamp, thingTypeUIDs, null); }
/** * Notifies the registered {@link DiscoveryListener}s about a removed device. * * @param thingUID * The UID of the removed thing. */ protected void thingRemoved(ThingUID thingUID) { for (DiscoveryListener discoveryListener : discoveryListeners) { try { discoveryListener.thingRemoved(this, thingUID); } catch (Exception e) { logger.error("An error occurred while calling the discovery listener {}.", discoveryListener.getClass().getName(), e); } } synchronized (cachedResults) { cachedResults.remove(thingUID); } }
@Override public void addDiscoveryListener(@Nullable DiscoveryListener listener) { if (listener == null) { return; } synchronized (cachedResults) { for (DiscoveryResult cachedResult : cachedResults.values()) { listener.thingDiscovered(this, cachedResult); } } discoveryListeners.add(listener); }
for (DiscoveryListener discoveryListener : discoveryListeners) { try { removedThings = discoveryListener.removeOlderResults(this, timestamp, toBeRemoved); } catch (Exception e) { logger.error("An error occurred while calling the discovery listener {}.",
/** * Notifies the registered {@link DiscoveryListener}s about a removed device. * * @param thingUID The UID of the removed thing. */ protected void thingRemoved(ThingUID thingUID) { for (DiscoveryListener discoveryListener : discoveryListeners) { try { discoveryListener.thingRemoved(this, thingUID); } catch (Exception e) { logger.error("An error occurred while calling the discovery listener {}.", discoveryListener.getClass().getName(), e); } } synchronized (cachedResults) { cachedResults.remove(thingUID); } }
@Override public void addDiscoveryListener(DiscoveryListener listener) throws IllegalStateException { synchronized (cachedResults) { cachedResults.forEach((service, results) -> { results.forEach(result -> listener.thingDiscovered(service, result)); }); } this.listeners.add(listener); }
for (DiscoveryListener discoveryListener : discoveryListeners) { try { removedThings = discoveryListener.removeOlderResults(this, timestamp, toBeRemoved, bridgeUID); } catch (Exception e) { logger.error("An error occurred while calling the discovery listener {}.",
@Override public void addDiscoveryListener(DiscoveryListener listener) throws IllegalStateException { synchronized (cachedResults) { Set<Entry<DiscoveryService, DiscoveryResult>> entries = cachedResults.entries(); for (Entry<DiscoveryService, DiscoveryResult> entry : entries) { listener.thingDiscovered(entry.getKey(), entry.getValue()); } } this.listeners.add(listener); }
/** * Notifies the registered {@link DiscoveryListener}s about a discovered device. * * @param discoveryResult Holds the information needed to identify the discovered device. */ protected void thingDiscovered(final DiscoveryResult discoveryResult) { final DiscoveryResult discoveryResultNew; if (this.i18nProvider != null && this.localeProvider != null) { Bundle bundle = FrameworkUtil.getBundle(this.getClass()); String defaultLabel = discoveryResult.getLabel(); String key = I18nUtil.stripConstantOr(defaultLabel, () -> inferKey(discoveryResult, "label")); String label = this.i18nProvider.getText(bundle, key, defaultLabel, this.localeProvider.getLocale()); discoveryResultNew = new DiscoveryResultImpl(discoveryResult.getThingTypeUID(), discoveryResult.getThingUID(), discoveryResult.getBridgeUID(), discoveryResult.getProperties(), discoveryResult.getRepresentationProperty(), label, discoveryResult.getTimeToLive()); } else { discoveryResultNew = discoveryResult; } for (DiscoveryListener discoveryListener : discoveryListeners) { try { discoveryListener.thingDiscovered(this, discoveryResultNew); } catch (Exception e) { logger.error("An error occurred while calling the discovery listener {}.", discoveryListener.getClass().getName(), e); } } synchronized (cachedResults) { cachedResults.put(discoveryResultNew.getThingUID(), discoveryResultNew); } }
/** * Notifies the registered {@link DiscoveryListener}s about a discovered device. * * @param discoveryResult * Holds the information needed to identify the discovered device. */ protected void thingDiscovered(DiscoveryResult discoveryResult) { if (this.i18nProvider != null && this.localeProvider != null) { Bundle bundle = FrameworkUtil.getBundle(this.getClass()); String defaultLabel = discoveryResult.getLabel(); String key = I18nUtil.isConstant(defaultLabel) ? I18nUtil.stripConstant(defaultLabel) : inferKey(discoveryResult, "label"); String label = this.i18nProvider.getText(bundle, key, defaultLabel, this.localeProvider.getLocale()); discoveryResult = new DiscoveryResultImpl(discoveryResult.getThingTypeUID(), discoveryResult.getThingUID(), discoveryResult.getBridgeUID(), discoveryResult.getProperties(), discoveryResult.getRepresentationProperty(), label, discoveryResult.getTimeToLive()); } for (DiscoveryListener discoveryListener : discoveryListeners) { try { discoveryListener.thingDiscovered(this, discoveryResult); } catch (Exception e) { logger.error("An error occurred while calling the discovery listener {}.", discoveryListener.getClass().getName(), e); } } synchronized (cachedResults) { cachedResults.put(discoveryResult.getThingUID(), discoveryResult); } }