Class ConnectorServiceWrapper<O,I,CO,CI>
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.AbstractService
-
- de.iip_ecosphere.platform.services.environment.ConnectorServiceWrapper<O,I,CO,CI>
-
- Type Parameters:
O- the output type from the underlying machine/platformI- the input type to the underlying machine/platformCO- the output type of the connectorCI- the input type of the connector
- All Implemented Interfaces:
ParameterConfigurerProvider,Service,ServiceBase
- Direct Known Subclasses:
MockingConnectorServiceWrapper
public class ConnectorServiceWrapper<O,I,CO,CI> extends AbstractService
Wraps a connector into a service. Implicitly reacts on parameter "inPath" and "outPath" as string to override dynamically the configured data path into the connector data.- Author:
- Holger Eichelberger, SSE
-
-
Field Summary
Fields Modifier and Type Field Description private de.iip_ecosphere.platform.connectors.Connector<O,I,CO,CI>connectorprivate java.util.function.Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter>connParamSupplierprivate java.lang.StringinPathprivate java.lang.StringoutPathprivate java.util.Map<java.lang.String,ParameterConfigurer<?>>paramConfigurers-
Fields inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
APPLICATION_SEPARATOR, DEFAULT_APPLICATION_INSTANCE_ID
-
-
Constructor Summary
Constructors Constructor Description ConnectorServiceWrapper(YamlService yaml, de.iip_ecosphere.platform.connectors.Connector<O,I,CO,CI> connector, java.util.function.Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> connParamSupplier)Creates a service wrapper instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoSetState(ServiceState state)Changes the state by callingAbstractService.setState(ServiceState).voidenableNotifications(boolean enableNotifications)Enables/disables notifications/polling at all.voidenablePolling(boolean enablePolling)Enable/disable polling (does not influence the polling timer).de.iip_ecosphere.platform.connectors.Connector<O,I,CO,CI>getConnector()Returns the connector instance.java.lang.StringgetInPath(java.lang.String cfgPath)Returns the (eventually re-configured) data access path within the protocol.java.lang.StringgetOutPath(java.lang.String cfgPath)Returns the (eventually re-configured) data access path within the protocol.ParameterConfigurer<?>getParameterConfigurer(java.lang.String paramName)Returns the parameter configurer for a given parameter.java.util.Set<java.lang.String>getParameterNames()The set of parameter names.voidmigrate(java.lang.String resourceId)Migrates a service.voidsend(CI data)CallsConnector.write(Object)on data and handles the respective exception potentially thrown by the underlying connector.private voidsetInPath(java.lang.String inPath)ChangesinPath.private voidsetOutPath(java.lang.String outPath)ChangesoutPath.voidsetReceptionCallback(de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CO> callback)Attaches a receptioncallbackto this connector.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 de.iip_ecosphere.platform.services.environment.AbstractService
activate, addConfigurer, addConfigurer, addConfigurer, createInstance, createInstance, createInstance, getDescription, getId, getKind, getName, getNetMgtKeyAddress, getResourceAsStream, getState, getVersion, initializeFrom, isDeployable, isTopLevel, notifyReconfigured, passivate, reconf, reconfigure, reconfigure, rollbackReconfigurationOnFailure, setLibJars, start, stop
-
-
-
-
Field Detail
-
connParamSupplier
private java.util.function.Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> connParamSupplier
-
paramConfigurers
private java.util.Map<java.lang.String,ParameterConfigurer<?>> paramConfigurers
-
outPath
private java.lang.String outPath
-
inPath
private java.lang.String inPath
-
-
Constructor Detail
-
ConnectorServiceWrapper
public ConnectorServiceWrapper(YamlService yaml, de.iip_ecosphere.platform.connectors.Connector<O,I,CO,CI> connector, java.util.function.Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> connParamSupplier)
Creates a service wrapper instance.- Parameters:
yaml- the service information as read from YAMLconnector- the connector instance to wrapconnParamSupplier- the connector parameter supplier for connecting the underlying connector
-
-
Method Detail
-
getConnector
public de.iip_ecosphere.platform.connectors.Connector<O,I,CO,CI> getConnector()
Returns the connector instance.- Returns:
- the connector instance
-
send
public void send(CI data)
CallsConnector.write(Object)on data and handles the respective exception potentially thrown by the underlying connector.- Parameters:
data- the data to write
-
setReceptionCallback
public void setReceptionCallback(de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CO> callback)
Attaches a receptioncallbackto this connector. Thecallbackis called upon a reception. Handles the respective exception potentially thrown by the underlying connector.- Parameters:
callback- the callback to attach
-
setState
public void setState(ServiceState state) throws java.util.concurrent.ExecutionException
Description copied from class:AbstractServiceChanges the state. [R133c]- Specified by:
setStatein interfaceServiceBase- Overrides:
setStatein classAbstractService- Parameters:
state- the new state- Throws:
java.util.concurrent.ExecutionException- if changing the state fails for some reason- See Also:
AbstractService.start(),AbstractService.stop()
-
doSetState
protected void doSetState(ServiceState state) throws java.util.concurrent.ExecutionException
Changes the state by callingAbstractService.setState(ServiceState). Introduced, so that super functionality is made available to super-classes as-is.- 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]- Parameters:
resourceId- the target resource id, e.g., a device- Throws:
java.util.concurrent.ExecutionException- if migration fails
-
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.- 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]- Parameters:
targetId- the id of the target service- Throws:
java.util.concurrent.ExecutionException- if switching the service cannot be performed for some reason
-
enablePolling
public void enablePolling(boolean enablePolling)
Enable/disable polling (does not influence the polling timer).- Parameters:
enablePolling- whether polling shall enabled- See Also:
enableNotifications(boolean)
-
enableNotifications
public void enableNotifications(boolean enableNotifications)
Enables/disables notifications/polling at all.- Parameters:
enableNotifications- enable or disable notifications
-
getParameterConfigurer
public ParameterConfigurer<?> getParameterConfigurer(java.lang.String paramName)
Description copied from interface:ParameterConfigurerProviderReturns the parameter configurer for a given parameter. We need this generic approach to ease code generation and initial setting of parameter values.- Parameters:
paramName- the name of the parameter- Returns:
- the associated parameter configurer or null if there is none
-
getParameterNames
public java.util.Set<java.lang.String> getParameterNames()
Description copied from interface:ParameterConfigurerProviderThe set of parameter names.- Returns:
- the parameter names, may be null for none
-
setInPath
private void setInPath(java.lang.String inPath)
ChangesinPath.- Parameters:
inPath- the in path (ignored if null or empty)
-
setOutPath
private void setOutPath(java.lang.String outPath)
ChangesoutPath.- Parameters:
outPath- the out path (ignored if null or empty)
-
getOutPath
public java.lang.String getOutPath(java.lang.String cfgPath)
Returns the (eventually re-configured) data access path within the protocol.- Parameters:
cfgPath- the configured path from the model- Returns:
- the path to use, may be
cfgPath
-
getInPath
public java.lang.String getInPath(java.lang.String cfgPath)
Returns the (eventually re-configured) data access path within the protocol.- Parameters:
cfgPath- the configured path from the model- Returns:
- the path to use, may be
cfgPath
-
-