public PresenceLightAgent() throws InstantiationException { super(PresenceLightAgent.class); actionRescheduleHelper = new ActionRescheduler(RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { logger.warn("New trigger state: " + data.getValue()); GlobalCachedExecutorService.submit(() -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { switchlightsOn(); } else { logger.warn("Stop execution"); actionRescheduleHelper.stopExecution(); } return null; }); }; }
private boolean verifyAndCondition() throws CouldNotPerformException { for (AbstractTrigger abstractTrigger : triggerListAND) { if (!abstractTrigger.getActivationState().getValue().equals(ActivationState.State.ACTIVE) && !abstractTrigger.getActivationState().getValue().equals(ActivationState.State.UNKNOWN)) { return false; } } return !triggerListAND.isEmpty(); }
public TemperatureControllerAgent() throws InstantiationException { super(TemperatureControllerAgent.class); previousTemperatureState = new HashMap(); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { regulateTemperature(); } else { actionRescheduleHelper.stopExecution(); restoreTemperature(); } }; }
public Future<ActionFuture> setActivationState(final ActivationState activation) throws CouldNotPerformException { if (activation == null || activation.getValue().equals(ActivationState.State.UNKNOWN)) { throw new InvalidStateException("Unknown is not a valid state!");
@Override public Void call() throws Exception { if (activation == null || activation.getValue().equals(ActivationState.State.UNKNOWN)) { throw new InvalidStateException("Unknown is not a valid state!");
public TriggerPool() throws InstantiationException { triggerListAND = new ArrayList(); triggerListOR = new ArrayList(); active = false; triggerAndObserver = (Observable<ActivationState> source, ActivationState data) -> { verifyCondition(); }; triggerOrObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { if (!getActivationState().getValue().equals(ActivationState.State.ACTIVE)) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } } else { verifyCondition(); } }; try { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); } catch (CouldNotPerformException ex) { throw new InstantiationException("Could not set initial state", ex); } }
public IlluminationRollerShutterAgent() throws InstantiationException { super(IlluminationRollerShutterAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { if (locationRemote.getIlluminanceState().getIlluminance() > MAXIMUM_WANTED_ILLUMINATION) { regulateShutterLevelDown(); } else if (locationRemote.getIlluminanceState().getIlluminance() < MINIMUM_NEEDED_ILLUMINATION) { regulateShutterLevelUp(); } } else { actionRescheduleHelper.stopExecution(); } }; }
public RandomLightPatternAgent() throws InstantiationException { super(RandomLightPatternAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationStateType.ActivationState> source, ActivationStateType.ActivationState data) -> { GlobalCachedExecutorService.submit(() -> { if (data.getValue().equals(ActivationStateType.ActivationState.State.ACTIVE)) { makeRandomLightPattern(); } else { stopRandomLightPattern(); } return null; }); }; }
public AbsenceEnergySavingAgent() throws InstantiationException { super(AbsenceEnergySavingAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationStateType.ActivationState> source, ActivationStateType.ActivationState data) -> { GlobalCachedExecutorService.submit(() -> { if (data.getValue().equals(ActivationStateType.ActivationState.State.ACTIVE)) { switchlightsOff(); switchMultimediaOff(); } else { actionRescheduleHelper.stopExecution(); } return null; }); }; }
public HeaterEnergySavingAgent() throws InstantiationException { super(HeaterEnergySavingAgent.class); previousTemperatureState = new HashMap(); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { regulateHeater(); } else { actionRescheduleHelper.stopExecution(); restoreTemperatureState(); } }; }
private void verifyCondition() throws CouldNotPerformException { if (verifyOrCondition() || verifyAndCondition()) { if (!getActivationState().getValue().equals(ActivationState.State.ACTIVE)) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } } else { if (!getActivationState().getValue().equals(ActivationState.State.DEACTIVE)) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build())); } } }
public IlluminationLightSavingAgent() throws InstantiationException { super(IlluminationLightSavingAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { regulateLightIntensity(); } else { actionRescheduleHelper.stopExecution(); } }; }
public FireAlarmAgent() throws InstantiationException { super(FireAlarmAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { alarmRoutine(); } else { actionRescheduleHelper.stopExecution(); } }; }
private boolean verifyOrCondition() throws CouldNotPerformException { for (AbstractTrigger abstractTrigger : triggerListOR) { if (abstractTrigger.getActivationState().getValue().equals(ActivationState.State.ACTIVE)) { return true; } } return false; }
protected void notifyChange(final ActivationState newState) throws CouldNotPerformException { if (!triggerObservable.getValue().getValue().equals(newState.getValue())) { triggerObservable.notifyObservers(newState); } }
public NearFieldLightAgent() throws InstantiationException { super(NearFieldLightAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { dimmLights(); } else { actionRescheduleHelper.stopExecution(); } }; }