/** * Gets the center coordinates of the unit's BoundingBox in the unit coordinate system as a Point3d object. * * @return center coordinates of the unit's BoundingBox relative to unit * * @throws NotAvailableException is thrown if the center can not be calculate. */ default Point3d getUnitBoundingBoxCenterPoint3d() throws NotAvailableException { return getLocationRegistry().getUnitBoundingBoxCenterPoint3d(getConfig()); }
/** * Add an observer which is only notified if the value for the current * value of the given service type changes. * * @param serviceType The service type on which the observer is added. * @param observer The observer which is added. */ @Override default void addServiceStateObserver(final ServiceType serviceType, final Observer observer) { addServiceStateObserver(ServiceTempus.CURRENT, serviceType, observer); }
/** * Gets the Transform3D of the transformation from root to unit coordinate system. * * @return transform relative to root location * * @throws NotAvailableException is thrown if the transformation is not available. * @throws InterruptedException is thrown if the thread was externally interrupted. * @deprecated please use {@code getRootToUnitTransform3D()} instead. */ default Transform3D getTransform3D() throws NotAvailableException, InterruptedException { return getRootToUnitTransform3D(); }
public static void verifyUnitType(final Unit<?> unit) throws VerificationFailedException { try { UnitConfigProcessor.verifyUnitType(unit.getConfig(), unit.getUnitType()); } catch (NotAvailableException ex) { throw new VerificationFailedException("Could not verify unit type!", ex); } }
public static boolean isDalUnit(final Unit<?> unit) throws CouldNotPerformException { return UnitConfigProcessor.isDalUnit(unit.getConfig()); }
private ServiceConfig loadServiceConfig() throws CouldNotPerformException { for (final ServiceConfig serviceConfig : ((Unit<?>) unit).getConfig().getServiceConfigList()) { if (serviceConfig.getServiceDescription().getType().equals(serviceType)) { return serviceConfig; } } throw new CouldNotPerformException("Could not detect service config! Service[" + serviceType.name() + "] is not configured in Unit[" + ((Unit) unit).getId() + "]!"); }
/** * Returns the variable provider of this unit like {@code generateVariablePool()}. Additionally this provider also contains variables related to the given service of this unit. * For this it's needed that this unit supports the given service. Additional to the {@code generateVariablePool()} this method further provides: * * BindingServiceConfig (if available) * * ServiceMetaConfig (if available) * * ServiceConfig (protobuf fields) * * @return a key - value pair pool providing all related variable of this unit including the service variables. * * @throws NotAvailableException is thrown if the variable pool is not available e.g. because the unit is not compatible with the given service type.. */ default VariableProvider generateVariablePool(final ServiceType serviceType) throws NotAvailableException { for (ServiceConfig serviceConfig : getConfig().getServiceConfigList()) { if (serviceConfig.getServiceDescription().getType() == serviceType) { return generateVariablePool(serviceConfig); } } throw new NotAvailableException("VariableProvider", new InvalidStateException("ServiceType[" + serviceType.name() + "] not supported by " + this)); }
final UnitConfig unitConfig = getConfig(); final MetaConfigPool configPool = new MetaConfigPool(); if (isDalUnit()) { UnitConfig hostUnitConfig = getHostUnitConfig(); configPool.register(new MetaConfigVariableProvider("HostConfigMetaConfig", hostUnitConfig.getMetaConfig())); configPool.register(new ProtobufVariableProvider(hostUnitConfig));
MultiException.ExceptionStack exceptionStack = null; Snapshot.Builder snapshotBuilder = Snapshot.newBuilder(); for (ServiceDescription serviceDescription : getUnitTemplate().getServiceDescriptionList()) { try { ServiceStateDescription.Builder serviceStateDescription = ServiceStateDescription.newBuilder().setServiceType(serviceDescription.getType()).setUnitId(getId()); serviceStateDescription.setUnitId(getId()); serviceStateDescription.setUnitType(getUnitTemplate().getType()); serviceStateDescription.setServiceType(serviceDescription.getType()); serviceStateDescription.setServiceAttributeType(serviceJSonProcessor.getServiceAttributeType(serviceAttribute));
public static boolean detectAutoRepeat(final Unit unit) { try { return unit.generateVariablePool().getValue("COMPANY").equalsIgnoreCase("philips"); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory("Could not detect auto repeat of "+unit+"!", ex, LOGGER, LogLevel.WARN); } return false; } }
default long getLatestTransactionId() throws CouldNotPerformException { long latestTransactionId = -1; for (ServiceDescription serviceDescription : getUnitTemplate().getServiceDescriptionList()) { if (serviceDescription.getPattern() != ServicePattern.OPERATION) { continue; } latestTransactionId = Math.max(latestTransactionId, getTransactionIdByServiceType(serviceDescription.getType())); } if (latestTransactionId == -1) { throw new NotAvailableException("transaction id"); } return latestTransactionId; }
@RPCMethod @Override default Future<Void> restoreSnapshot(final Snapshot snapshot) throws CouldNotPerformException, InterruptedException { try { Collection<Future> futureCollection = new ArrayList<>(); for (final ServiceStateDescription serviceStateDescription : snapshot.getServiceStateDescriptionList()) { ActionDescription actionDescription = ActionDescription.newBuilder().setServiceStateDescription(serviceStateDescription).build(); futureCollection.add(applyAction(actionDescription)); } return GlobalCachedExecutorService.allOf(futureCollection); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not record snapshot!", ex); } }
/** * Get the transaction id of a service state in the data of this unit. * * @param serviceType * * @return * * @throws CouldNotPerformException */ default long getTransactionIdByServiceType(ServiceType serviceType) throws CouldNotPerformException { Message serviceState = (Message) Services.invokeProviderServiceMethod(serviceType, getData()); Descriptors.FieldDescriptor fieldDescriptor = ProtoBufFieldProcessor.getFieldDescriptor(serviceState, "responsible_action"); ActionDescription actionDescription = (ActionDescription) serviceState.getField(fieldDescriptor); return actionDescription.getTransactionId(); }
public static boolean isHostUnit(final Unit<?> unit) throws CouldNotPerformException { return UnitConfigProcessor.isHostUnit(unit.getConfig()); }
public static void verifyUnitConfig(final Unit<?> unit) throws VerificationFailedException { try { UnitConfigProcessor.verifyUnitConfig(unit.getConfig(), unit.getUnitType()); } catch (NotAvailableException ex) { throw new VerificationFailedException("Could not verify unit type!", ex); } }
/** * Returns the variable provider of this unit like {@code generateVariablePool()}. Additionally this provider also contains variables related to the given service of this unit. * For this it's needed that this unit supports the given service. Additional to the {@code generateVariablePool()} this method further provides: * * BindingServiceConfig (if available) * * ServiceMetaConfig (if available) * * ServiceConfig (protobuf fields) * * @return a key - value pair pool providing all related variable of this unit including the service variables. * * @throws NotAvailableException is thrown if the variable pool is not available. */ default VariableProvider generateVariablePool(final ServiceConfig serviceConfig) throws NotAvailableException { final MetaConfigPool configPool = (MetaConfigPool) generateVariablePool(); if (serviceConfig.hasBindingConfig()) { configPool.register(new MetaConfigVariableProvider("BindingServiceConfig", serviceConfig.getBindingConfig().getMetaConfig())); } configPool.register(new MetaConfigVariableProvider("ServiceMetaConfig", serviceConfig.getMetaConfig())); configPool.register(new ProtobufVariableProvider(serviceConfig)); return configPool; }
/** * Method returns the transformation leading from the unit to the root location. * * @return the transformation * * @throws org.openbase.jul.exception.NotAvailableException */ default Transform getUnitToRootTransformation() throws NotAvailableException { try { return getLocationRegistry().getUnitToRootTransformation(getConfig()); } catch (final CouldNotPerformException ex) { throw new NotAvailableException("UnitTransformation", ex); } }
public static boolean isBaseUnit(final Unit<?> unit) throws CouldNotPerformException { return UnitConfigProcessor.isBaseUnit(unit.getConfig()); }
/** * Gets the position of the unit relative to the root location as a Translation object. * * @return position relative to the root location * * @throws NotAvailableException is thrown if the transformation is not available. */ default Translation getUnitPositionGlobal() throws NotAvailableException { try { return getLocationRegistry().getUnitPositionGlobal(getConfig()); } catch (NotAvailableException ex) { throw new NotAvailableException("GlobalPosition", ex); } }
/** * Method returns the unit shape of this unit. * <p> * If this unit configuration does not provide any shape information the shape of the unit host will be returned. * In case the unit host even does not provide any shape information and the unit is a device than the shape of the device class will be used. * * @return the shape representing the unit. * * @throws NotAvailableException is thrown if the unit shape is not available or the resolution has been failed. */ default Shape getUnitShape() throws NotAvailableException { try { try { return Registries.getLocationRegistry().getUnitShape(getConfig()); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new FatalImplementationErrorException("getLocationRegistry should not throw InterruptedExceptions anymore!", Unit.class, ex); } } catch (final CouldNotPerformException ex) { throw new NotAvailableException("UnitShape", ex); } }