Class MockingMultiConnectorServiceWrapper
java.lang.Object
de.iip_ecosphere.platform.services.environment.AbstractService
de.iip_ecosphere.platform.services.environment.MultiConnectorServiceWrapper
de.iip_ecosphere.platform.services.environment.MockingMultiConnectorServiceWrapper
- All Implemented Interfaces:
de.iip_ecosphere.platform.connectors.events.EventHandlingConnector,ParameterConfigurerProvider,Service,ServiceBase
public class MockingMultiConnectorServiceWrapper
extends MultiConnectorServiceWrapper
implements de.iip_ecosphere.platform.connectors.events.EventHandlingConnector
Mocks a
MultiConnectorServiceWrapper by data in a JSON file through DataMapper.
JSON data may contain meta values $period or $repeats as for DataMapper.BaseDataUnitFunctions.- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classRunnable for parallel data ingestion. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> private booleanprivate intprivate DataRecorderFields inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
APPLICATION_SEPARATOR, DEFAULT_APPLICATION_INSTANCE_ID -
Constructor Summary
ConstructorsConstructorDescriptionMockingMultiConnectorServiceWrapper(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 DataRecorderCreates an optional data recorder instance.protected final DataRecorderCreates a default data recorder instance (writes to target in JSON format).voidEmits data received from the platform.voidenableNotifications(boolean enableNotifications) Enables/disables notifications/polling at all.voidenablePolling(boolean enablePolling) Enable/disable polling (does not influence the polling timer).protected InputStreamgetDataStream(String name) Returns the input data stream for mocking.private StringgetFileName(de.iip_ecosphere.platform.connectors.Connector<?, ?, ?, ?> connector) Returns the data file name for a connector.getStorageValue(String key) private <CO> voidhandleReceived(Class<CO> cls, CO data, int notifInterval) Handles received data.voidMigrates a service.protected InputStreamopenDataStream(String name) Tries to open an input data stream for mocking.<CI> voidCallsConnector.write(Object)on data and handles the respective exception potentially thrown by the underlying connector.voidsetDataTimeDifference(int difference) voidsetInputCallback(de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<?> inputCallback) Sets a callback on data received from the platform.<CO> voidsetReceptionCallback(de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CO> callback) Attaches a receptioncallbackto this connector.voidsetState(ServiceState state) Changes the state.voidsetStorageValue(String key, Object value) private voidstartData(de.iip_ecosphere.platform.connectors.Connector<?, ?, ?, ?> connector, Supplier<Boolean> continueFunction) Starts data ingestion on the given connector.private voidStarts data ingestion on all connectors.private voidStarts a parallel thread for data ingestion.voidSwitches to an interface-compatible service.voidtrigger()private <CO> voidtrigger(de.iip_ecosphere.platform.connectors.Connector<?, ?, ?, ?> connector, Class<CO> connectorOutType, String fileName) Triggers a certain connector.voidtrigger(de.iip_ecosphere.platform.connectors.events.ConnectorTriggerQuery query) voidUpdates the service by the service in the givenlocation.Methods inherited from class de.iip_ecosphere.platform.services.environment.MultiConnectorServiceWrapper
doSetState, getActualConnectorOutputType, getConnectors, getEventHandlingConnector, getInPath, getOutPath, getParameterConfigurer, getParameterNames, isEmpty, resolveMethods inherited from class de.iip_ecosphere.platform.services.environment.AbstractService
activate, addConfigurer, addConfigurer, addConfigurer, addTypeSubstitution, createGenericInstance, createGenericInstanceByPlugin, 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.connectors.events.EventHandlingConnector
getNameMethods inherited from interface de.iip_ecosphere.platform.services.environment.Service
createType, createType
-
Field Details
-
callbacks
-
inputCallbacks
-
cachingStrategies
-
triggerIterators
-
connParamSupplier
-
enableNotifications
private boolean enableNotifications -
dataRunnable
-
recorder
-
storage
-
notificationInterval
private int notificationInterval
-
-
Constructor Details
-
MockingMultiConnectorServiceWrapper
public MockingMultiConnectorServiceWrapper(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) Description copied from class:MultiConnectorServiceWrapperAdds a connector. Already registered connectors will be overwritten. Creates/enables a shared connector space if available.- Overrides:
addConnectorin classMultiConnectorServiceWrapper- Parameters:
connector- the connector to register (may be null, ignored)
-
getFileName
Returns the data file name for a connector.- Parameters:
connector- the connector- Returns:
- the data file name
-
createDataRecorder
Creates an optional data recorder instance.- Returns:
- the data recorder instance, may be null for none
- See Also:
-
createDataRecorderOrig
Creates a default data recorder instance (writes to target in JSON format). Cannot be overriden to be accessible to subclasses althoughcreateDataRecorder()is overridden.- Returns:
- the data recorder instance, may be null for none
- See Also:
-
send
Description copied from class:MultiConnectorServiceWrapperCallsConnector.write(Object)on data and handles the respective exception potentially thrown by the underlying connector.- Overrides:
sendin classMultiConnectorServiceWrapper- 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.- Overrides:
setReceptionCallbackin classMultiConnectorServiceWrapper- Parameters:
callback- the callback to attach
-
getDataStream
Returns the input data stream for mocking. Considers ".yml" (legacy, typo) and ".json" files.- Parameters:
name- the name of the file/resource to be used- Returns:
- the stream, may be null
-
openDataStream
Tries to open an input data stream for mocking.- Parameters:
name- the name of the file/resource to be used- Returns:
- the stream, may be null
-
startData
Starts data ingestion on all connectors.- Parameters:
continueFunction- supplier indicating whether further data shall be ingested although still potential input data may be available- Throws:
IOException- if the data file cannot be found/opened
-
startData
private void startData(de.iip_ecosphere.platform.connectors.Connector<?, ?, throws IOException?, ?> connector, Supplier<Boolean> continueFunction) Starts data ingestion on the given connector.- Parameters:
connector- the connector to start data ingestion oncontinueFunction- supplier indicating whether further data shall be ingested although still potential input data may be available- Throws:
IOException- if the data file cannot be found/opened
-
handleReceived
Handles received data.- Type Parameters:
CO- the connector output type- Parameters:
cls- the connector output type classdata- the datanotifInterval- the notification interval causing a sleep if data was sent, ignored if not positive
-
startDataThread
private void startDataThread()Starts a parallel thread for data ingestion. Non-blocking execution is typically required by a streaming engine. -
setState
Description copied from class:AbstractServiceChanges the state. [R133c]- Specified by:
setStatein interfaceServiceBase- Overrides:
setStatein classMultiConnectorServiceWrapper- Parameters:
state- the new state- Throws:
ExecutionException- if changing the state fails for some reason- See Also:
-
migrate
Description copied from interface:ServiceMigrates a service. However, it may be required to migrate/move the containing artifact. [adaptation]- Specified by:
migratein interfaceService- Overrides:
migratein classMultiConnectorServiceWrapper- 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- Overrides:
updatein classMultiConnectorServiceWrapper- 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- Overrides:
switchToin classMultiConnectorServiceWrapper- 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) Description copied from class:MultiConnectorServiceWrapperEnable/disable polling (does not influence the polling timer).- Specified by:
enablePollingin interfacede.iip_ecosphere.platform.connectors.events.EventHandlingConnector- Overrides:
enablePollingin classMultiConnectorServiceWrapper- Parameters:
enablePolling- whether polling shall enabled- See Also:
-
enableNotifications
public void enableNotifications(boolean enableNotifications) Description copied from class:MultiConnectorServiceWrapperEnables/disables notifications/polling at all.- Overrides:
enableNotificationsin classMultiConnectorServiceWrapper- Parameters:
enableNotifications- enable or disable notifications
-
emitData
Emits data received from the platform.- Parameters:
data- the last data
-
setInputCallback
public void setInputCallback(de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<?> inputCallback) Sets a callback on data received from the platform.- Parameters:
inputCallback- the input callback, may be null for none
-
trigger
public void trigger()- Specified by:
triggerin interfacede.iip_ecosphere.platform.connectors.events.EventHandlingConnector
-
trigger
private <CO> void trigger(de.iip_ecosphere.platform.connectors.Connector<?, ?, ?, ?> connector, Class<CO> connectorOutType, String fileName) Triggers a certain connector.- Type Parameters:
CO- the connector output type- Parameters:
connector- the connectorconnectorOutType- the connector output type classfileName- the file name for reading data from
-
trigger
public void trigger(de.iip_ecosphere.platform.connectors.events.ConnectorTriggerQuery query) - Specified by:
triggerin interfacede.iip_ecosphere.platform.connectors.events.EventHandlingConnector
-
setStorageValue
- Specified by:
setStorageValuein interfacede.iip_ecosphere.platform.connectors.events.EventHandlingConnector
-
getStorageValue
- Specified by:
getStorageValuein interfacede.iip_ecosphere.platform.connectors.events.EventHandlingConnector
-
setDataTimeDifference
public void setDataTimeDifference(int difference) - Specified by:
setDataTimeDifferencein interfacede.iip_ecosphere.platform.connectors.events.EventHandlingConnector
-