@Override public M getValue() throws NotAvailableException { return unit.getData(); }
@Override public Future<M> getValueFuture() { return unit.getDataFuture(); }
@Override public boolean isValueAvailable() { return unit.isDataAvailable(); }
@Deprecated public void init() { // create a synchronisation task which makes sure that the change requested by // the internal future has at one time been synchronized to the remote synchronisationFuture = GlobalCachedExecutorService.submit(() -> { dataProvider.addDataObserver(notifyChangeObserver); try { dataProvider.waitForData(); T result = internalFuture.get(); waitForSynchronization(result); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory("Could not sync with internal future!", ex, logger); } finally { dataProvider.removeDataObserver(notifyChangeObserver); } return null; }); }
@Override public void activate() throws CouldNotPerformException, InterruptedException { if (locationDataObserver == null) { throw new NotInitializedException(this); } active = true; locationDataProvider.addDataObserver(locationDataObserver); // start initial timeout presenceTimeout.start(); updateMotionState(locationDataProvider.getData().getMotionState()); }
@Override public void waitForValue(long timeout, TimeUnit timeUnit) throws CouldNotPerformException, InterruptedException { unit.waitForData(); }
@Override public void deactivate() throws CouldNotPerformException, InterruptedException { active = false; presenceTimeout.cancel(); if (locationDataProvider != null) { // can be null if never initialized or initialization failed locationDataProvider.removeDataObserver(locationDataObserver); } }
@Override public Class<D> getDataClass() { return responsibleInstance.getDataClass(); }
public <B> B updateBuilderWithAvailableServiceStates(final B builder) throws InterruptedException, CouldNotPerformException { return updateBuilderWithAvailableServiceStates(builder, responsibleInstance.getDataClass(), getManagedServiceTypes()); }
@Override public D getData() throws NotAvailableException { return responsibleInstance.getData(); }
@Override public boolean isDataAvailable() { return responsibleInstance.isDataAvailable(); }
@Override public CompletableFuture<D> getDataFuture() { return responsibleInstance.getDataFuture(); }
@Override public void expired() { try { // if motion is still detected just restart the timeout. if (locationDataProvider.getData().getMotionState().getValue() == MotionState.State.MOTION) { GlobalCachedExecutorService.submit(() -> { try { presenceTimeout.restart(); } catch (final CouldNotPerformException ex) { ExceptionPrinter.printHistory("Could not setup presence timeout!", ex, logger); } }); return; } updatePresenceState(PresenceState.newBuilder().setValue(PresenceState.State.ABSENT)); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Could not notify absent by timer!", ex), logger); } } };