/** * {@inheritDoc} * * @throws org.openbase.jul.exception.CouldNotPerformException {@inheritDoc} */ @Override public List<UnitConfig> getNeighborLocations(String locationId) throws CouldNotPerformException { UnitConfig locationConfig = getLocationConfigById(locationId); if (locationConfig.getLocationConfig().getType() != LocationConfig.LocationType.TILE) { throw new CouldNotPerformException("Id[" + locationId + "] does not belong to a tile and therefore its neighbors aren't defined!"); } Map<String, UnitConfig> neighborMap = new HashMap<>(); for (UnitConfig connectionConfig : getConnectionConfigs()) { if (connectionConfig.getConnectionConfig().getTileIdList().contains(locationId)) { for (String id : connectionConfig.getConnectionConfig().getTileIdList()) { if (id.equals(locationId)) { continue; } neighborMap.put(id, getLocationConfigById(id)); } } } return new ArrayList<>(neighborMap.values()); }
public static void waitForData(long timeout, TimeUnit timeUnit) throws CouldNotPerformException, InterruptedException { getRegistry().waitForData(timeout, timeUnit); }
/** * {@inheritDoc} * * @throws org.openbase.jul.exception.CouldNotPerformException {@inheritDoc} */ @Override public List<UnitConfig> getUnitConfigsByLocationLabel(final String locationLabel) throws CouldNotPerformException { final HashMap<String, UnitConfig> unitConfigMap = new HashMap<>(); for (UnitConfig location : getLocationConfigsByLabel(locationLabel)) { for (UnitConfig unitConfig : getUnitConfigsByLocation(location.getId())) { unitConfigMap.put(unitConfig.getId(), unitConfig); } } return new ArrayList<>(unitConfigMap.values()); }
/** * {@inheritDoc} * * @throws org.openbase.jul.exception.NotAvailableException {@inheritDoc} */ @Override public List<UnitConfig> getUnitConfigsByLocation(final String locationId, final boolean recursive) throws CouldNotPerformException { final List<UnitConfig> unitConfigList = new ArrayList<>(); for (String unitConfigId : getLocationConfigById(locationId).getLocationConfig().getUnitIdList()) { final UnitConfig unitConfig = unitRegistry.getUnitConfigById(unitConfigId); if (recursive || unitConfig.getPlacementConfig().getLocationId().equals(locationId)) { unitConfigList.add(unitConfig); } } return unitConfigList; }
ArrayList<LocationUnitConfigHolder> locationConfigHolderList = new ArrayList<>(); locationConfigHolderList.add(ALL_LOCATION); for (UnitConfig locationUnitConfig : Registries.getLocationRegistry().getLocationConfigs()) { locationConfigHolderList.add(new LocationUnitConfigHolder(locationUnitConfig)); if (selectedUnitType == UnitType.UNKNOWN) { if (selectedLocationConfigHolder != null && !selectedLocationConfigHolder.isNotSpecified()) { for (final UnitConfig config : Registries.getLocationRegistry().getUnitConfigsByLocation(selectedLocationConfigHolder.getConfig().getId())) { try { unitConfigHolderList.add(new UnitConfigHolder(config, Registries.getLocationRegistry().getLocationConfigById(config.getPlacementConfig().getLocationId()))); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); throw new InvalidStateException("Could not load location unit of " + config.getLabel() + " because its not configured!"); unitConfigHolderList.add(new UnitConfigHolder(config, Registries.getLocationRegistry().getLocationConfigById(config.getPlacementConfig().getLocationId()))); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); for (UnitConfig config : Registries.getLocationRegistry().getUnitConfigsByLocation(selectedUnitType, selectedLocationConfigHolder.getConfig().getId())) { try { unitConfigHolderList.add(new UnitConfigHolder(config, Registries.getLocationRegistry().getLocationConfigById(config.getPlacementConfig().getLocationId()))); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); unitConfigHolderList.add(new UnitConfigHolder(config, Registries.getLocationRegistry().getLocationConfigById(config.getPlacementConfig().getLocationId()))); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack);
public PartyLightTileFollowerApp() throws InstantiationException, InterruptedException { super(PartyLightTileFollowerApp.class); try { Registries.getLocationRegistry().waitForData(); Registries.getUnitRegistry().waitForData(); this.locationRemoteMap = new HashMap<>(); // init tile remotes for (final UnitConfig locationUnitConfig : Registries.getLocationRegistry().getLocationConfigs()) { if (!locationUnitConfig.getLocationConfig().getType().equals(LocationConfigType.LocationConfig.LocationType.TILE)) { continue; } locationRemoteMap.put(locationUnitConfig.getId(), Units.getUnit(locationUnitConfig, false, Units.LOCATION)); } } catch (CouldNotPerformException ex) { throw new InstantiationException(this, ex); } }
if (!Registries.getLocationRegistry().getUnitConfigsByLocation(UnitTemplateType.UnitTemplate.UnitType.COLORABLE_LIGHT, locationRemote.getId()).isEmpty()) { try { if (locationRemote.isConnected() && locationRemote.isDataAvailable()) { for (UnitConfig neighborConfig : Registries.getLocationRegistry().getNeighborLocations(locationRemote.getId())) {
public void init() throws InitializationException, InterruptedException, CouldNotPerformException { statusPanel = StatusPanel.getInstance(); statusPanel.setStatus("Wait for unit registry...", StatusPanel.StatusType.INFO, true); Registries.getUnitRegistry().waitForData(); statusPanel.setStatus("Wait for location registry...", StatusPanel.StatusType.INFO, true); Registries.getLocationRegistry().waitForData(); statusPanel.setStatus("Connection established.", StatusPanel.StatusType.INFO, 3); // register change observer Registries.getUnitRegistry().addDataObserver((Observable<UnitRegistryDataType.UnitRegistryData> source, UnitRegistryDataType.UnitRegistryData data) -> { SwingUtilities.invokeLater(() -> { updateDynamicComponents(); }); }); Registries.getLocationRegistry().addDataObserver((Observable<LocationRegistryData> source, LocationRegistryData data) -> { SwingUtilities.invokeLater(() -> { updateDynamicComponents(); }); }); init = true; setEnable(true); updateDynamicComponents(); }
/** * {@inheritDoc} * * @throws org.openbase.jul.exception.CouldNotPerformException {@inheritDoc} */ @Override public List<UnitConfig> getUnitConfigsByLocation(final String locationId) throws CouldNotPerformException { return getUnitConfigsByLocation(locationId, true); }
public LocationManagerController() throws org.openbase.jul.exception.InstantiationException, InterruptedException { try { this.locationFactory = LocationFactoryImpl.getInstance(); this.connectionFactory = ConnectionFactoryImpl.getInstance(); this.locationRegistry = new ControllerRegistryImpl<>(); this.connectionRegistry = new ControllerRegistryImpl<>(); this.locationRegistrySynchronizer = new ActivatableEntryRegistrySynchronizer<String, LocationController, UnitConfig, UnitConfig.Builder>(locationRegistry, Registries.getLocationRegistry().getLocationConfigRemoteRegistry(), Registries.getLocationRegistry(), locationFactory) { @Override public boolean activationCondition(final UnitConfig config) { return config.getEnablingState().getValue() == State.ENABLED; } }; this.connectionRegistrySynchronizer = new ActivatableEntryRegistrySynchronizer<String, ConnectionController, UnitConfig, UnitConfig.Builder>(connectionRegistry, Registries.getLocationRegistry().getConnectionConfigRemoteRegistry(), Registries.getLocationRegistry(), connectionFactory) { @Override public boolean activationCondition(final UnitConfig config) { return config.getEnablingState().getValue() == State.ENABLED; } }; this.unitGrouptFactory = UnitGroupFactoryImpl.getInstance(); this.unitGroupRegistry = new ControllerRegistryImpl<>(); this.unitGroupRegistrySynchronizer = new ActivatableEntryRegistrySynchronizer<String, UnitGroupController, UnitConfig, UnitConfig.Builder>(unitGroupRegistry, Registries.getUnitRegistry().getUnitGroupUnitConfigRemoteRegistry(), Registries.getUnitRegistry(), unitGrouptFactory) { @Override public boolean activationCondition(final UnitConfig config) { return config.getEnablingState().getValue() == State.ENABLED; } }; } catch (CouldNotPerformException ex) { throw new org.openbase.jul.exception.InstantiationException(this, ex); } }
@Override public List<String> getNeighborLocationIds() throws CouldNotPerformException { List<String> neighborIdList = new ArrayList<>(); try { for (UnitConfig locationConfig : Registries.getLocationRegistry().getNeighborLocations(getId())) { neighborIdList.add(locationConfig.getId()); } } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } return neighborIdList; }
public List<ConnectionRemote> getConnectionList(final boolean waitForData) throws CouldNotPerformException { if (!getConfig().getLocationConfig().getType().equals(LocationType.TILE)) { throw new CouldNotPerformException("Location is not a Tile!"); } List<ConnectionRemote> connectionList = new ArrayList<>(); try { for (UnitConfig connectionUnitConfig : CachedLocationRegistryRemote.getRegistry().getConnectionConfigs()) { ConnectionRemote connection = Units.getUnit(connectionUnitConfig, waitForData, CONNECTION); if (connection.getConfig().getConnectionConfig().getTileIdList().contains(getId())) { connectionList.add(connection); } } } catch (InterruptedException ex) { throw new CouldNotPerformException("Could not get all connections!", ex); } return connectionList; }
public List<LocationRemote> getChildLocationList(final boolean waitForData) throws CouldNotPerformException { final List<LocationRemote> childList = new ArrayList<>(); for (String childId : getConfig().getLocationConfig().getChildIdList()) { try { childList.add(Units.getUnit(CachedLocationRegistryRemote.getRegistry().getLocationConfigById(childId), waitForData, LOCATION)); } catch (InterruptedException ex) { throw new CouldNotPerformException("Could not get all child locations!", ex); } } return childList; }
/** * {@inheritDoc} * * @throws org.openbase.jul.exception.CouldNotPerformException {@inheritDoc} * @throws org.openbase.jul.exception.NotAvailableException {@inheritDoc} */ @Override public List<ServiceConfig> getServiceConfigsByLocation(final String locationId) throws CouldNotPerformException, NotAvailableException { List<ServiceConfig> serviceConfigList = new ArrayList<>(); for (UnitConfig unitConfig : getUnitConfigsByLocation(locationId)) { serviceConfigList.addAll(unitConfig.getServiceConfigList()); } return serviceConfigList; }
locationRemoteFactory = new LocationRemoteFactoryImpl(); connectionRemoteFactory = new ConnectionRemoteFactoryImpl(); locationRegistrySynchronizer = new RegistrySynchronizer<String, LocationRemote, UnitConfig, UnitConfig.Builder>(locationRegistry, Registries.getLocationRegistry().getLocationConfigRemoteRegistry(), Registries.getLocationRegistry(), locationRemoteFactory) { this.connectionRegistrySynchronizer = new RegistrySynchronizer<String, ConnectionRemote, UnitConfig, UnitConfig.Builder>(connectionRegistry, Registries.getLocationRegistry().getConnectionConfigRemoteRegistry(), Registries.getLocationRegistry(), connectionRemoteFactory) {
public List<LocationRemote> getNeighborLocationList(final boolean waitForData) throws CouldNotPerformException { final List<LocationRemote> neighborList = new ArrayList<>(); try { for (UnitConfig locationUnitConfig : CachedLocationRegistryRemote.getRegistry().getNeighborLocations(getId())) { neighborList.add(Units.getUnit(locationUnitConfig, waitForData, LOCATION)); } } catch (InterruptedException ex) { throw new CouldNotPerformException("Could not get all neighbors!", ex); } return neighborList; }
/** * Method collects all connections between this and the given location and returns those instances. * * @param locationID the location id of the location to check. * @param waitForData flag defines if the method should block until all needed instances are available. * @return a collection of unit connection remotes. * @throws CouldNotPerformException is thrown if the check could not be performed e.g. if some data is not available yet. */ public List<ConnectionRemote> getDirectConnectionList(final String locationID, final boolean waitForData) throws CouldNotPerformException { if (!getConfig().getLocationConfig().getType().equals(LocationType.TILE)) { throw new CouldNotPerformException("Location is not a Tile!"); } List<ConnectionRemote> connectionList = new ArrayList<>(); try { for (UnitConfig connectionUnitConfig : Registries.getLocationRegistry().getConnectionConfigs()) { ConnectionRemote connection = Units.getUnit(connectionUnitConfig, waitForData, CONNECTION); if (connectionUnitConfig.getConnectionConfig().getTileIdList().contains(getId()) && connectionUnitConfig.getConnectionConfig().getTileIdList().contains(locationID)) { connectionList.add(connection); } } } catch (InterruptedException ex) { throw new CouldNotPerformException("Could not get all connections!", ex); } return connectionList; }
public List<LocationRemote> getChildLocationList(final boolean waitForData) throws CouldNotPerformException { final List<LocationRemote> childList = new ArrayList<>(); for (String childId : getConfig().getLocationConfig().getChildIdList()) { try { childList.add(Units.getUnit(CachedLocationRegistryRemote.getRegistry().getLocationConfigById(childId), waitForData, LOCATION)); } catch (InterruptedException ex) { throw new CouldNotPerformException("Could not get all child locations!", ex); } } return childList; } }
public static void waitForData() throws InterruptedException, CouldNotPerformException { getRegistry().waitForData(); }
/** * {@inheritDoc} * * @throws org.openbase.jul.exception.CouldNotPerformException {@inheritDoc} * @throws org.openbase.jul.exception.NotAvailableException {@inheritDoc} */ @Override public List<UnitConfig> getUnitConfigsByLocationLabel(final UnitType unitType, final String locationLabel) throws CouldNotPerformException { HashMap<String, UnitConfig> unitConfigMap = new HashMap<>(); for (UnitConfig location : getLocationConfigsByLabel(locationLabel)) { for (UnitConfig unitConfig : getUnitConfigsByLocation(unitType, location.getId())) { unitConfigMap.put(unitConfig.getId(), unitConfig); } } return new ArrayList<>(unitConfigMap.values()); }