@Override public void run() { try { stopScan(); } catch (Exception e) { logger.debug("Exception occurred during execution: {}", e.getMessage(), e); } } };
@Override @Modified protected void modified(Map<String, Object> configProperties) { super.modified(configProperties); }
@Override protected void activate(Map<String, Object> configProperties) { super.activate(configProperties); startScan(); }
/** * Called on component activation, if the implementation of this class is an * OSGi declarative service and does not override the method. The method * implementation calls {@link AbstractDiscoveryService#startBackgroundDiscovery()} if background * discovery is enabled by default and not overridden by the configuration. * * @param configProperties configuration properties */ protected void activate(@Nullable Map<String, @Nullable Object> configProperties) { if (configProperties != null) { Object property = configProperties.get(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY); if (property != null) { this.backgroundDiscoveryEnabled = getAutoDiscoveryEnabled(property); } } if (this.backgroundDiscoveryEnabled) { startBackgroundDiscovery(); logger.debug("Background discovery for discovery service '{}' enabled.", this.getClass().getName()); } }
stopScan(); if (scheduledStop != null) { scheduledStop.cancel(false); if (getScanTimeout() > 0) { Runnable runnable = new Runnable() { @Override scheduledStop = scheduler.schedule(runnable, getScanTimeout(), TimeUnit.SECONDS); startScan(); } catch (Exception ex) { if (scheduledStop != null) {
/** * Called when the configuration for the discovery service is changed. If * background discovery should be enabled and is currently disabled, the * method {@link AbstractDiscoveryService#startBackgroundDiscovery()} is * called. If background discovery should be disabled and is currently * enabled, the method {@link AbstractDiscoveryService#stopBackgroundDiscovery()} is called. In * all other cases, nothing happens. * * @param configProperties configuration properties */ protected void modified(@Nullable Map<String, @Nullable Object> configProperties) { if (configProperties != null) { Object property = configProperties.get(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY); if (property != null) { boolean enabled = getAutoDiscoveryEnabled(property); if (this.backgroundDiscoveryEnabled && !enabled) { stopBackgroundDiscovery(); logger.debug("Background discovery for discovery service '{}' disabled.", this.getClass().getName()); } else if (!this.backgroundDiscoveryEnabled && enabled) { startBackgroundDiscovery(); logger.debug("Background discovery for discovery service '{}' enabled.", this.getClass().getName()); } this.backgroundDiscoveryEnabled = enabled; } } }
/** * Call to remove all results of all {@link #supportedThingTypes} that are * older than the given timestamp. To remove all left over results after a * full scan, this method could be called {@link #getTimestampOfLastScan()} * as timestamp. * * @param timestamp timestamp, older results will be removed */ protected void removeOlderResults(long timestamp) { removeOlderResults(timestamp, null, null); }
@Override @Deactivate protected void deactivate() { super.deactivate(); }
/** * 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); } }
Collection<ThingUID> removedThings = null; Collection<ThingTypeUID> toBeRemoved = thingTypeUIDs != null ? thingTypeUIDs : getSupportedThingTypes(); for (DiscoveryListener discoveryListener : discoveryListeners) { try {
stopScan(); if (scheduledStop != null) { scheduledStop.cancel(false); if (getScanTimeout() > 0) { Runnable runnable = new Runnable() { @Override scheduledStop = scheduler.schedule(runnable, getScanTimeout(), TimeUnit.SECONDS); startScan(); } catch (Exception ex) { if (scheduledStop != null) {
/** * Called when the configuration for the discovery service is changed. If * background discovery should be enabled and is currently disabled, the * method {@link AbstractDiscoveryService#startBackgroundDiscovery()} is * called. If background discovery should be disabled and is currently * enabled, the method {@link AbstractDiscoveryService#stopBackgroundDiscovery()} is called. In * all other cases, nothing happens. * * @param configProperties * configuration properties */ protected void modified(@Nullable Map<String, @Nullable Object> configProperties) { if (configProperties != null) { Object property = configProperties.get(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY); if (property != null) { boolean enabled = getAutoDiscoveryEnabled(property); if (this.backgroundDiscoveryEnabled && !enabled) { stopBackgroundDiscovery(); logger.debug("Background discovery for discovery service '{}' disabled.", this.getClass().getName()); } else if (!this.backgroundDiscoveryEnabled && enabled) { startBackgroundDiscovery(); logger.debug("Background discovery for discovery service '{}' enabled.", this.getClass().getName()); } this.backgroundDiscoveryEnabled = enabled; } } }
/** * Called on component activation, if the implementation of this class is an * OSGi declarative service and does not override the method. The method * implementation calls {@link AbstractDiscoveryService#startBackgroundDiscovery()} if background * discovery is enabled by default and not overridden by the configuration. * * @param configProperties configuration properties */ protected void activate(@Nullable Map<String, @Nullable Object> configProperties) { if (configProperties != null) { Object property = configProperties.get(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY); if (property != null) { this.backgroundDiscoveryEnabled = getAutoDiscoveryEnabled(property); } } if (this.backgroundDiscoveryEnabled) { startBackgroundDiscovery(); logger.debug("Background discovery for discovery service '{}' enabled.", this.getClass().getName()); } }
/** * Call to remove all results of all {@link #supportedThingTypes} that are * older than the given timestamp. To remove all left over results after a * full scan, this method could be called {@link #getTimestampOfLastScan()} * as timestamp. * * @param timestamp * timestamp, older results will be removed */ protected void removeOlderResults(long timestamp) { removeOlderResults(timestamp, null); }
@Override public void deactivate() { super.deactivate(); inbox.stream().filter(thing -> { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); return BluetoothBindingConstants.SUPPORTED_THING_TYPES.contains(thingTypeUID); }).forEach(thing -> inbox.remove(thing.getThingUID())); }
/** * 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); } }
Collection<ThingUID> removedThings = null; Collection<ThingTypeUID> toBeRemoved = thingTypeUIDs != null ? thingTypeUIDs : getSupportedThingTypes(); for (DiscoveryListener discoveryListener : discoveryListeners) { try {
@Override public void run() { try { stopScan(); } catch (Exception e) { logger.debug("Exception occurred during execution: {}", e.getMessage(), e); } } };
@Override @Modified protected void modified(Map<String, Object> configProperties) { super.modified(configProperties); }
@Override @Activate protected void activate(@Nullable Map<String, @Nullable Object> configProperties) { super.activate(configProperties); usbSerialDiscovery.registerDiscoveryListener(this); }