private boolean isResultExpired(DiscoveryResult result, long now) { if (result.getTimeToLive() == DiscoveryResult.TTL_UNLIMITED) { return false; } return (result.getTimestamp() + result.getTimeToLive() * 1000 < now); } }
private boolean isResultExpired(DiscoveryResult result, long now) { if (result.getTimeToLive() == DiscoveryResult.TTL_UNLIMITED) { return false; } return (result.getTimestamp() + result.getTimeToLive() * 1000 < now); } }
/** * Merges the content of the specified source {@link DiscoveryResult} into this object. * <p> * <i>Hint:</i> The {@link DiscoveryResultFlag} of this object keeps its state. * <p> * This method returns silently if the specified source {@link DiscoveryResult} is {@code null} or its {@code Thing} * type or ID does not fit to this object. * * @param sourceResult the discovery result which is used as source for the merge */ public void synchronize(DiscoveryResult sourceResult) { if ((sourceResult != null) && (sourceResult.getThingUID().equals(this.thingUID))) { this.properties = sourceResult.getProperties(); this.representationProperty = sourceResult.getRepresentationProperty(); this.label = sourceResult.getLabel(); this.timestamp = new Date().getTime(); this.timeToLive = sourceResult.getTimeToLive(); } }
/** * Merges the content of the specified source {@link DiscoveryResult} into this object. * <p> * <i>Hint:</i> The {@link DiscoveryResultFlag} of this object keeps its state. * <p> * This method returns silently if the specified source {@link DiscoveryResult} is {@code null} or its {@code Thing} * type or ID does not fit to this object. * * @param sourceResult the discovery result which is used as source for the merge */ public void synchronize(DiscoveryResult sourceResult) { if ((sourceResult != null) && (sourceResult.getThingUID().equals(this.thingUID))) { this.properties = sourceResult.getProperties(); this.representationProperty = sourceResult.getRepresentationProperty(); this.label = sourceResult.getLabel(); this.timestamp = new Date().getTime(); this.timeToLive = sourceResult.getTimeToLive(); } }
private void printInboxEntries(Console console, List<DiscoveryResult> discoveryResults) { if (discoveryResults.isEmpty()) { console.println("No inbox entries found."); } for (DiscoveryResult discoveryResult : discoveryResults) { ThingTypeUID thingTypeUID = discoveryResult.getThingTypeUID(); ThingUID thingUID = discoveryResult.getThingUID(); String label = discoveryResult.getLabel(); DiscoveryResultFlag flag = discoveryResult.getFlag(); ThingUID bridgeId = discoveryResult.getBridgeUID(); Map<String, Object> properties = discoveryResult.getProperties(); String representationProperty = discoveryResult.getRepresentationProperty(); String timestamp = new Date(discoveryResult.getTimestamp()).toString(); String timeToLive = discoveryResult.getTimeToLive() == DiscoveryResult.TTL_UNLIMITED ? "UNLIMITED" : "" + discoveryResult.getTimeToLive(); console.println(String.format( "%s [%s]: %s [thingId=%s, bridgeId=%s, properties=%s, representationProperty=%s, timestamp=%s, timeToLive=%s]", flag.name(), thingTypeUID, label, thingUID, bridgeId, properties, representationProperty, timestamp, timeToLive)); } }
private void printInboxEntries(Console console, List<DiscoveryResult> discoveryResults) { if (discoveryResults.isEmpty()) { console.println("No inbox entries found."); } for (DiscoveryResult discoveryResult : discoveryResults) { ThingTypeUID thingTypeUID = discoveryResult.getThingTypeUID(); ThingUID thingUID = discoveryResult.getThingUID(); String label = discoveryResult.getLabel(); DiscoveryResultFlag flag = discoveryResult.getFlag(); ThingUID bridgeId = discoveryResult.getBridgeUID(); Map<String, Object> properties = discoveryResult.getProperties(); String representationProperty = discoveryResult.getRepresentationProperty(); String timestamp = new Date(discoveryResult.getTimestamp()).toString(); String timeToLive = discoveryResult.getTimeToLive() == DiscoveryResult.TTL_UNLIMITED ? "UNLIMITED" : "" + discoveryResult.getTimeToLive(); console.println(String.format( "%s [%s]: %s [thingId=%s, bridgeId=%s, properties=%s, representationProperty=%s, timestamp=%s, timeToLive=%s]", flag.name(), thingTypeUID, label, thingUID, bridgeId, properties, representationProperty, timestamp, timeToLive)); } }
/** * 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); } }
private DiscoveryResult createDiscoveryResultWithUsbProperties(DiscoveryResult result, UsbSerialDeviceInformation usbSerialDeviceInformation) { Map<String, Object> resultProperties = new HashMap<>(result.getProperties()); resultProperties.put(THING_PROPERTY_USB_VENDOR_ID, usbSerialDeviceInformation.getVendorId()); resultProperties.put(THING_PROPERTY_USB_PRODUCT_ID, usbSerialDeviceInformation.getProductId()); return DiscoveryResultBuilder.create(result.getThingUID()).withProperties(resultProperties) .withBridge(result.getBridgeUID()).withTTL(result.getTimeToLive()).withLabel(result.getLabel()) .withRepresentationProperty(result.getRepresentationProperty()).build(); } }
/** * 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); } }