/** * {@inheritDoc} * * @throws InterruptedException {@inheritDoc} * @throws CouldNotPerformException {@inheritDoc} */ @Override public void activate(final Object maintainer) throws InterruptedException, CouldNotPerformException { if (!isLocked() || this.maintainer.equals(maintainer)) { synchronized (maintainerLock) { unlock(maintainer); activate(); lock(maintainer); } } else { throw new VerificationFailedException("[" + maintainer + "] is not the current maintainer of this remote"); } }
public RSBRemoteViewFrame(RSBRemoteService<M> remoteService) { this.remoteService = remoteService; remoteService.addDataObserver(this); }
/** * Atomic deactivate which makes sure that the maintainer stays the same. * * @param maintainer the current maintainer of this remote * @throws InterruptedException if deactivation is interrupted * @throws CouldNotPerformException if deactivation fails * @throws VerificationFailedException is thrown if the given maintainer does not match the current one */ public void deactivate(final Object maintainer) throws InterruptedException, CouldNotPerformException, VerificationFailedException { if (this.maintainer.equals(maintainer)) { synchronized (maintainerLock) { unlock(maintainer); deactivate(); lock(maintainer); } } else { throw new VerificationFailedException("[" + maintainer + "] is not the current maintainer of this remote"); } }
/** * {@inheritDoc} * * @throws InterruptedException {@inheritDoc} * @throws CouldNotPerformException {@inheritDoc} */ @Override public void activate(boolean waitForData) throws InterruptedException, CouldNotPerformException { activate(); if (waitForData) { // make sure the remote is fully synchronized with main controller before continue. waitForData(); } }
private void internalInit(final Scope scope, final ParticipantConfig participantConfig) throws InitializationException, InterruptedException { synchronized (maintainerLock) { try { verifyMaintainability(); if (isActive()) { setConnectionState(ConnectionState.RECONNECTING); } else { setConnectionState(ConnectionState.REINITIALIZING); deactivate(); reset(); initListener(internalScope, internalParticipantConfig); initRemoteServer(internalScope, internalParticipantConfig); addHandler(mainHandler, true); postInit(); initialized = true; switch (getConnectionState()) { case RECONNECTING: activate(); break; case REINITIALIZING: setConnectionState(ConnectionState.DISCONNECTED); break;
throw new CouldNotPerformException("Could not access remote!", ex); remote.init(JPService.getProperty(JPScope.class).getValue()); remote.activate(); Method remoteMethod = JPService.getProperty(JPRemoteMethod.class).getValue(); throw new CouldNotPerformException("Could not invoke remote method!", ex); remote.shutdown(); } catch (Exception ex) { throw new InitializationException(this, ex);
remoteService.addDataObserver(remoteRegistrySynchronizer); if (remoteService.isDataAvailable()) { try { remoteRegistrySynchronizer.update(null, remoteService.getData()); } catch (Exception ex) { ExceptionPrinter.printHistory("Initial synchronization of " + this + " failed!", ex, LOGGER); if (remoteService.isDataAvailable()) { remoteRegistrySynchronizer.update(null, remoteService.getData());
/** * {@inheritDoc} * * @param scope {@inheritDoc} * @throws org.openbase.jul.exception.InitializationException {@inheritDoc} * @throws java.lang.InterruptedException {@inheritDoc} */ @Override public void init(final rsb.Scope scope) throws InitializationException, InterruptedException { init(scope, RSBSharedConnectionConfig.getParticipantConfig()); }
/** * {@inheritDoc} * * @throws CouldNotPerformException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ @Override public void waitForData() throws CouldNotPerformException, InterruptedException { try { if (isDataAvailable()) { return; } logger.debug("Wait for " + this.toString() + " data..."); getDataFuture().get(); dataObservable.waitForValue(); } catch (ExecutionException | CancellationException ex) { throw new CouldNotPerformException("Could not wait for data!", ex); } }
@Override public void activate() throws InterruptedException, CouldNotPerformException { super.activate(); for (final RemoteRegistry remoteRegistry : remoteRegistries) { if (remoteRegistry instanceof SynchronizedRemoteRegistry) { ((SynchronizedRemoteRegistry) remoteRegistry).activate(); } } }
public M getData() throws CouldNotPerformException { return remoteService.getData(); }
/** * This method deactivates the remote and cleans all resources. */ @Override public void shutdown() { try { verifyMaintainability(); } catch (VerificationFailedException ex) { throw new RuntimeException("Can not shutdown " + this + "!", ex); } this.shutdownInitiated = true; try { dataObservable.shutdown(); } finally { try { deactivate(); } catch (CouldNotPerformException | InterruptedException ex) { ExceptionPrinter.printHistory("Could not shutdown " + this + "!", ex, logger); } } }
@Override public void deactivate() throws InterruptedException, CouldNotPerformException { super.deactivate(); for (final RemoteRegistry remoteRegistry : remoteRegistries) { if (remoteRegistry instanceof SynchronizedRemoteRegistry) { ((SynchronizedRemoteRegistry) remoteRegistry).deactivate(); } } }
/** * {@inheritDoc} * * @param timeout {@inheritDoc} * @param timeUnit {@inheritDoc} * @throws CouldNotPerformException {@inheritDoc} * @throws java.lang.InterruptedException {@inheritDoc} */ @Override public void waitForData(long timeout, TimeUnit timeUnit) throws CouldNotPerformException, InterruptedException { try { if (isDataAvailable()) { return; } long startTime = System.currentTimeMillis(); getDataFuture().get(timeout, timeUnit); long partialTimeout = timeUnit.toMillis(timeout) - (System.currentTimeMillis() - startTime); if (partialTimeout <= 0) { throw new java.util.concurrent.TimeoutException("Data timeout is reached!"); } dataObservable.waitForValue(partialTimeout, TimeUnit.MILLISECONDS); } catch (java.util.concurrent.TimeoutException | CouldNotPerformException | ExecutionException | CancellationException ex) { throw new NotAvailableException("Data is not yet available!", ex); } }
/** * @param observer * @deprecated use removeDataObserver(observer); instead */ @Deprecated public void removeObserver(Observer<M> observer) { removeDataObserver(observer); }
@Override public String getName() { if (fieldDescriptors == null || fieldDescriptors.length == 0) { return getClass().getSimpleName() + "[" + (remoteService != null ? remoteService.toString() : "?") + "]"; } else { String fieldDescriptorNames = "["; fieldDescriptorNames += fieldDescriptors[0].getName(); for (int i = 1; i < fieldDescriptors.length; ++i) { fieldDescriptorNames += ", " + fieldDescriptors[i].getName(); } fieldDescriptorNames += "]"; return getClass().getSimpleName() + "[" + remoteService.toString() + "]" + fieldDescriptorNames; } }
/** * {@inheritDoc} */ @Override public void shutdown() { super.shutdown(); remoteRegistries.stream().forEach((remoteRegistry) -> { remoteRegistry.shutdown(); }); }
@Override protected void postInit() throws InitializationException, InterruptedException { super.postInit(); try { try { remoteRegistries.clear(); registerRemoteRegistries(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not activate version control for all internal registries!", ex); } } catch (CouldNotPerformException ex) { throw new InitializationException(this, ex); } }
public void validateData() throws InvalidStateException { if (!isDataAvailable()) { throw new InvalidStateException(this + " not synchronized yet!", new NotAvailableException("data")); } }
/** * {@inheritDoc} * * @param scope {@inheritDoc} * @throws org.openbase.jul.exception.InitializationException {@inheritDoc} * @throws java.lang.InterruptedException {@inheritDoc} */ @Override public void init(final Scope scope) throws InitializationException, InterruptedException { init(scope, RSBSharedConnectionConfig.getParticipantConfig()); }