applyDataUpdate(activation.toBuilder().setTimestamp(TimestampProcessor.getCurrentTimestamp()).build(), ServiceType.ACTIVATION_STATE_SERVICE); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not " + StringProcessor.transformUpperCaseToCamelCase(activation.getValue().name()) + " " + this, ex);
applyDataUpdate(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).setTimestamp(TimestampProcessor.getCurrentTimestamp()).build(), ServiceType.ACTIVATION_STATE_SERVICE);
case HIGH_ACTIVE: if (value >= upperBoundary) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } else if (value < lowerBoundary) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build())); notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build())); } else if (value <= lowerBoundary) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build())); notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build()));
notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build())); notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build()));
private void verifyCondition(DT data) { try { Object serviceState = Services.invokeProviderServiceMethod(serviceType, data); Method method = serviceState.getClass().getMethod("getValue"); if (method.invoke(serviceState).equals(targetState)) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build())); } } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory("Could not verify condition " + this, ex, LOGGER); } catch (NoSuchMethodException ex) { ExceptionPrinter.printHistory("Method not known " + this, ex, LOGGER); } catch (SecurityException ex) { ExceptionPrinter.printHistory("Security Exception " + this, ex, LOGGER); } catch (IllegalAccessException ex) { ExceptionPrinter.printHistory("Illegal Access Exception " + this, ex, LOGGER); } catch (IllegalArgumentException ex) { ExceptionPrinter.printHistory("Illegal Argument Exception " + this, ex, LOGGER); } catch (InvocationTargetException ex) { ExceptionPrinter.printHistory("Could not invoke method " + this, ex, LOGGER); } }
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 GenericValueDualBoundaryBCOTrigger(final UR unitRemote, final double upperBoundary, final double lowerBoundary, final TriggerOperation triggerOperation, ServiceType serviceType, String specificValueCall) throws InstantiationException { super(); if (upperBoundary < lowerBoundary) { throw new InstantiationException(this.getClass(), new Throwable("upperBoundary below lowerBoundary")); } this.unitRemote = unitRemote; this.serviceType = serviceType; this.upperBoundary = upperBoundary; this.lowerBoundary = lowerBoundary; this.triggerOperation = triggerOperation; this.specificValueCall = specificValueCall; dataObserver = (Observable<DT> source, DT data) -> { verifyCondition(data); }; connectionObserver = (Observable<Remote.ConnectionState> source, Remote.ConnectionState data) -> { if (data.equals(Remote.ConnectionState.CONNECTED)) { verifyCondition((DT) unitRemote.getData()); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); } }; }
public GenericValueBoundaryBCOTrigger(final UR unitRemote, final double boundary, final TriggerOperation triggerOperation, ServiceType serviceType, String specificValueCall) throws InstantiationException { super(); this.unitRemote = unitRemote; this.serviceType = serviceType; this.boundary = boundary; this.triggerOperation = triggerOperation; this.specificValueCall = specificValueCall; dataObserver = (Observable<DT> source, DT data) -> { verifyCondition(data); }; connectionObserver = (Observable<Remote.ConnectionState> source, Remote.ConnectionState data) -> { if (data.equals(Remote.ConnectionState.CONNECTED)) { verifyCondition((DT) unitRemote.getData()); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); } }; }
@Override public ActivationState getActivationState(final UnitType unitType) throws NotAvailableException { ActivationState.State activationStateValue = ActivationState.State.DEACTIVE; try { for (ActivationStateOperationService service : getServices(unitType)) { if (!((UnitRemote) service).isDataAvailable()) { continue; } if (service.getActivationState().getValue() == ActivationState.State.ACTIVE) { activationStateValue = ActivationState.State.ACTIVE; } } return TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(activationStateValue)).build(); } catch (CouldNotPerformException ex) { throw new NotAvailableException("ActivationState", ex); } }
public GenericBCOTrigger(final UR unitRemote, final STE targetState, final ServiceType serviceType) throws InstantiationException { super(); this.unitRemote = unitRemote; this.targetState = targetState; this.serviceType = serviceType; dataObserver = (Observable<DT> source, DT data) -> { verifyCondition(data); }; connectionObserver = (Observable<ConnectionState> source, ConnectionState data) -> { if (data.equals(ConnectionState.CONNECTED)) { verifyCondition((DT) unitRemote.getData()); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); } }; }
@Override public void enable() throws CouldNotPerformException, InterruptedException { try { synchronized (enablingLock) { enabled = true; activate(); if (detectAutostart()) { setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build()).get(); } else { setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build()).get(); } } } catch (ExecutionException ex) { throw new CouldNotPerformException("Could not enable " + this, ex); } }
@Override public void enable() throws CouldNotPerformException, InterruptedException { try { synchronized (enablingLock) { super.enable(); if (detectAutostart()) { setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build()).get(); } else { setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build()).get(); } } } catch (ExecutionException ex) { throw new CouldNotPerformException("Could not diable " + this, ex); } }
@RPCMethod public Future<ActionFuture> setActivationState(final ActivationState activationState) throws CouldNotPerformException;
public NeighborConnectionPresenceTrigger(final LocationRemote locationRemote, final ConnectionRemote connectionRemote) throws org.openbase.jul.exception.InstantiationException { super(); this.locationRemote = locationRemote; this.connectionRemote = connectionRemote; dataObserver = (source, data) -> { verifyCondition(); }; connectionObserver = (Observable<Remote.ConnectionState> source, Remote.ConnectionState data) -> { if (data.equals(Remote.ConnectionState.CONNECTED)) { verifyCondition(); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); } }; }
private void verifyCondition() { try { if (locationRemote.getData().getPresenceState().getValue().equals(PresenceState.State.PRESENT) && (connectionRemote.getDoorState().getValue().equals(DoorState.State.OPEN) || connectionRemote.getWindowState().getValue().equals(WindowState.State.OPEN))) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build())); } } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory("Could not verify trigger state " + this, ex, LoggerFactory.getLogger(getClass())); } } }
@Override public void deactivate() throws CouldNotPerformException, InterruptedException { for (AbstractTrigger abstractTrigger : triggerListAND) { abstractTrigger.deregisterObserver(triggerAndObserver); abstractTrigger.deactivate(); } for (AbstractTrigger abstractTrigger : triggerListOR) { abstractTrigger.deregisterObserver(triggerOrObserver); abstractTrigger.deactivate(); } notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); active = false; }
public SceneControllerImpl() throws org.openbase.jul.exception.InstantiationException { super(SceneControllerImpl.class, SceneData.newBuilder()); this.buttonRemoteSet = new HashSet<>(); this.remoteActionList = new ArrayList<>(); this.buttonObserver = (final Observable<ButtonData> source, ButtonData data) -> { // skip initial button state synchronization during system startup if (data.getButtonStateLast().getValue().equals(State.UNKNOWN)) { return; } if (data.getButtonState().getValue().equals(ButtonState.State.PRESSED)) { setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build()); } }; }
public OntologyTrigger(TriggerConfig config) throws InstantiationException { super(); triggerObserver = (Observable<ActivationState.State> source, ActivationState.State data) -> { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(data).build())); }; try { final TriggerFactory triggerFactory = new TriggerFactory(); trigger = triggerFactory.newInstance(config); trigger.addObserver(triggerObserver); } catch (CouldNotPerformException | InterruptedException ex) { throw new InstantiationException("Could not instantiate OntologyTrigger", ex); } }
@Override public void disable() throws CouldNotPerformException, InterruptedException { try { synchronized (enablingLock) { cancelExecution(); enabled = false; setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build()).get(); deactivate(); } } catch (ExecutionException ex) { throw new CouldNotPerformException("Could not disable " + this, ex); } }
public static ActivationState transform(OnOffHolderType.OnOffHolder.OnOff onOffType) throws CouldNotTransformException { switch (onOffType) { case OFF: return ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build(); case ON: return ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build(); default: throw new CouldNotTransformException("Could not transform " + OnOffHolderType.OnOffHolder.OnOff.class.getName() + "! " + OnOffHolderType.OnOffHolder.OnOff.class.getSimpleName() + "[" + onOffType.name() + "] is unknown!"); } }