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 aConnectorServiceWrapperby data in a JSON file throughDataMapper.- Author:
- Holger Eichelberger, SSE
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classMockingConnectorServiceWrapper.DataRunnableRunnable for parallel data ingestion.
-
Field Summary
Fields Modifier and Type Field Description private de.iip_ecosphere.platform.connectors.CachingStrategycachingStrategyprivate de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CO>callbackprivate java.lang.Class<? extends CO>connectorOutTypeprivate java.util.function.Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter>connParamSupplierprivate MockingConnectorServiceWrapper.DataRunnabledataRunnableprivate booleanenableNotificationsprivate java.lang.StringfileNameprivate de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CI>inputCallbackprivate DataMapper.IOIterator<? extends CO>triggerIterator-
Fields inherited from interface de.iip_ecosphere.platform.services.environment.switching.ServiceBase
APPLICATION_SEPARATOR, DEFAULT_APPLICATION_INSTANCE_ID
-
-
Constructor Summary
Constructors Constructor Description MockingConnectorServiceWrapper(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 voidemitData(CI data)Emits 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 java.io.InputStreamgetDataStream(java.lang.String name)The input data stream.private voidhandleReceived(CO data, int notifInterval)Handles received data.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.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.private voidstartData(java.util.function.Supplier<java.lang.Boolean> continueFunction)Starts data ingestion.private voidstartDataThread()Starts a parallel thread for data ingestion.voidswitchTo(java.lang.String targetId)Switches to an interface-compatible service.voidtrigger()voidtrigger(de.iip_ecosphere.platform.connectors.events.ConnectorTriggerQuery query)voidupdate(java.net.URI location)Updates the service by the service in the givenlocation.-
Methods inherited from class de.iip_ecosphere.platform.services.environment.ConnectorServiceWrapper
doSetState, getConnector, getInPath, getOutPath, getParameterConfigurer, getParameterNames
-
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
-
connectorOutType
private java.lang.Class<? extends CO> connectorOutType
-
callback
private de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CO> callback
-
inputCallback
private de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<CI> inputCallback
-
connParamSupplier
private java.util.function.Supplier<de.iip_ecosphere.platform.connectors.ConnectorParameter> connParamSupplier
-
enableNotifications
private boolean enableNotifications
-
fileName
private java.lang.String fileName
-
dataRunnable
private MockingConnectorServiceWrapper.DataRunnable dataRunnable
-
cachingStrategy
private de.iip_ecosphere.platform.connectors.CachingStrategy cachingStrategy
-
triggerIterator
private DataMapper.IOIterator<? extends CO> triggerIterator
-
-
Constructor Detail
-
MockingConnectorServiceWrapper
public MockingConnectorServiceWrapper(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
-
send
public void send(CI data)
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
protected java.io.InputStream getDataStream(java.lang.String name)
The input data stream.- Parameters:
name- the name of the file/resource to be used- Returns:
- the stream
-
startData
private void startData(java.util.function.Supplier<java.lang.Boolean> continueFunction) throws java.io.IOExceptionStarts data ingestion.- Parameters:
continueFunction- supplier indicating whether further data shall be ingested although still potential input data may be available- Throws:
java.io.IOException- if the data file cannot be found/opened
-
handleReceived
private void handleReceived(CO data, int notifInterval)
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
public void setState(ServiceState state) throws java.util.concurrent.ExecutionException
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:
java.util.concurrent.ExecutionException- if changing the state fails for some reason- See Also:
AbstractService.start(),AbstractService.stop()
-
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- Overrides:
updatein classConnectorServiceWrapper<O,I,CO,CI>- 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]
-
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:
ConnectorServiceWrapper.enableNotifications(boolean)
-
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
public void emitData(CI data)
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
-
-