Class ServiceStub
java.lang.Object
de.iip_ecosphere.platform.services.environment.ServiceStub
- All Implemented Interfaces:
ParameterConfigurerProvider,Service,ServiceBase
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 Summary
FieldsModifier and TypeFieldDescriptionFields inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
APPLICATION_SEPARATOR, DEFAULT_APPLICATION_INSTANCE_ID -
Constructor Summary
ConstructorsConstructorDescriptionServiceStub(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.ServiceStub(de.iip_ecosphere.platform.support.aas.InvocablesCreator iCreator, String serviceId, String... path) Creates the setup and registers the operations. -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Activates the service.private <T> TconvertGetterResult(String getId, T dflt, Function<Object, T> conversion) Converts a getter result.private <T extends Enum<T>>
TconvertGetterResultToEnum(String getId, T dflt, Class<T> cls) Returns the result of the specified getter converted to the given enum type.private StringReturns the result of the specified getter converted to string with default value "".static <T extends Enum<T>>
TconvertToEnumSafe(Object val, T dflt, Class<T> cls) Converts an objectvalto an enum value without throwing exceptions.The description of the service.de.iip_ecosphere.platform.support.aas.InvokableReturns the getter invokable for a given property.getId()Returns the unique id of the service.getKind()Returns the service kind.getName()The name of the service.de.iip_ecosphere.platform.support.aas.InvokablegetOperation(String name) Returns the invokable for a given operation.de.iip_ecosphere.platform.support.aas.InvokableReturns the setter invokable for a given property.getState()Returns the state the service is currently in.de.iip_ecosphere.platform.support.VersionThe version of the service.booleanReturns whether the service is deployable in distributable manner or fixed in deployment location.booleanReturns whether the service is a top-level service.voidMigrates a service.voidPassivates the service.voidreconfigure(Map<String, String> values) Reconfigures the service.private voidregisterOperation(String name, de.iip_ecosphere.platform.support.aas.Invokable operation) Registers the functor for an operation.private voidregisterProperty(String name, de.iip_ecosphere.platform.support.aas.Invokable getter, de.iip_ecosphere.platform.support.aas.Invokable setter) Registers the functors for a property.voidsetState(ServiceState state) Changes the state.voidSwitches to an interface-compatible service.voidUpdates the service by the service in the givenlocation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.iip_ecosphere.platform.services.environment.Service
addTypeSubstitution, createType, createType, getNetMgtKeyAddress, getParameterConfigurer, getParameterNames, getSubstitutedType, getTypeCreator, getTypeSubstitutions
-
Field Details
-
getters
-
setters
-
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 creatorserviceId- the service id to create the qualified names viaServiceMapper.getQName(Service, String)path- to submodel element representingserviceId
-
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 creatorserviceId- the service id to create the qualified names viaServiceMapper.getQName(Service, String)aasSupplier- overrides the default AAS supplier (AasPartRegistry.retrieveIipAas(), may be null for the defaultpath- to submodel element representingserviceId
-
-
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 propertygetter- the getter functorsetter- 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 propertyoperation- the operation functor
-
getGetter
Returns the getter invokable for a given property.- Parameters:
name- the (unqualified) property name- Returns:
- the invokable, may be null for none
-
getSetter
Returns the setter invokable for a given property.- Parameters:
name- the (unqualified) property name- Returns:
- the invokable, may be null for none
-
getOperation
Returns the invokable for a given operation.- Parameters:
name- the (unqualified) operation name- Returns:
- the invokable, may be null for none
-
convertGetterResult
Converts a getter result.- Type Parameters:
T- the target type of the value- Parameters:
getId- the getter IDdflt- the default value to return if a conversion is not possible, e.g., response is nullconversion- the conversion operation- Returns:
- the converted value or
dflt
-
convertGetterResultToString
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
Converts an objectvalto 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 appliedcls- the enum type- Returns:
- the converted value or
dflt
-
convertGetterResultToEnum
Returns the result of the specified getter converted to the given enum type.- Type Parameters:
T- the enum value type- Parameters:
getId- the getter IDdflt- the default value if the conversion failscls- the enum type- Returns:
- the converted value or
dflt - See Also:
-
getId
Description copied from interface:ServiceBaseReturns the unique id of the service. May be a single service id, a service id and a postfixed application id (afterServiceBase.APPLICATION_SEPARATOR) or a service id with application id and postfixed application instance id (afterServiceBase.APPLICATION_SEPARATOR)- Specified by:
getIdin interfaceServiceBase- Returns:
- the unique id
-
getName
Description copied from interface:ServiceThe name of the service. -
getVersion
public de.iip_ecosphere.platform.support.Version getVersion()Description copied from interface:ServiceThe version of the service.- Specified by:
getVersionin interfaceService- Returns:
- the version
-
getDescription
Description copied from interface:ServiceThe description of the service.- Specified by:
getDescriptionin interfaceService- Returns:
- the description, may be empty
-
getState
Description copied from interface:ServiceBaseReturns the state the service is currently in. [R4c]- Specified by:
getStatein interfaceServiceBase- Returns:
- the state
-
isDeployable
public boolean isDeployable()Description copied from interface:ServiceReturns whether the service is deployable in distributable manner or fixed in deployment location.- Specified by:
isDeployablein interfaceService- Returns:
truefor deployable,falsefor fixed
-
isTopLevel
public boolean isTopLevel()Description copied from interface:ServiceReturns whether the service is a top-level service.- Specified by:
isTopLevelin interfaceService- Returns:
truefor top-level,falsefor nested
-
getKind
Description copied from interface:ServiceReturns the service kind. -
setState
Description copied from interface:ServiceBaseChanges the state. [R133c]- Specified by:
setStatein interfaceServiceBase- Parameters:
state- the new state- Throws:
ExecutionException- if changing the state fails for some reason
-
migrate
Description copied from interface:ServiceMigrates a service. However, it may be required to migrate/move the containing artifact. [adaptation]- Specified by:
migratein interfaceService- Parameters:
resourceId- the target resource id, e.g., a device- Throws:
ExecutionException- if migration fails
-
update
Description copied from interface:ServiceUpdates the service by the service in the givenlocation. This operation is responsible for stopping the running service (if needed), replacing it, starting the new service.- Specified by:
updatein interfaceService- 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
Description copied from interface:ServiceSwitches to an interface-compatible service. This method cares for stopping the old service, performing a handover if adequate, starting thetargetservice. [adaptation]- Specified by:
switchToin interfaceService- Parameters:
targetId- the id of the target service- Throws:
ExecutionException- if switching the service cannot be performed for some reason
-
activate
Description copied from interface:ServiceActivates the service. [adaptation]- Specified by:
activatein interfaceService- Throws:
ExecutionException- in case that activating fails, e.g., because the service is already active
-
passivate
Description copied from interface:ServicePassivates the service. [adaptation]- Specified by:
passivatein interfaceService- Throws:
ExecutionException- in case that passivating fails, e.g., because the service is already passive
-
reconfigure
Description copied from interface:ServiceReconfigures the service. [adaptation]- Specified by:
reconfigurein interfaceService- 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
-