java.lang.Object
de.iip_ecosphere.platform.services.environment.ServiceStub
All Implemented Interfaces:
ParameterConfigurerProvider, Service, ServiceBase

public class ServiceStub extends Object implements Service
Implements the service interface through AAS protocol operations. The operations stored in here can be directly used as suppliers, consumers and functions for an AAS. In addition, this class can be used standalone with an appropriate invocables creator as client stub.
Author:
Holger Eichelberger, SSE
  • Field Details

    • getters

      private Map<String,de.iip_ecosphere.platform.support.aas.Invokable> getters
    • setters

      private Map<String,de.iip_ecosphere.platform.support.aas.Invokable> setters
    • operations

      private Map<String,de.iip_ecosphere.platform.support.aas.Invokable> operations
  • Constructor Details

    • ServiceStub

      public ServiceStub(de.iip_ecosphere.platform.support.aas.InvocablesCreator iCreator, String serviceId, String... path)
      Creates the setup and registers the operations.
      Parameters:
      iCreator - the AAS invocables creator
      serviceId - the service id to create the qualified names via ServiceMapper.getQName(Service, String)
      path - to submodel element representing serviceId
    • ServiceStub

      public ServiceStub(de.iip_ecosphere.platform.support.aas.InvocablesCreator iCreator, String serviceId, de.iip_ecosphere.platform.support.function.IOSupplier<de.iip_ecosphere.platform.support.aas.Aas> aasSupplier, String... path)
      Creates the setup and registers the operations.
      Parameters:
      iCreator - the AAS invocables creator
      serviceId - the service id to create the qualified names via ServiceMapper.getQName(Service, String)
      aasSupplier - overrides the default AAS supplier (AasPartRegistry.retrieveIipAas(), may be null for the default
      path - to submodel element representing serviceId
  • Method Details

    • registerProperty

      private void registerProperty(String name, de.iip_ecosphere.platform.support.aas.Invokable getter, de.iip_ecosphere.platform.support.aas.Invokable setter)
      Registers the functors for a property.
      Parameters:
      name - the (unqualified) name of the property
      getter - the getter functor
      setter - the setter functor
    • registerOperation

      private void registerOperation(String name, de.iip_ecosphere.platform.support.aas.Invokable operation)
      Registers the functor for an operation.
      Parameters:
      name - the (unqualified) name of the property
      operation - the operation functor
    • getGetter

      public de.iip_ecosphere.platform.support.aas.Invokable getGetter(String name)
      Returns the getter invokable for a given property.
      Parameters:
      name - the (unqualified) property name
      Returns:
      the invokable, may be null for none
    • getSetter

      public de.iip_ecosphere.platform.support.aas.Invokable getSetter(String name)
      Returns the setter invokable for a given property.
      Parameters:
      name - the (unqualified) property name
      Returns:
      the invokable, may be null for none
    • getOperation

      public de.iip_ecosphere.platform.support.aas.Invokable getOperation(String name)
      Returns the invokable for a given operation.
      Parameters:
      name - the (unqualified) operation name
      Returns:
      the invokable, may be null for none
    • convertGetterResult

      private <T> T convertGetterResult(String getId, T dflt, Function<Object,T> conversion)
      Converts a getter result.
      Type Parameters:
      T - the target type of the value
      Parameters:
      getId - the getter ID
      dflt - the default value to return if a conversion is not possible, e.g., response is null
      conversion - the conversion operation
      Returns:
      the converted value or dflt
    • convertGetterResultToString

      private String convertGetterResultToString(String getId)
      Returns the result of the specified getter converted to string with default value "".
      Parameters:
      getId - the getter ID
      Returns:
      the converted value
      See Also:
    • convertToEnumSafe

      public static <T extends Enum<T>> T convertToEnumSafe(Object val, T dflt, Class<T> cls)
      Converts an object val to an enum value without throwing exceptions.
      Type Parameters:
      T - the enum value type
      Parameters:
      val - the value to be converted, may be null, a non-matching string, etc.
      dflt - the default value if the conversion cannot be applied
      cls - the enum type
      Returns:
      the converted value or dflt
    • convertGetterResultToEnum

      private <T extends Enum<T>> T convertGetterResultToEnum(String getId, T dflt, Class<T> cls)
      Returns the result of the specified getter converted to the given enum type.
      Type Parameters:
      T - the enum value type
      Parameters:
      getId - the getter ID
      dflt - the default value if the conversion fails
      cls - the enum type
      Returns:
      the converted value or dflt
      See Also:
    • getId

      public String getId()
      Description copied from interface: ServiceBase
      Returns the unique id of the service. May be a single service id, a service id and a postfixed application id (after ServiceBase.APPLICATION_SEPARATOR) or a service id with application id and postfixed application instance id (after ServiceBase.APPLICATION_SEPARATOR)
      Specified by:
      getId in interface ServiceBase
      Returns:
      the unique id
    • getName

      public String getName()
      Description copied from interface: Service
      The name of the service.
      Specified by:
      getName in interface Service
      Returns:
      the name
    • getVersion

      public de.iip_ecosphere.platform.support.Version getVersion()
      Description copied from interface: Service
      The version of the service.
      Specified by:
      getVersion in interface Service
      Returns:
      the version
    • getDescription

      public String getDescription()
      Description copied from interface: Service
      The description of the service.
      Specified by:
      getDescription in interface Service
      Returns:
      the description, may be empty
    • getState

      public ServiceState getState()
      Description copied from interface: ServiceBase
      Returns the state the service is currently in. [R4c]
      Specified by:
      getState in interface ServiceBase
      Returns:
      the state
    • isDeployable

      public boolean isDeployable()
      Description copied from interface: Service
      Returns whether the service is deployable in distributable manner or fixed in deployment location.
      Specified by:
      isDeployable in interface Service
      Returns:
      true for deployable, false for fixed
    • isTopLevel

      public boolean isTopLevel()
      Description copied from interface: Service
      Returns whether the service is a top-level service.
      Specified by:
      isTopLevel in interface Service
      Returns:
      true for top-level, false for nested
    • getKind

      public ServiceKind getKind()
      Description copied from interface: Service
      Returns the service kind.
      Specified by:
      getKind in interface Service
      Returns:
      the service kind
    • setState

      public void setState(ServiceState state) throws ExecutionException
      Description copied from interface: ServiceBase
      Changes the state. [R133c]
      Specified by:
      setState in interface ServiceBase
      Parameters:
      state - the new state
      Throws:
      ExecutionException - if changing the state fails for some reason
    • migrate

      public void migrate(String resourceId) throws ExecutionException
      Description copied from interface: Service
      Migrates a service. However, it may be required to migrate/move the containing artifact. [adaptation]
      Specified by:
      migrate in interface Service
      Parameters:
      resourceId - the target resource id, e.g., a device
      Throws:
      ExecutionException - if migration fails
    • update

      public void update(URI location) throws ExecutionException
      Description copied from interface: Service
      Updates the service by the service in the given location. This operation is responsible for stopping the running service (if needed), replacing it, starting the new service.
      Specified by:
      update in interface Service
      Parameters:
      location - the location of the new service, e.g., an URL
      Throws:
      ExecutionException - if the given service cannot be updated for some reason, e.g., because the replacement service is not an evolved version of the running service
    • switchTo

      public void switchTo(String targetId) throws ExecutionException
      Description copied from interface: Service
      Switches to an interface-compatible service. This method cares for stopping the old service, performing a handover if adequate, starting the target service. [adaptation]
      Specified by:
      switchTo in interface Service
      Parameters:
      targetId - the id of the target service
      Throws:
      ExecutionException - if switching the service cannot be performed for some reason
    • activate

      public void activate() throws ExecutionException
      Description copied from interface: Service
      Activates the service. [adaptation]
      Specified by:
      activate in interface Service
      Throws:
      ExecutionException - in case that activating fails, e.g., because the service is already active
    • passivate

      public void passivate() throws ExecutionException
      Description copied from interface: Service
      Passivates the service. [adaptation]
      Specified by:
      passivate in interface Service
      Throws:
      ExecutionException - in case that passivating fails, e.g., because the service is already passive
    • reconfigure

      public void reconfigure(Map<String,String> values) throws ExecutionException
      Description copied from interface: Service
      Reconfigures the service. [adaptation]
      Specified by:
      reconfigure in interface Service
      Parameters:
      values - the (service-specific) name-value mapping that shall lead to a reconfiguration of the service; values come either as primitive values or as JSON structures complying with the parameter descriptor. The service is responsible for correct JSON de-serialization according to the respective descriptor.
      Throws:
      ExecutionException - if reconfiguration fails