/** * {@inheritDoc} */ @Override public void shutdown() { try { deactivate(); } catch (CouldNotPerformException | InterruptedException ex) { ExceptionPrinter.printHistory("Could not deactivate " + this + " during shutdown!", ex, logger); } reset(); destroyed = true; if (shutdownDeamon != null) { shutdownDeamon.cancel(); } }
/** * @param scope * @throws InitializationException * @throws InterruptedException */ public void init(final rsb.Scope scope) throws InitializationException, InterruptedException { init(scope, RSBSharedConnectionConfig.getParticipantConfig()); }
/** * @param fieldId * @return */ protected final Descriptors.FieldDescriptor getDataFieldDescriptor(int fieldId) { return cloneDataBuilder().getDescriptorForType().findFieldByNumber(fieldId); }
synchronized (manageableLock) { try { final boolean alreadyActivated = isActive(); ParticipantConfig internalParticipantConfig = participantConfig; deactivate(); reset(); registerMethods(server); setControllerAvailabilityState(ControllerAvailabilityState.ONLINE); notifyChange(); } catch (InterruptedException ex) { logger.debug("Initial sync was skipped because of controller shutdown."); postInit(); activate();
synchronized (manageableLock) { try { validateInitialization(); } catch (final NotInitializedException ex) { newData = updateDataToPublish(cloneDataBuilder()); Event event = new Event(informer.getScope(), newData.getClass(), newData); event.getMetaData().setUserTime(RPCHelper.USER_TIME_KEY, System.nanoTime()); if (isActive()) { try { waitForMiddleware(NOTIFICATILONG_TIMEOUT, TimeUnit.MILLISECONDS); informer.publish(event); } catch (CouldNotPerformException ex) { notifyDataUpdate(newData); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Could not notify data update!", ex), logger);
private void scheduleNotifyChangeTask() { if (notifyChangeFuture == null || notifyChangeFuture.isDone()) { notifyChangeFuture = GlobalCachedExecutorService.submit(() -> { try { waitUntilReady(); syncRegistryFlags(); try { // lock internal registries so that no changes can take place while notifying lockInternalRegistries(); super.notifyChange(); } finally { // unlock internal registries only if this thread has locked them before if (lock.isWriteLockedByCurrentThread()) { unlockInternalRegistries(); } } } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } catch (CouldNotPerformException ex) { logger.warn("Could not notify change", ex); } finally { synchronized (CHANGE_NOTIFIER) { CHANGE_NOTIFIER.notifyAll(); } } }); } }
@Override public void deactivate() throws InterruptedException, CouldNotPerformException { super.deactivate(); deactivateRemoteRegistries(); removeDependencies(); }
@Override public void activate() throws InterruptedException, CouldNotPerformException { try { super.activate(); activateRemoteRegistries(); registerDependencies(); performInitialConsistencyCheck(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not activate location registry!", ex); } }
@Override protected void postInit() throws InitializationException, InterruptedException { super.postInit(); try { try {
/** * {@inheritDoc} * * @return {@inheritDoc} */ @Override public CompletableFuture<M> getDataFuture() { try { return CompletableFuture.completedFuture(getData()); } catch (NotAvailableException ex) { CompletableFuture future = new CompletableFuture(); future.completeExceptionally(ex); return future; } }
/** * {@inheritDoc} * * @param consumer {@inheritDoc} * @return {@inheritDoc} */ @Override public ClosableDataBuilder<MB> getDataBuilder(final Object consumer) { return new ClosableDataBuilder<>(getBuilderSetup(), consumer); }
public void validateActivation() throws InvalidStateException { if (!isActive()) { throw new InvalidStateException(this + " not activated!"); } }
/** * Create a communication service. * * @param builder the initial data builder * @throws InstantiationException if the creation fails */ public RSBCommunicationService(final MB builder) throws InstantiationException { logger.debug("Create RSBCommunicationService for component " + getClass().getSimpleName() + "."); this.dataBuilder = builder; try { if (builder == null) { throw new NotAvailableException("builder"); } this.controllerAvailabilityState = ControllerAvailabilityState.OFFLINE; this.dataLock = new ReentrantReadWriteLock(); this.dataBuilderReadLock = dataLock.readLock(); this.dataBuilderWriteLock = dataLock.writeLock(); this.messageClass = detectDataClass(); this.server = new NotInitializedRSBLocalServer(); this.informer = new NotInitializedRSBInformer<>(); this.dataObserver = new MessageObservable(this); this.dataObserver.setExecutorService(GlobalCachedExecutorService.getInstance().getExecutorService()); this.initialized = false; this.destroyed = false; this.shutdownDeamon = registerShutdownHook(this); } catch (CouldNotPerformException ex) { throw new InstantiationException(this, ex); } }
super.notifyChange(); } finally {
@Override public boolean isDataAvailable() { try { return getData().isInitialized(); } catch (NotAvailableException ex) { return false; } }
/** * {@inheritDoc} * * @param consumer {@inheritDoc} * @return {@inheritDoc} */ @Override public ClosableDataBuilder<MB> getDataBuilder(final Object consumer, final boolean notifyChange) { return new ClosableDataBuilder<>(getBuilderSetup(), consumer, notifyChange); }
/** * @param scope * @throws InitializationException * @throws InterruptedException */ public void init(final Scope scope) throws InitializationException, InterruptedException { init(scope, RSBSharedConnectionConfig.getParticipantConfig()); }
/** * @param name * @return * @throws NotAvailableException */ protected final Object getDataField(String name) throws NotAvailableException { try { MB dataClone = cloneDataBuilder(); Descriptors.FieldDescriptor findFieldByName = dataClone.getDescriptorForType().findFieldByName(name); if (findFieldByName == null) { throw new NotAvailableException("Field[" + name + "] does not exist for type " + dataClone.getClass().getName()); } return dataClone.getField(findFieldByName); } catch (Exception ex) { throw new NotAvailableException(name, this, ex); } }
/** * {@inheritDoc} * * @return {@inheritDoc} * @throws org.openbase.jul.exception.CouldNotPerformException {@inheritDoc} */ @Override public M requestStatus() throws CouldNotPerformException { logger.debug("requestStatus of " + this); try { return getData(); } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw ExceptionPrinter.printHistoryAndReturnThrowable(new CouldNotPerformException("Could not request status update.", ex), logger, LogLevel.ERROR); } }
/** * @param scope * @throws InitializationException * @throws InterruptedException */ public void init(final String scope) throws InitializationException, InterruptedException { try { init(new rsb.Scope(scope)); } catch (CouldNotPerformException | NullPointerException ex) { throw new InitializationException(this, ex); } }