if (getActivationState().getValue() == ActivationState.State.ACTIVE) { locationMap.forEach((remote, observer) -> { remote.addServiceStateObserver(ServiceType.PRESENCE_STATE_SERVICE, observer);
applyDataUpdate(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).setTimestamp(TimestampProcessor.getCurrentTimestamp()).build(), ServiceType.ACTIVATION_STATE_SERVICE);
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!"); if (activation.getValue() == getActivationState().getValue()) { return CompletableFuture.completedFuture(null); if (activation.getValue() == ActivationState.State.ACTIVE) { 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);
boolean active = getActivationState().getValue() == State.ACTIVE;
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()));
@Override public Void call() throws Exception { if (activation == null || activation.getValue().equals(ActivationState.State.UNKNOWN)) { throw new InvalidStateException("Unknown is not a valid state!"); if (activation.getValue() == ActivationState.State.ACTIVE) { if (!executing) { executing = true; throw new CouldNotPerformException("Could not " + StringProcessor.transformUpperCaseToCamelCase(activation.getValue().name()) + " " + this, ex);
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()));
@Override protected void updateDynamicComponents() { try { logger.info("state: " + getProviderService().getActivationState().getValue().name()); switch (getProviderService().getActivationState().getValue()) { case ACTIVE: activationStatusLabel.setForeground(Color.BLACK); activationStatePanel.setBackground(Color.GREEN.darker()); activationButton.setText("Deactivate"); break; case DEACTIVE: activationStatusLabel.setForeground(Color.LIGHT_GRAY); activationStatePanel.setBackground(Color.GRAY.darker()); activationButton.setText("Activate"); break; case UNKNOWN: activationStatusLabel.setForeground(Color.BLACK); activationStatePanel.setBackground(Color.ORANGE.darker()); activationButton.setText("Activate"); break; default: throw new InvalidStateException("State[" + getProviderService().getActivationState().getValue() + "] is unknown."); } activationStatusLabel.setText("Current ActivationState = " + StringProcessor.transformUpperCaseToCamelCase(getProviderService().getActivationState().getValue().name())); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); } } }
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 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 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); } }
/** * Constructor prepares the launcher and registers already a shutdown hook. * The launcher class is used to instantiate a new launcher instance if the instantiateLaunchable() method is not overwritten. * <p> * After instantiation of this class the launcher must be initialized and activated before the RSB interface is provided. * * @param launchableClass the class to be launched. * @param applicationClass the class representing this application. Those is used for scope generation if the getName() method is not overwritten. * @throws org.openbase.jul.exception.InstantiationException */ public AbstractLauncher(final Class applicationClass, final Class<L> launchableClass) throws InstantiationException { super(ActivationState.newBuilder()); // try { this.launchableClass = launchableClass; this.applicationClass = applicationClass; // } catch (CouldNotPerformException ex) { // throw new InstantiationException(this, ex); // } }
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())); } }; }
private void activationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_activationButtonActionPerformed try { switch (getOperationService().getActivationState().getValue()) { case ACTIVE: notifyActionProcessing(getOperationService().setActivationState(DEACTIVE)); break; case DEACTIVE: case UNKNOWN: notifyActionProcessing(getOperationService().setActivationState(ACTIVE)); break; default: throw new InvalidStateException("State[" + getProviderService().getActivationState().getValue() + "] is unknown."); } } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Could not set activation state!", ex), logger); } }//GEN-LAST:event_activationButtonActionPerformed
@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 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; }); }; }
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); } }
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; }); }; }
@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); } }