@Override public void registerMethods(final RSBLocalServer server) throws CouldNotPerformException { super.registerMethods(server); RPCHelper.registerInterface(UserActivityRegistry.class, this, server); }
@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 public void deactivate() throws InterruptedException, CouldNotPerformException { super.deactivate(); deactivateRemoteRegistries(); removeDependencies(); }
try { try { registerRegistries(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not register all internal registries!", ex); registerRemoteRegistries(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could register all remote registries!", ex); activateVersionControl(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not activate version control for all internal registries!", ex); loadRegistries(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not load all internal registries!", ex); registerConsistencyHandler(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not register consistency handler for all internal registries!", ex); registerPlugins(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not register plugins for all internal registries!", ex); registerObserver(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not register observer for all internal registries!", ex);
try { syncRegistryFlags(); for (ProtoBufFileSynchronizedRegistry registry : getRegistries()) { if (registry.isBusy()) { scheduleNotifyChangeTask(); return; lockInternalRegistries(); super.notifyChange(); } finally { unlockInternalRegistries();
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(); } } }); } }
for (Registry registry : getRegistries()) { try { if (registry.tryLockRegistry()) { unlockInternalRegistries();
/** * {@inheritDoc} * * @throws InterruptedException {@inheritDoc} */ @Override public void waitUntilReady() throws InterruptedException { while (true) { // handle interruption if (Thread.interrupted()) { throw new InterruptedException(); } synchronized (CHANGE_NOTIFIER) { // check ready state if (isReady()) { return; } // sleep until change // todo: why is this timeout needed??? Is there any event skipped? Please debug me! CHANGE_NOTIFIER.wait(500); } } }
@Override protected void deactivateRemoteRegistries() throws CouldNotPerformException, InterruptedException { getRegistryRemotes().forEach((registryRemote) -> { registryRemote.removeDataObserver(virtualRegistrySynchronizer); }); super.deactivateRemoteRegistries(); }
@Override public void verify() throws VerificationFailedException { if (!getLaunchable().isConsistent()) { throw new VerificationFailedException(getLaunchable().getClass().getSimpleName() + " is inconsistent"); } } }
private void activateVersionControl() throws CouldNotPerformException { Package versionConverterPackage; for (final ProtoBufFileSynchronizedRegistry registry : registryList) { try { versionConverterPackage = detectVersionConverterPackage(); } catch (NotAvailableException ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Skip version control activation for " + registry + "!", ex), logger, LogLevel.WARN); continue; } registry.activateVersionControl(versionConverterPackage); } }
@Override protected void activateRemoteRegistries() throws CouldNotPerformException, InterruptedException { /* The order here is important! * If the VirtualRegistrySynchronizer would be registered first the data type would be notified while the remote registries * have not synced. This way getter for the VirtualRegistryController would not contain the updated values when called within an observer. */ super.activateRemoteRegistries(); getRegistryRemotes().forEach((registryRemote) -> { registryRemote.addDataObserver(virtualRegistrySynchronizer); // perform initial sync if data already available if (registryRemote.isDataAvailable()) { try { virtualRegistrySynchronizer.update(null, (RM) registryRemote.getData()); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Initial sync of [" + this + "] failed", ex), logger, LogLevel.WARN); } } }); }
@Override public void registerMethods(final RSBLocalServer server) throws CouldNotPerformException { super.registerMethods(server); RPCHelper.registerInterface(UnitRegistry.class, this, server); }