for (UnitRemote targetRemote : targetRemotes) { targetRemote.addServiceStateObserver(ServiceTempus.REQUESTED, ServiceType.POWER_STATE_SERVICE, targetRequestObserer); targetRemote.addServiceStateObserver(ServiceTempus.CURRENT, ServiceType.POWER_STATE_SERVICE, targetObserver); targetRemote.addServiceStateObserver(ServiceTempus.CURRENT, ServiceType.COLOR_STATE_SERVICE, unitRemoteColorObserverMap.get(targetRemote)); targetRemote.addServiceStateObserver(ServiceTempus.REQUESTED, ServiceType.COLOR_STATE_SERVICE, unitRemoteColorObserverMap.get(targetRemote)); sourceRemote.addServiceStateObserver(ServiceTempus.REQUESTED, ServiceType.POWER_STATE_SERVICE, sourceRequestObserver); sourceRemote.addServiceStateObserver(ServiceTempus.CURRENT, ServiceType.POWER_STATE_SERVICE, sourceObserver);
/** * Method creates and adds the necessary observer for collecting time and system state information. The observer types are: * 1 connectionState: Keep the state of the unit remote connection to verify the correctness of the state changes. * N providerServices: Keep the state changes of the different provider services, which are set dependent on the unit remote. * * @param unitRemote is the unit remote to identify the provider services and their state changes. * @throws CouldNotPerformException is thrown in case the provider services could not be detected. */ private void createAndAddObserver(final UnitRemote unitRemote) throws CouldNotPerformException { final Set<Method> methodsStateType = ReflectionUtility.detectMethods(unitRemote.getDataClass(), MethodRegEx.STATE_METHOD.getName(), Pattern.CASE_INSENSITIVE); for (final Method getGenericStateService : methodsStateType) { final String serviceTypeName = StringModifier.getServiceTypeNameFromStateMethodName(getGenericStateService.getName()); final ServiceType serviceType = OntConfig.SERVICE_NAME_MAP.get(serviceTypeName); final RecurrenceEventFilter recurrenceEventFilter = new RecurrenceEventFilter(200) { @Override public void relay() { serviceStateChangeProcessing(providerServiceObj, serviceType, serviceTypeName); } }; final Observer<T> serviceStateObserver = (final Observable<T> observable, final T providerServiceData) -> { this.providerServiceObj = providerServiceData; recurrenceEventFilter.trigger(); }; unitRemote.addServiceStateObserver(OntConfig.SERVICE_NAME_MAP.get(serviceTypeName), serviceStateObserver); } final Observer<ConnectionState> unitRemoteConnectionObserver = (final Observable<ConnectionState> observable, final ConnectionState connectionState) -> connectionPhase.identifyConnectionState(connectionState); unitRemote.addConnectionStateObserver(unitRemoteConnectionObserver); }