* Refactor websocket concurrency handling
* Modify web socket buffering logic to ensure FIFO and avoid blocking the logger thread
* Use a dedicated executor that is guaranteed not to log anything
* Logging tweak
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
Some of the SDDP tasks are long-running by design, the background scan task in particular runs indefinitely (until interrupted). This clashes with the idea in #4969, and perhaps with the envisioned use of OH's shared thread pools in general, in that pools are small and tasks are expected to be short-lived. When setting logging to DEBUG, the log will be constantly "spammed" with complaints about the SDDP discovery task taking more than 5 seconds, which it is in fact designed to do.
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
* Remove double localization of discovery results
Localization of discovery results requires a bundle from which to acquire the translations. When bindings implement AbstractDiscoveryService themselves, the bundle is resolved using the class of the implementation. For "sub discovery services" where bindings are "participants", this doesn't work, because the implementing class is the "sub discovery service" itself, not the binding, which means that the resolved bundle doesn't have any translations. This has been solved by doing an extra round of localization in the "sub discovery service" (using the correct bundle) before passing the DiscoveryResult on to AbstractDiscoveryService, which will attempt localization again, with the wrong bundle, but since no translations are found in this bundle, it has no other consequences than being wasteful.
This solves the problem by adding a second thingDiscovered() method to AbstractDiscoveryService, which accepts a bundle as a second argument. That way, "sub discovery services" can resolve the correct bundle using the participant class, and pass on the correct bundle, avoiding the "double localization".
In addition, a new factory method is added to DiscoveryResultBuilder that allows initializing a new builder from an existing DiscoveryResult instance, so that this doesn't have to be done in the localization method itself.
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
* Create User32Ex with some mappings missing in JNA's User32
* Create WindowMessageHandler for subscribing to device change messages
The class, when run as a Runnable, creates an invisible window and uses that to listen for device change events for USB devices and serial ports. It listens in a blocking message loop, so it's necessary to call terminate() for the loop to exit and the run() method to exit. Results are sent to subscribing WindowMessageListeners.
* Refactor WindowsUsbSerialDiscovery to use a different approach to gathering device information
The previous implementation scanned the registry for USB devices on a fixed interval. This implementation changes most of the core logic, using SetupAPI as the primary source of information instead of the registry. That allows it to process less information to get to the information of interest, in addition to only "discovering" devices that are currently connected to the computer. The registry keeps the entries for all devices that have previously been connected as well, which would also be "discovered" with the previous implementation.
In addition, this implementation uses WindowMessageHandler to receive device change messages from Windows, making regular scanning unnecessary. If the WindowMessageHandler fails for some reason, the implementation will fall back to scanning on an interval, but this scanning is still using SetupAPI to acquire the data.
* Various thread-safety and consistency fixes
- UsbAddonFinder: Remove unused Set and fix concurrency behavior. ConcurrentHashMap is unsuitable here because it doesn't allow locking the full map, which is needed during "merging" and when resolving suggested add-ons.
- DeltaUsbSerialScanner: Make lastScanResult thread-safe.
- Ser2NetUsbSerialDiscovery: Make lastScanResult thread-safe, reduce the scope of locking to reduce contention and lessen how many locks are held at once. Make notifyListeners volatile for thread-safe access, and stop reacting to jmdns serviceAdded events. jmdns first fires serviceAdded when the service has just been discovered, but most of the information hasn't yet been gathered, and then fires serviceResolved once all the data has been registered. The data received in serviceAdded is incomplete and rarely useful, at best it's a "heads-up, this device might be resolved soon".
- UsbSerialDiscovery: Correct JavaDoc
- UsbSerialDiscoveryService: Minor logging tweaks, only log "Discovered new" the first time the device is "discovered".
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
* Add AbstractThingHandlerDiscoveryService constructor for tests to use a different executor
* Add JavaDocs
* Make ThingHandler type generic
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
By using the discovery thread pool to do the actual registrations in AbstractDiscoveryService, binding threads won't have to wait for the registration to complete, which can be slow.
In addition, some thread-safety fixes have been done in AbstractDiscoveryService and DiscoveryServiceRegistryImpl, both to avoid contention and to ensure isolation of mutable objects.
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
AddonSuggestionService has had a delayed application of configuration because it was based on a timer that refreshed it every minute. This led to various issue where "wrong decision" were made based on stale information. This addresses the root cause for why the configuration wasn't delivered in a timely manner by OSGi, and removes the scheduled configuration refresh.
For the configuration to be accessible to multiple bundles, its "location" must be "a region". This must be configured before any bundle tries to use the configuration. To do this very early, it has been attached to the Activator of the "main core bundle". It doesn't have to be there, as long as it will always run very early during startup.
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
Additionally, change HashSet to LinkedHashSet in classes RuleGSONParser and TemplateGSONParser
to make iteration order predictable.
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
* Remove forum compatibility range from add-on title
* Fix and unify error handling of missing content in community marketplace add-on handlers
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
It was removed in 8154dce3076d56df5e1d87b2fd465c8232f7cba1 (#4922) and might be causing the logging of errors during startup, as reported in #4965.
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>