/** * Method initializes the unit manager with the given unit controller registry. * * @param unitControllerRegistry the unit controller registry to quire the unit controller to simulate. * @throws InterruptedException is thrown if the current thread is externally interrupted. */ @Override public void init(final UnitControllerRegistry<?, ?> unitControllerRegistry) throws InterruptedException { if (!enabled) { return; } try { Registries.getUnitRegistry().waitForData(); unitControllerRegistry.addObserver((source, data) -> { updateUnitSimulators(data.values()); }); updateUnitSimulators(unitControllerRegistry.getValue().values()); } catch (Exception ex) { ExceptionPrinter.printHistory(new InitializationException(this, ex), LOGGER); } }
@Override public UnitConfig applyConfigUpdate(UnitConfig config) throws CouldNotPerformException, InterruptedException { synchronized (configUpdateLock) { UnitConfig unitConfig = super.applyConfigUpdate(config); for (final String removedUnitId : getRemovedUnitIds()) { DeviceManagerController.getDeviceManager().getUnitControllerRegistry().remove(removedUnitId); } for (final UnitController newUnitController : getNewUnitController()) { DeviceManagerController.getDeviceManager().getUnitControllerRegistry().register(newUnitController); } return unitConfig; } }
public void receiveUpdate(OpenhabCommandType.OpenhabCommand command) throws CouldNotPerformException { LOGGER.info("receiveUpdate [" + command.getItem() + "=" + command.getType() + "]"); OpenhabCommandMetaData metaData = new OpenhabCommandMetaData(command); Object serviceData = OpenhabCommandTransformer.getServiceData(command, metaData.getServiceType()); if (serviceData == null) { return; } final UnitController unitController; try { unitController = unitControllerRegistry.getUnitByScope(metaData.getUnitScope()); } catch (NotAvailableException ex) { if (!unitControllerRegistry.isInitiallySynchronized()) { LOGGER.debug("ItemUpdate[" + command.getItem() + "=" + command.getType() + "] skipped because controller registry was not ready yet!"); return; } throw ex; } unitController.applyDataUpdate(serviceData, metaData.getServiceType()); } }