Class ServiceStub
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.ServiceStub
-
- All Implemented Interfaces:
ParameterConfigurerProvider,Service,ServiceBase
public class ServiceStub extends java.lang.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 Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.util.function.Supplier<java.lang.Object>>gettersprivate java.util.Map<java.lang.String,java.util.function.Function<java.lang.Object[],java.lang.Object>>operationsprivate java.util.Map<java.lang.String,java.util.function.Consumer<java.lang.Object>>setters-
Fields inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
APPLICATION_SEPARATOR, DEFAULT_APPLICATION_INSTANCE_ID
-
-
Constructor Summary
Constructors Constructor Description ServiceStub(de.iip_ecosphere.platform.support.aas.InvocablesCreator iCreator, java.lang.String serviceId)Creates the setup and registers the operations.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivate()Activates the service.private <T> TconvertGetterResult(java.lang.String getId, T dflt, java.util.function.Function<java.lang.Object,T> conversion)Converts a getter result.private <T extends java.lang.Enum<T>>
TconvertGetterResultToEnum(java.lang.String getId, T dflt, java.lang.Class<T> cls)Returns the result of the specified getter converted to the given enum type.private java.lang.StringconvertGetterResultToString(java.lang.String getId)Returns the result of the specified getter converted to string with default value "".static <T extends java.lang.Enum<T>>
TconvertToEnumSafe(java.lang.Object val, T dflt, java.lang.Class<T> cls)Converts an objectvalto an enum value without throwing exceptions.java.lang.StringgetDescription()The description of the service.java.util.function.Supplier<java.lang.Object>getGetter(java.lang.String name)Returns the getter functor for a given property.java.lang.StringgetId()Returns the unique id of the service.ServiceKindgetKind()Returns the service kind.java.lang.StringgetName()The name of the service.java.util.function.Function<java.lang.Object[],java.lang.Object>getOperation(java.lang.String name)Returns the functor for a given operation.java.util.function.Consumer<java.lang.Object>getSetter(java.lang.String name)Returns the setter functor for a given property.ServiceStategetState()Returns the state the service is currently in.de.iip_ecosphere.platform.support.iip_aas.VersiongetVersion()The version of the service.booleanisDeployable()Returns whether the service is deployable in distributable manner or fixed in deployment location.booleanisTopLevel()Returns whether the service is a top-level service.voidmigrate(java.lang.String resourceId)Migrates a service.voidpassivate()Passivates the service.voidreconfigure(java.util.Map<java.lang.String,java.lang.String> values)Reconfigures the service.private voidregisterOperation(java.lang.String name, java.util.function.Function<java.lang.Object[],java.lang.Object> operation)Registers the functor for an operation.private voidregisterProperty(java.lang.String name, java.util.function.Supplier<java.lang.Object> getter, java.util.function.Consumer<java.lang.Object> setter)Registers the functors for a property.voidsetState(ServiceState state)Changes the state.voidswitchTo(java.lang.String targetId)Switches to an interface-compatible service.voidupdate(java.net.URI location)Updates 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, wait
-
Methods inherited from interface de.iip_ecosphere.platform.services.environment.Service
getNetMgtKeyAddress, getParameterConfigurer, getParameterNames
-
-
-
-
Field Detail
-
getters
private java.util.Map<java.lang.String,java.util.function.Supplier<java.lang.Object>> getters
-
setters
private java.util.Map<java.lang.String,java.util.function.Consumer<java.lang.Object>> setters
-
operations
private java.util.Map<java.lang.String,java.util.function.Function<java.lang.Object[],java.lang.Object>> operations
-
-
Constructor Detail
-
ServiceStub
public ServiceStub(de.iip_ecosphere.platform.support.aas.InvocablesCreator iCreator, java.lang.String serviceId)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)
-
-
Method Detail
-
registerProperty
private void registerProperty(java.lang.String name, java.util.function.Supplier<java.lang.Object> getter, java.util.function.Consumer<java.lang.Object> 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(java.lang.String name, java.util.function.Function<java.lang.Object[],java.lang.Object> operation)Registers the functor for an operation.- Parameters:
name- the (unqualified) name of the propertyoperation- the operation functor
-
getGetter
public java.util.function.Supplier<java.lang.Object> getGetter(java.lang.String name)
Returns the getter functor for a given property.- Parameters:
name- the (unqualified) property name- Returns:
- the functor, may be null for none
-
getSetter
public java.util.function.Consumer<java.lang.Object> getSetter(java.lang.String name)
Returns the setter functor for a given property.- Parameters:
name- the (unqualified) property name- Returns:
- the functor, may be null for none
-
getOperation
public java.util.function.Function<java.lang.Object[],java.lang.Object> getOperation(java.lang.String name)
Returns the functor for a given operation.- Parameters:
name- the (unqualified) operation name- Returns:
- the functor, may be null for none
-
convertGetterResult
private <T> T convertGetterResult(java.lang.String getId, T dflt, java.util.function.Function<java.lang.Object,T> conversion)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
private java.lang.String convertGetterResultToString(java.lang.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:
convertGetterResult(String, Object, Function)
-
convertToEnumSafe
public static <T extends java.lang.Enum<T>> T convertToEnumSafe(java.lang.Object val, T dflt, java.lang.Class<T> cls)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
private <T extends java.lang.Enum<T>> T convertGetterResultToEnum(java.lang.String getId, T dflt, java.lang.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 IDdflt- the default value if the conversion failscls- the enum type- Returns:
- the converted value or
dflt - See Also:
convertGetterResult(String, Object, Function),convertToEnumSafe(Object, Enum, Class)
-
getId
public java.lang.String 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
public java.lang.String getName()
Description copied from interface:ServiceThe name of the service.
-
getVersion
public de.iip_ecosphere.platform.support.iip_aas.Version getVersion()
Description copied from interface:ServiceThe version of the service.- Specified by:
getVersionin interfaceService- Returns:
- the version
-
getDescription
public java.lang.String getDescription()
Description copied from interface:ServiceThe description of the service.- Specified by:
getDescriptionin interfaceService- Returns:
- the description, may be empty
-
getState
public ServiceState 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
public ServiceKind getKind()
Description copied from interface:ServiceReturns the service kind.
-
setState
public void setState(ServiceState state) throws java.util.concurrent.ExecutionException
Description copied from interface:ServiceBaseChanges the state. [R133c]- Specified by:
setStatein interfaceServiceBase- Parameters:
state- the new state- Throws:
java.util.concurrent.ExecutionException- if changing the state fails for some reason
-
migrate
public void migrate(java.lang.String resourceId) throws java.util.concurrent.ExecutionExceptionDescription copied from interface:ServiceMigrates a service. However, it may be required to migrate/move the containing artifact. [adaptation]
-
update
public void update(java.net.URI location) throws java.util.concurrent.ExecutionExceptionDescription 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:
java.util.concurrent.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(java.lang.String targetId) throws java.util.concurrent.ExecutionExceptionDescription 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]
-
activate
public void activate() throws java.util.concurrent.ExecutionExceptionDescription copied from interface:ServiceActivates the service. [adaptation]
-
passivate
public void passivate() throws java.util.concurrent.ExecutionExceptionDescription copied from interface:ServicePassivates the service. [adaptation]
-
reconfigure
public void reconfigure(java.util.Map<java.lang.String,java.lang.String> values) throws java.util.concurrent.ExecutionExceptionDescription 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:
java.util.concurrent.ExecutionException- if reconfiguration fails
-
-