Class MockingConnectorServiceWrapper<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>
de.iip_ecosphere.platform.services.environment.MockingConnectorServiceWrapper<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:
de.iip_ecosphere.platform.connectors.events.EventHandlingConnector,ParameterConfigurerProvider,Service,ServiceBase
public class MockingConnectorServiceWrapper<O,I,CO,CI>
extends ConnectorServiceWrapper<O,I,CO,CI>
implements de.iip_ecosphere.platform.connectors.events.EventHandlingConnector
Mocks a
ConnectorServiceWrapper 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 de.iip_ecosphere.platform.connectors.CachingStrategyprivate de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CO> private Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> private MockingConnectorServiceWrapper<O,I, CO, CI>.DataRunnable private booleanprivate Stringprivate de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CI> private intprivate DataRecorderprivate de.iip_ecosphere.platform.support.json.IOIterator<? extends CO> Fields inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
APPLICATION_SEPARATOR, DEFAULT_APPLICATION_INSTANCE_ID -
Constructor Summary
ConstructorsConstructorDescriptionMockingConnectorServiceWrapper(YamlService yaml, de.iip_ecosphere.platform.connectors.Connector<O, I, CO, CI> connector, Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> connParamSupplier) Creates a service wrapper instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.getStorageValue(String key) private voidhandleReceived(CO data, int notifInterval) Handles received data.voidMigrates a service.protected InputStreamopenDataStream(String name) Tries to open an input data stream for mocking.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<CI> inputCallback) Sets a callback on data received from the platform.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 voidStarts data ingestion.private voidStarts a parallel thread for data ingestion.voidSwitches to an interface-compatible service.voidtrigger()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.ConnectorServiceWrapper
doSetState, getConnector, getInPath, getOutPath, getParameterConfigurer, getParameterNamesMethods 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
-
connectorOutType
-
callback
-
inputCallback
-
connParamSupplier
-
enableNotifications
private boolean enableNotifications -
fileName
-
dataRunnable
-
cachingStrategy
private de.iip_ecosphere.platform.connectors.CachingStrategy cachingStrategy -
triggerIterator
-
recorder
-
storage
-
notificationInterval
private int notificationInterval
-
-
Constructor Details
-
MockingConnectorServiceWrapper
public MockingConnectorServiceWrapper(YamlService yaml, de.iip_ecosphere.platform.connectors.Connector<O, I, CO, CI> connector, 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 Details
-
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
CallsConnector.write(Object)on data and handles the respective exception potentially thrown by the underlying connector. -
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.- Overrides:
setReceptionCallbackin classConnectorServiceWrapper<O,I, CO, CI> - 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.- 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
-
handleReceived
Handles received data.- Parameters:
data- 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 classConnectorServiceWrapper<O,I, CO, CI> - 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 classConnectorServiceWrapper<O,I, CO, CI> - 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 classConnectorServiceWrapper<O,I, CO, CI> - 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 classConnectorServiceWrapper<O,I, CO, CI> - 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:ConnectorServiceWrapperEnable/disable polling (does not influence the polling timer).- Specified by:
enablePollingin interfacede.iip_ecosphere.platform.connectors.events.EventHandlingConnector- Overrides:
enablePollingin classConnectorServiceWrapper<O,I, CO, CI> - Parameters:
enablePolling- whether polling shall enabled- See Also:
-
enableNotifications
public void enableNotifications(boolean enableNotifications) Description copied from class:ConnectorServiceWrapperEnables/disables notifications/polling at all.- Overrides:
enableNotificationsin classConnectorServiceWrapper<O,I, CO, CI> - 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<CI> 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
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
-