public static void waitForData(long timeout, TimeUnit timeUnit) throws CouldNotPerformException, InterruptedException { getRegistry().waitForData(timeout, timeUnit); }
/** * @return @throws InterruptedException * * @throws NotAvailableException */ public synchronized static UserActivityRegistryRemote getRegistry() throws InterruptedException, NotAvailableException { try { if (shutdown) { throw new InvalidStateException("Remote service is shutting down!"); } if (registryRemote == null) { try { registryRemote = new UserActivityRegistryRemote(); registryRemote.init(); registryRemote.activate(); registryRemote.lock(REMOTE_LOCK); } catch (Exception ex) { if (registryRemote != null) { registryRemote.unlock(REMOTE_LOCK); registryRemote.shutdown(); registryRemote = null; } throw ExceptionPrinter.printHistoryAndReturnThrowable(new CouldNotPerformException("Could not start cached user activity registry remote!", ex), LOGGER); } } return registryRemote; } catch (CouldNotPerformException ex) { throw new NotAvailableException("cached user activity registry", ex); } }
@Override public Boolean isUserActivityClassRegistryConsistent() throws CouldNotPerformException { try { validateData(); return getData().getUserActivityClassRegistryConsistent(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not check consistency!", ex); } }
@Override public List<UserActivityConfig> getUserActivityConfigsByType(UserActivityType userActivityType) throws CouldNotPerformException { validateData(); List<UserActivityConfig> userActivityConfigList = new ArrayList<>(); String userActivityClassId = getUserActivityClassByType(userActivityType).getId(); for (UserActivityConfig userActivityConfig : userActivityConfigRemoteRegistry.getMessages()) { if (userActivityConfig.getUserActivityClassId().equals(userActivityClassId)) { userActivityConfigList.add(userActivityConfig); } } return userActivityConfigList; }
@Override public Boolean isUserActivityClassRegistryReadOnly() throws CouldNotPerformException { validateData(); try { if (JPService.getProperty(JPReadOnly.class).getValue() || !isConnected()) { return true; } } catch (JPServiceException ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Could not access java property!", ex), logger); } return getData().getUserActivityClassRegistryReadOnly(); }
public UserActivityRegistryRemote() throws InstantiationException, InterruptedException { super(JPUserActivityRegistryScope.class, UserActivityRegistryData.class); try { this.userActivityClassRemoteRegistry = new SynchronizedRemoteRegistry<>(this.getIntenalPriorizedDataObservable(), this, UserActivityRegistryData.USER_ACTIVITY_CLASS_FIELD_NUMBER); this.userActivityConfigRemoteRegistry = new SynchronizedRemoteRegistry<>(this.getIntenalPriorizedDataObservable(), this, UserActivityRegistryData.USER_ACTIVITY_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { throw new InstantiationException(this, ex); } }
private void updateComboBoxModel() throws InterruptedException, CouldNotPerformException { Object selected = userActivityComboBox.getModel().getSelectedItem(); List<UserActivityConfigHolder> userActivityConfigHolderList = new ArrayList<>(); for (UserActivityConfig userActivityConfig : Registries.getUserActivityRegistry().getUserActivityConfigs()) { userActivityConfigHolderList.add(new UserActivityConfigHolder(userActivityConfig)); } Collections.sort(userActivityConfigHolderList); userActivityComboBox.setModel(new DefaultComboBoxModel(userActivityConfigHolderList.toArray())); if (selected != null) { userActivityComboBox.getModel().setSelectedItem(selected); } else { userActivityComboBox.getModel().setSelectedItem(userActivityComboBox.getModel().getElementAt(0)); } }
private void initDynamicComponents() throws org.openbase.jul.exception.InstantiationException { try { Registries.getUserActivityRegistry(true); updateComboBoxModel(); Registries.getUserActivityRegistry().addDataObserver((Observable<UserActivityRegistryData> source, UserActivityRegistryData data) -> { updateComboBoxModel(); }); } catch (CouldNotPerformException ex) { throw new org.openbase.jul.exception.InstantiationException(this, "Could not init dynamic components", ex); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } }
@Override protected void updateDynamicComponents() { try { if (getProviderService().getUserActivityState().hasActivityId() && !getProviderService().getUserActivityState().getActivityId().isEmpty()) { UserActivityConfig userActivityConfig = Registries.getUserActivityRegistry().getUserActivityConfigById(getProviderService().getUserActivityState().getActivityId()); logger.info("state: " + userActivityConfig.getLabel()); userActivityComboBox.getModel().setSelectedItem(new UserActivityConfigHolder(userActivityConfig)); userActivityStateLabel.setText("Current UserActivityState = " + userActivityConfig.getLabel()); } } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } }
@Override public Boolean isUserActivityConfigRegistryReadOnly() throws CouldNotPerformException { validateData(); try { if (JPService.getProperty(JPReadOnly.class).getValue() || !isConnected()) { return true; } } catch (JPServiceException ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Could not access java property!", ex), logger); } return getData().getUserActivityConfigRegistryReadOnly(); }
public static void waitForData() throws InterruptedException, CouldNotPerformException { getRegistry().waitForData(); }
@Override public Boolean isUserActivityConfigRegistryConsistent() throws CouldNotPerformException { try { validateData(); return getData().getUserActivityConfigRegistryConsistent(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not check consistency!", ex); } }
/** * Returns an initialized and activated remote registry. * * @param waitForData defines if this call should block until the registry data is available. * @return the remote registry instance. * @throws NotAvailableException * @throws InterruptedException is thrown if thread is externally interrupted. */ public static UserActivityRegistryRemote getUserActivityRegistry(final boolean waitForData) throws CouldNotPerformException, InterruptedException { if (waitForData) { CachedUserActivityRegistryRemote.getRegistry().waitForData(); } return CachedUserActivityRegistryRemote.getRegistry(); }