@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); } } }); }
protected void bindRegistryRemoteToRemoteRegistry(SynchronizedRemoteRegistry remoteRegistry, RegistryRemote<? extends GeneratedMessage> registryRemote, Integer fieldNumber) throws CouldNotPerformException { try { Descriptors.FieldDescriptor fieldDescriptor = null; try { fieldDescriptor = ProtoBufFieldProcessor.getFieldDescriptors(registryRemote.getDataClass(), fieldNumber)[0]; } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Invalid field descriptor for [" + registryRemote.getDataClass().getSimpleName() + "]", ex); } if (!registryRemotes.contains(registryRemote)) { throw new CouldNotPerformException("Trying to bind to unregistered registryRemote"); } remoteRegistryFieldDescriptorMap.put(remoteRegistry, fieldDescriptor); remoteRegistrySyncMap.put(remoteRegistry, registryRemote); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not bind fieldNumber[" + fieldNumber + "] of [" + registryRemote.getDataClass().getSimpleName() + "] to remoteRegistry[" + remoteRegistry + "]", ex); } }
@Override protected void deactivateRemoteRegistries() throws CouldNotPerformException, InterruptedException { getRegistryRemotes().forEach((registryRemote) -> { registryRemote.removeDataObserver(virtualRegistrySynchronizer); }); super.deactivateRemoteRegistries(); }
@Override public boolean isDataAvailable() { for (RegistryRemote registryRemote : registryRemotes) { if (!registryRemote.isDataAvailable()) { return false; } } // TODO release: // workaround, should be removed in release scrab virtualRegistryInitiallySynchronized = virtualRegistryInitiallySynchronized || isVirtualRegistrySynchronized(); return super.isDataAvailable() && virtualRegistryInitiallySynchronized; }
@Override public void waitForData() throws CouldNotPerformException, InterruptedException { for (RegistryRemote registryRemote : registryRemotes) { registryRemote.waitForData(); } super.waitForData(); waitForVirtualRegistrySync(); }
for (SynchronizedRemoteRegistry remoteRegistry : remoteRegistrySyncMap.keySet()) { try { final List registryRemoteMessageList = new ArrayList((List) remoteRegistrySyncMap.get(remoteRegistry).getData().getField(remoteRegistryFieldDescriptorMap.get(remoteRegistry))); final List registryRemoteFilteredMessageList = remoteRegistry.getFilter().filter(registryRemoteMessageList);