mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-26 20:21:33 +01:00
Replaced orphaned 'registerHandlerLock' by 'thingLocks' (#1060)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
9ae7bbe2e8
commit
6a3c9b03ac
@ -350,8 +350,6 @@ public class ThingManagerImpl
|
|||||||
|
|
||||||
private final Set<Thing> things = new CopyOnWriteArraySet<>();
|
private final Set<Thing> things = new CopyOnWriteArraySet<>();
|
||||||
|
|
||||||
private final Set<ThingUID> registerHandlerLock = new HashSet<>();
|
|
||||||
|
|
||||||
private final Set<ThingUID> thingUpdatedLock = new HashSet<>();
|
private final Set<ThingUID> thingUpdatedLock = new HashSet<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -366,11 +364,10 @@ public class ThingManagerImpl
|
|||||||
scheduler.schedule(new Runnable() {
|
scheduler.schedule(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Lock lock = getLockForThing(thing.getUID());
|
ThingUID thingUID = thing.getUID();
|
||||||
|
Lock lock = getLockForThing(thingUID);
|
||||||
try {
|
try {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
ThingUID thingUID = thing.getUID();
|
|
||||||
waitForRunningHandlerRegistrations(thingUID);
|
|
||||||
|
|
||||||
// Remove the ThingHandler, if any
|
// Remove the ThingHandler, if any
|
||||||
final ThingHandlerFactory oldThingHandlerFactory = findThingHandlerFactory(thing.getThingTypeUID());
|
final ThingHandlerFactory oldThingHandlerFactory = findThingHandlerFactory(thing.getThingTypeUID());
|
||||||
@ -403,12 +400,8 @@ public class ThingManagerImpl
|
|||||||
thingRegistry.update(thing);
|
thingRegistry.update(thing);
|
||||||
|
|
||||||
ThingHandler handler = thing.getHandler();
|
ThingHandler handler = thing.getHandler();
|
||||||
String handlerString = "NO HANDLER";
|
logger.debug("Changed ThingType of Thing {} to {}. New ThingHandler is {}.", thingUID,
|
||||||
if (handler != null) {
|
thing.getThingTypeUID(), handler == null ? "NO HANDLER" : handler);
|
||||||
handlerString = handler.toString();
|
|
||||||
}
|
|
||||||
logger.debug("Changed ThingType of Thing {} to {}. New ThingHandler is {}.",
|
|
||||||
thing.getUID().toString(), thing.getThingTypeUID(), handlerString);
|
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
@ -433,25 +426,6 @@ public class ThingManagerImpl
|
|||||||
logger.error(message);
|
logger.error(message);
|
||||||
throw new IllegalStateException(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);
|
}, 0, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user