Class MultiConnectorServiceWrapper
java.lang.Object
de.iip_ecosphere.platform.services.environment.AbstractService
de.iip_ecosphere.platform.services.environment.MultiConnectorServiceWrapper
- All Implemented Interfaces:
ParameterConfigurerProvider,Service,ServiceBase
- Direct Known Subclasses:
MockingMultiConnectorServiceWrapper
Wraps multiple connector instances 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
FieldsModifier and TypeFieldDescriptionprivate static final Comparator<Class<?>> private Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> private Stringprivate Stringprivate Map<String, ParameterConfigurer<?>> private de.iip_ecosphere.platform.connectors.model.SharedSpaceFields inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
APPLICATION_SEPARATOR, DEFAULT_APPLICATION_INSTANCE_ID -
Constructor Summary
ConstructorsConstructorDescriptionMultiConnectorServiceWrapper(YamlService yaml, Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> connParamSupplier) Creates a service wrapper instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConnector(de.iip_ecosphere.platform.connectors.Connector<?, ?, ?, ?> connector) Adds a connector.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).protected static <CO> Class<? extends CO> getActualConnectorOutputType(Class<CO> connectorOutType) Returns the actual connector output type.protected Collection<de.iip_ecosphere.platform.connectors.Connector<?, ?, ?, ?>> Returns all connectors.<CI> de.iip_ecosphere.platform.connectors.events.EventHandlingConnectorgetEventHandlingConnector(Class<CI> ciCls) Returns the event handling connector for the given (app) connector input type.Returns the (eventually re-configured) data access path within the protocol.getOutPath(String cfgPath) Returns the (eventually re-configured) data access path within the protocol.getParameterConfigurer(String paramName) Returns the parameter configurer for a given parameter.The set of parameter names.booleanisEmpty()Returns whether any connectors were added.voidMigrates a service.protected static Class<?> Resolves cls to the declared type.<CI> voidCallsConnector.write(Object)on data and handles the respective exception potentially thrown by the underlying connector.private voidChangesinPath.private voidsetOutPath(String outPath) ChangesoutPath.<CO> voidsetReceptionCallback(de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CO> callback) Attaches a receptioncallbackto this connector.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 de.iip_ecosphere.platform.services.environment.AbstractService
activate, addConfigurer, addConfigurer, addConfigurer, addTypeSubstitution, createGenericInstance, createGenericInstance, createGenericInstanceByPlugin, createGenericMultiInstance, createGenericMultiInstance, createGenericMultiInstanceByPlugin, createInstance, createInstance, createInstance, createInstanceByPlugin, getArg, getDescription, getId, getKind, getName, getNetMgtKeyAddress, getResourceAsStream, getState, getStringArg, getSubstitutedType, getTypeCreator, getTypeSubstitutions, getVersion, initializeFrom, isDeployable, isTopLevel, notifyReconfigured, passivate, reconf, reconfigure, reconfigure, rollbackReconfigurationOnFailure, setLibJars, start, stop, transferDataMethods 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
createType, createType
-
Field Details
-
CLASS_COMPARATOR
-
inConnectors
-
outConnectors
-
connParamSupplier
-
paramConfigurers
-
outPath
-
inPath
-
-
Constructor Details
-
MultiConnectorServiceWrapper
public MultiConnectorServiceWrapper(YamlService yaml, Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> connParamSupplier) Creates a service wrapper instance.- Parameters:
yaml- the service information as read from YAMLconnParamSupplier- the connector parameter supplier for connecting the underlying connector
-
-
Method Details
-
addConnector
public void addConnector(de.iip_ecosphere.platform.connectors.Connector<?, ?, ?, ?> connector) Adds a connector. Already registered connectors will be overwritten. Creates/enables a shared connector space if available.- Parameters:
connector- the connector to register (may be null, ignored)
-
isEmpty
public boolean isEmpty()Returns whether any connectors were added.- Returns:
truefor empty,falseelse
-
getEventHandlingConnector
public <CI> de.iip_ecosphere.platform.connectors.events.EventHandlingConnector getEventHandlingConnector(Class<CI> ciCls) Returns the event handling connector for the given (app) connector input type.- Type Parameters:
CI- the (app) connector input type- Parameters:
ciCls- the (app) connector input type class- Returns:
- the connector, may be null for none
-
getConnectors
Returns all connectors.- Returns:
- the connectors (in a stable sequence)
-
resolve
Resolves cls to the declared type.- Parameters:
cls- the class to resolve- Returns:
- the resolved class
-
getActualConnectorOutputType
Returns the actual connector output type.- Type Parameters:
CO- the declared connector output type- Parameters:
connectorOutType- the connector output type- Returns:
- the actual output type
-
send
CallsConnector.write(Object)on data and handles the respective exception potentially thrown by the underlying connector.- Parameters:
data- the data to write
-
setReceptionCallback
public <CO> 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
Description copied from class:AbstractServiceChanges the state. [R133c]- Specified by:
setStatein interfaceServiceBase- Overrides:
setStatein classAbstractService- Parameters:
state- the new state- Throws:
ExecutionException- if changing the state fails for some reason- See Also:
-
doSetState
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:
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]- 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.- 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]- Parameters:
targetId- the id of the target service- Throws:
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
public void enableNotifications(boolean enableNotifications) Enables/disables notifications/polling at all.- Parameters:
enableNotifications- enable or disable notifications
-
getParameterConfigurer
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
Description copied from interface:ParameterConfigurerProviderThe set of parameter names.- Returns:
- the parameter names, may be null for none
-
setInPath
ChangesinPath.- Parameters:
inPath- the in path (ignored if null or empty)
-
setOutPath
ChangesoutPath.- Parameters:
outPath- the out path (ignored if null or empty)
-
getOutPath
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
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
-