Class AbstractThreadedConnector<O,I,CO,CI,M extends ModelAccess>
java.lang.Object
de.iip_ecosphere.platform.connectors.AbstractConnector<O,I,CO,CI>
de.iip_ecosphere.platform.connectors.AbstractThreadedConnector<O,I,CO,CI,M>
- 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 connectorM- the model access type of the connector
- All Implemented Interfaces:
Connector<O,,I, CO, CI> EventHandlingConnector,AbstractModelAccess.NotificationChangedListener
public abstract class AbstractThreadedConnector<O,I,CO,CI,M extends ModelAccess>
extends AbstractConnector<O,I,CO,CI>
Provides a reusable base for connectors that require a
ModelAccess instance per calling
thread. Extends AbstractConnector implementation using the
ProtocolAdapter. Call setModelAccessSupplier(Supplier) (and implicitly
AbstractConnector.configureModelAccess(ModelAccess)) before connect(ConnectorParameter).
Calls ModelAccess.dispose().- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested classes/interfaces inherited from class de.iip_ecosphere.platform.connectors.AbstractConnector
AbstractConnector.BasicAdapterProvider -
Field Summary
FieldsFields inherited from class de.iip_ecosphere.platform.connectors.AbstractConnector
DEFAULT_CHANNEL -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractThreadedConnector(AdapterSelector<O, I, CO, CI> selector, ProtocolAdapter<O, I, CO, CI>... adapter) Creates an instance and installs the protocol adapter(s).protectedAbstractThreadedConnector(ProtocolAdapter<O, I, CO, CI>... adapter) Creates an instance and installs the protocol adapter(s) with a default selector for the first adapter. -
Method Summary
Modifier and TypeMethodDescriptionprotected ProtocolAdapter<O, I, CO, CI> configureAdapter(ProtocolAdapter<O, I, CO, CI> adapter) Configures the adapter if needed.voidconnect(ConnectorParameter params) Connects the connector to the underlying machine/platform.intReturns the cleanup period.protected MReturns the model-access instance for the current thread.protected MgetModelAccess(Thread thread) Returns the model-access instance for the given thread.Returns the model access supplier.private MobtainModelAccess(Thread thread) Returns/allocates a model access object forthread.protected voidsetCleanupPeriod(int cleanupPeriod) Changes the cleanup period/timeout.protected voidsetModelAccessSupplier(Supplier<M> modelAccessSupplier) Sets the model access supplier.protected voidUninstall poll task.Methods inherited from class de.iip_ecosphere.platform.connectors.AbstractConnector
checkCache, configureModelAccess, connectImpl, createTlsContext, disconnect, disconnectImpl, dispose, doPolling, enableNotifications, enablePolling, error, getCachingStrategy, getCachingStrategyCls, getConnectorInputType, getConnectorOutputType, getConnectorParameter, getInitCachingStrategyCls, getInstanceIdentification, getProtocolInputType, getProtocolOutputType, getSelector, getStorageValue, initializeModelAccess, initSelector, installPollTask, isPolling, notificationsChanged, notifyDataTimeDifference, notifyReconfigured, read, received, received, request, request, setDataTimeDifference, setDataTimeDifferenceProvider, setInstanceIdentification, setReceptionCallback, setStorageValue, trigger, trigger, useTls, write, writeImplMethods 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.Connector
createSharedSpace, disconnectSafe, enabledEncryption, enableSharedSpace, setReceptionCallbackSafe, supportedEncryptionMethods inherited from interface de.iip_ecosphere.platform.connectors.events.EventHandlingConnector
getName
-
Field Details
-
timer
-
modelAccessSupplier
-
accesses
-
cleanupTask
-
cleanupPeriod
private int cleanupPeriod
-
-
Constructor Details
-
AbstractThreadedConnector
Creates an instance and installs the protocol adapter(s) with a default selector for the first adapter. For integration compatibility, connector constructors are supposed to accept a var-arg parameter for adapters.- Parameters:
adapter- the protocol adapter(s)- Throws:
IllegalArgumentException- ifadapteris null or empty or adapters are null- See Also:
-
AbstractThreadedConnector
@SafeVarargs protected AbstractThreadedConnector(AdapterSelector<O, I, CO, CI> selector, ProtocolAdapter<O, I, CO, CI>... adapter) Creates an instance and installs the protocol adapter(s). For integration compatibility, connector constructors are supposed to accept a var-arg parameter for adapters.- Parameters:
selector- the adapter selector (null leads to a default selector for the first adapter)adapter- the protocol adapter(s)- Throws:
IllegalArgumentException- ifadapteris null or empty or adapters are null- See Also:
-
-
Method Details
-
setModelAccessSupplier
Sets the model access supplier. CallsAbstractConnector.configureModelAccess(ModelAccess)- Parameters:
modelAccessSupplier- supplier for model access instances, ignored if null
-
getModelAccessSupplier
Returns the model access supplier.- Returns:
- the supplier for model access instances (may be null if
setModelAccessSupplier(Supplier)was not called with an appropriate instance before
-
obtainModelAccess
Returns/allocates a model access object forthread.- Parameters:
thread- the thread- Returns:
- the model access object
-
configureAdapter
Description copied from class:AbstractConnectorConfigures the adapter if needed.- Overrides:
configureAdapterin classAbstractConnector<O,I, CO, CI> - Parameters:
adapter- the adapter- Returns:
adapter
-
connect
Description copied from class:AbstractConnectorConnects the connector to the underlying machine/platform. CallsAbstractConnector.connectImpl(ConnectorParameter)and if successful (no exception thrown)AbstractConnector.initializeModelAccess(). CallsConnectorRegistry.registerConnector(Connector). -
setCleanupPeriod
protected void setCleanupPeriod(int cleanupPeriod) Changes the cleanup period/timeout.- Parameters:
cleanupPeriod- the period in ms, ignored if not positive
-
getCleanupPeriod
public int getCleanupPeriod()Returns the cleanup period.- Returns:
- the cleanup period in ms
-
uninstallPollTask
protected void uninstallPollTask()Description copied from class:AbstractConnectorUninstall poll task.- Overrides:
uninstallPollTaskin classAbstractConnector<O,I, CO, CI>
-
getModelAccess
Returns the model-access instance for the current thread.- Returns:
- the model-access instance, may be null
-
getModelAccess
Returns the model-access instance for the given thread.- Parameters:
thread- the thread to return the model access for- Returns:
- the model-access instance, may be null
-