/** * Creates a new scheduled {@code serviceType} simulator to simulate the given {@code @unitController}. * * @param unitController the unit to simulate. * @param serviceType the service type to simulate. * @param changeRate the simulation update speed in milliseconds. */ public AbstractScheduledServiceSimulator(final UnitController unitController, final ServiceType serviceType, final long changeRate) { this.changeRate = (isBenchmarkDetected() ? BENCHMARK_CHANGE_RATE : changeRate); this.unitController = unitController; this.simulationTask = () -> { final SERVICE_STATE serviceState; try { serviceState = getNextServiceState(); } catch (NotAvailableException ex) { LOGGER.warn("No more further service states are available. Simulation task will be terminated."); if (simulationTaskFuture != null) { simulationTaskFuture.cancel(true); } return; } // apply random service manipulation try { // randomly select one of the registered service states, update the service state timestamp and apply the state update on unit controller. unitController.applyDataUpdate(TimestampProcessor.updateTimestampWithCurrentTime(serviceState), serviceType); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory("Could not apply service modification!", ex, LOGGER); } }; }
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()); } }