Class TransportToAasConverter<T>
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.services.TransportToAasConverter<T>
-
- Type Parameters:
T- the data type
- Direct Known Subclasses:
TraceToAasService.Converter
public abstract class TransportToAasConverter<T> extends java.lang.ObjectImplements a generic converter from transport stream entries to AAS.- Author:
- Holger Eichelberger, SSE
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTransportToAasConverter.CleanupPredicatePredicate to determine whether a submodel elements collection shall be deleted.private classTransportToAasConverter.TraceRecordReceptionCallbackA trace reception callback callinghandleNew(Object)in own threads.static classTransportToAasConverter.TypeConverterEncapsulates a Java-to-AAS type converter.static interfaceTransportToAasConverter.ValueConverterConverts a Java value to an AAS value.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description TransportToAasConverter(java.lang.String submodelIdShort, java.lang.String transportStream, java.lang.Class<T> dataType)Creates a service instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddConverter(java.lang.Class<?> cls, TransportToAasConverter.TypeConverter converter)Adds/overwrites a converter.protected booleanbuildUpAas(de.iip_ecosphere.platform.support.aas.Aas.AasBuilder aasBuilder)Builds up the AAS.voidcleanup(de.iip_ecosphere.platform.support.aas.Aas aas)Cleans up outdated trace entries.protected booleancleanUpAas(de.iip_ecosphere.platform.support.aas.Aas aas)Cleans up the AAS.protected voidcreatePayloadEntries(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection.SubmodelElementCollectionBuilder payloadBuilder, java.lang.Object payload)Creates the generic properties and contents for the given payload object.abstract java.lang.StringgetAasId()Returns the AAS idShort of the AAS represented by this service/application.abstract java.lang.StringgetAasUrn()Returns the AAS URN of the AAS represented by this service/application.abstract TransportToAasConverter.CleanupPredicategetCleanupPredicate()Returns the cleanup predicate.protected abstract java.util.function.Function<T,java.lang.String>getSubmodelElementIdFunction()Returns a function turning a data instance into an id of the submodel representing the data instance.longgetTimeout()Returns the timeout.private java.lang.ObjectgetValue(java.lang.Object object, java.lang.reflect.Method method, java.lang.String field)Obtains the value return bymethodonpayload.protected voidhandleNew(T data)Handles a new trace record and cleans up outdated ones.private static booleanisGetter(java.lang.reflect.Method method)Returns whethermethodis an usual getter.protected java.lang.StringmapPayloadType(java.lang.Class<?> cls)Allows for application specific payload type names.protected abstract voidpopulateSubmodelElementCollection(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection.SubmodelElementCollectionBuilder smcBuilder, T data)Creates the submodel element representing a single received data value.voidsetTimeout(long timeout)Changes the timeout until trace events are deleted.booleanstart(de.iip_ecosphere.platform.support.iip_aas.AasPartRegistry.AasSetup aasSetup, boolean deploy)Starts the transport tracer.booleanstop()Stops the transport, deletes the AAS.
-
-
-
Field Detail
-
IDENTITY_CONVERTER
public static final TransportToAasConverter.ValueConverter IDENTITY_CONVERTER
-
JSON_CONVERTER
public static final TransportToAasConverter.ValueConverter JSON_CONVERTER
-
SHORT2INT_CONVERTER
public static final TransportToAasConverter.ValueConverter SHORT2INT_CONVERTER
-
STRING_CONVERTER
public static final TransportToAasConverter.ValueConverter STRING_CONVERTER
-
ENUM_NAME_CONVERTER
public static final TransportToAasConverter.ValueConverter ENUM_NAME_CONVERTER
-
DEFAULT_CONVERTERS
private static final java.util.Map<java.lang.Class<?>,TransportToAasConverter.TypeConverter> DEFAULT_CONVERTERS
-
PREFIX_GETTER
private static final java.lang.String PREFIX_GETTER
- See Also:
- Constant Field Values
-
METHODS_TO_IGNORE
private static final java.util.Set<java.lang.String> METHODS_TO_IGNORE
-
converters
private java.util.Map<java.lang.Class<?>,TransportToAasConverter.TypeConverter> converters
-
timeout
private long timeout
-
lastCleanup
private long lastCleanup
-
cleanupTimeout
private long cleanupTimeout
-
callback
private TransportToAasConverter.TraceRecordReceptionCallback callback
-
submodelIdShort
private java.lang.String submodelIdShort
-
transportStream
private java.lang.String transportStream
-
dataType
private java.lang.Class<T> dataType
-
aasSetup
private de.iip_ecosphere.platform.support.iip_aas.AasPartRegistry.AasSetup aasSetup
-
-
Constructor Detail
-
TransportToAasConverter
public TransportToAasConverter(java.lang.String submodelIdShort, java.lang.String transportStream, java.lang.Class<T> dataType)Creates a service instance.- Parameters:
submodelIdShort- the id short of the submodel to be maintainedtransportStream- the transport stream to be observed (name of the stream)dataType- the type of the data in the transport stream
-
-
Method Detail
-
setTimeout
public void setTimeout(long timeout)
Changes the timeout until trace events are deleted.- Parameters:
timeout- the timeout in ms
-
getTimeout
public long getTimeout()
Returns the timeout.- Returns:
- the timeout
-
addConverter
protected void addConverter(java.lang.Class<?> cls, TransportToAasConverter.TypeConverter converter)Adds/overwrites a converter.- Parameters:
cls- the class the converter applies toconverter- the converter instance
-
getAasId
public abstract java.lang.String getAasId()
Returns the AAS idShort of the AAS represented by this service/application.- Returns:
- the idShort
-
getAasUrn
public abstract java.lang.String getAasUrn()
Returns the AAS URN of the AAS represented by this service/application.- Returns:
- the URN
-
handleNew
protected void handleNew(T data)
Handles a new trace record and cleans up outdated ones. Called upon arrival. [protected for mocking]- Parameters:
data- the trace record data- See Also:
getSubmodelElementIdFunction(),populateSubmodelElementCollection(SubmodelElementCollectionBuilder, Object)
-
populateSubmodelElementCollection
protected abstract void populateSubmodelElementCollection(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection.SubmodelElementCollectionBuilder smcBuilder, T data)Creates the submodel element representing a single received data value.- Parameters:
smcBuilder- the builder for the submodel element collection representing the data valuedata- the data that may be used to create the element
-
getSubmodelElementIdFunction
protected abstract java.util.function.Function<T,java.lang.String> getSubmodelElementIdFunction()
Returns a function turning a data instance into an id of the submodel representing the data instance.- Returns:
- the function
-
createPayloadEntries
protected void createPayloadEntries(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection.SubmodelElementCollectionBuilder payloadBuilder, java.lang.Object payload)Creates the generic properties and contents for the given payload object.- Parameters:
payloadBuilder- the payload builderpayload- the payload to be presented
-
getValue
private java.lang.Object getValue(java.lang.Object object, java.lang.reflect.Method method, java.lang.String field)Obtains the value return bymethodonpayload.- Parameters:
object- the object to call the method onmethod- the method to callfield- the represented field (for logging)- Returns:
- the value of
fieldviamethod
-
mapPayloadType
protected java.lang.String mapPayloadType(java.lang.Class<?> cls)
Allows for application specific payload type names.- Parameters:
cls- the type- Returns:
- the mapped name
-
isGetter
private static boolean isGetter(java.lang.reflect.Method method)
Returns whethermethodis an usual getter.- Parameters:
method- the method to analyze- Returns:
truefor getter,falseelse
-
cleanup
public void cleanup(de.iip_ecosphere.platform.support.aas.Aas aas)
Cleans up outdated trace entries. Called inhandleNew(Object)if regular input is expected, may be called regularly by an external timer.- Parameters:
aas- the AAS to clean up- See Also:
getCleanupPredicate()
-
getCleanupPredicate
public abstract TransportToAasConverter.CleanupPredicate getCleanupPredicate()
Returns the cleanup predicate.- Returns:
- the predicate
-
start
public boolean start(de.iip_ecosphere.platform.support.iip_aas.AasPartRegistry.AasSetup aasSetup, boolean deploy)Starts the transport tracer.- Parameters:
aasSetup- the AAS setup to usedeploy- whether the AAS represented by this converter shall be deployed- Returns:
truefor success,falseelse
-
buildUpAas
protected boolean buildUpAas(de.iip_ecosphere.platform.support.aas.Aas.AasBuilder aasBuilder)
Builds up the AAS.- Parameters:
aasBuilder- the aas builder to use- Returns:
truefor success,falseelse
-
stop
public boolean stop()
Stops the transport, deletes the AAS.- Returns:
truefor success,falseelse
-
cleanUpAas
protected boolean cleanUpAas(de.iip_ecosphere.platform.support.aas.Aas aas)
Cleans up the AAS. Last action, may delete the AAS itself.- Parameters:
aas- the AAS to clean up- Returns:
truefor success,falseelse
-
-