persistent inbox: ensure all members have been set before usage (#826)

Fixes #823

Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
This commit is contained in:
Markus Rathgeb 2019-05-16 14:20:50 +02:00 committed by Christoph Weitkamp
parent 457df1e853
commit 0aaad726ff

View File

@ -148,19 +148,20 @@ public final class PersistentInbox implements Inbox, DiscoveryListener, ThingReg
final @Reference ThingRegistry thingRegistry, final @Reference ManagedThingProvider thingProvider,
final @Reference ThingTypeRegistry thingTypeRegistry,
final @Reference ConfigDescriptionRegistry configDescriptionRegistry) {
// First set all member variables to ensure the object itself is initialized (as most as possible).
this.discoveryResultStorage = storageService.getStorage(DiscoveryResult.class.getName(),
this.getClass().getClassLoader());
this.discoveryServiceRegistry = discoveryServiceRegistry;
this.discoveryServiceRegistry.addDiscoveryListener(this);
this.thingRegistry = thingRegistry;
this.thingRegistry.addRegistryChangeListener(this);
this.managedThingProvider = thingProvider;
this.thingTypeRegistry = thingTypeRegistry;
this.configDescRegistry = configDescriptionRegistry;
// This should be the last step (to be more precise: providing the "this" reference to other ones as long as the
// constructor is not finished is a bad idea at all) as "this" will be used by another thread and so we need
// This should be the last steps (to be more precise: providing the "this" reference to other ones as long as
// the constructor is not finished is a bad idea at all) as "this" will be used by another thread and so we need
// already fully instantiated object.
this.discoveryServiceRegistry.addDiscoveryListener(this);
this.thingRegistry.addRegistryChangeListener(this);
this.timeToLiveChecker = ThreadPoolManager.getScheduledPool("discovery")
.scheduleWithFixedDelay(new TimeToLiveCheckingThread(this), 0, 30, TimeUnit.SECONDS);
}