Replaced orphaned 'registerHandlerLock' by 'thingLocks' (#1060)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp 2019-10-06 11:17:51 +02:00 committed by Wouter Born
parent 9ae7bbe2e8
commit 6a3c9b03ac

View File

@ -350,8 +350,6 @@ public class ThingManagerImpl
private final Set<Thing> things = new CopyOnWriteArraySet<>();
private final Set<ThingUID> registerHandlerLock = new HashSet<>();
private final Set<ThingUID> thingUpdatedLock = new HashSet<>();
@Override
@ -366,11 +364,10 @@ public class ThingManagerImpl
scheduler.schedule(new Runnable() {
@Override
public void run() {
Lock lock = getLockForThing(thing.getUID());
ThingUID thingUID = thing.getUID();
Lock lock = getLockForThing(thingUID);
try {
lock.lock();
ThingUID thingUID = thing.getUID();
waitForRunningHandlerRegistrations(thingUID);
// Remove the ThingHandler, if any
final ThingHandlerFactory oldThingHandlerFactory = findThingHandlerFactory(thing.getThingTypeUID());
@ -403,12 +400,8 @@ public class ThingManagerImpl
thingRegistry.update(thing);
ThingHandler handler = thing.getHandler();
String handlerString = "NO HANDLER";
if (handler != null) {
handlerString = handler.toString();
}
logger.debug("Changed ThingType of Thing {} to {}. New ThingHandler is {}.",
thing.getUID().toString(), thing.getThingTypeUID(), handlerString);
logger.debug("Changed ThingType of Thing {} to {}. New ThingHandler is {}.", thingUID,
thing.getThingTypeUID(), handler == null ? "NO HANDLER" : handler);
} finally {
lock.unlock();
}
@ -433,25 +426,6 @@ public class ThingManagerImpl
logger.error(message);
throw new IllegalStateException(message);
}
private void waitForRunningHandlerRegistrations(ThingUID thingUID) {
for (int i = 0; i < 10 * 10; i++) {
if (!registerHandlerLock.contains(thingUID)) {
return;
}
try {
// Wait a little to give running handler registrations a chance to complete...
Thread.sleep(100);
} catch (InterruptedException e) {
return;
}
}
String message = MessageFormat.format(
"Thing type migration failed for {0}. Could not obtain lock for hander registration.",
thingUID.getAsString());
logger.error(message);
throw new IllegalStateException(message);
}
}, 0, TimeUnit.MILLISECONDS);
}