Class StoredDeadlineConverter
The stored form holds the payload's type name next to the payload, and the class name next to the scope descriptor.
The type name "empty" marks a deadline without a payload, as in Axon Framework 4. Any other type name is
resolved to a class, and the stored data is converted into it with the configured Converter. A type name that
resolves to no class yields an UnknownDeadlinePayload instead of a failure, as Axon Framework 4's
UnknownSerializedType did.
With an XStreamConverter, a type name is first resolved through the
mapper of its XStream instance, as Axon Framework 4's XStreamSerializer did. That serializer stored a
type's XStream alias instead of its class name, for XStream's built-in aliases such as uuid, int or
long, and for aliases the application registered. Such a payload or scope descriptor resolves when the
converter's XStream instance has the same aliases as the one Axon Framework 4 used.
A String or byte[] payload is stored the way Axon Framework 4's serializers stored it: as a JSON
string, Base64-encoded for a byte[], or as an XStream <string> or <byte-array> element. A
Converter treats a String or byte[] as content that is already in its stored form, so it
would store such a payload as is. Which of the two forms to write follows from the configured converter's format,
which is detected once, by converting a probe value. The JSON string is written and read with Jackson's streaming
JSON writer and parser, and the XStream element with XStream itself, so that both match what Axon Framework 4
wrote. A converter
that writes neither JSON nor XStream XML cannot store such a payload, and scheduling one fails. Reading follows the
stored form; the type names string and byte-array, under which Axon Framework 4's
XStreamSerializer stored these payloads, are XStream aliases and resolve as described above.
Metadata is read untyped, into a Map<String, Object>, and each value is turned into a String: Axon
Framework 4 metadata could hold any value, while Axon Framework 5 metadata holds strings only. Strings stay as they
are, numbers and booleans become their string value, and maps and lists are rendered
as JSON by Jackson's streaming JSON writer, the same for every converter that reads them as maps and lists. The
XStreamConverter already turns every metadata value into its string
value, so a nested value stored with XStream arrives as its toString(). Nested metadata is not expected
there, as that converter serves Saga and deadline payloads with plain metadata values.
This class is internal, as it only serves the deadline managers of this module, which share the stored layout.
- Since:
- 5.4.0
- Author:
- Jakob Hatzl
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe stored type name of a deadline without a payload. -
Constructor Summary
ConstructorsConstructorDescriptionStoredDeadlineConverter(Converter converter) Creates aStoredDeadlineConverterconverting with the givenconverter. -
Method Summary
Modifier and TypeMethodDescription<T> TfromStored(Object data, Class<T> type) Converts the given storeddatainto the giventype, for stored structures that are converted as a whole, such as JobRunr'sDeadlineDetails.static MessageTypemessageTypeOf(@Nullable Object payload) Returns theMessageTypeof a deadline carrying the givenpayload, derived from the payload's class, as the stored form keeps no message type.Converts the given stored metadata intoMetadata.@Nullable ObjectConverts the given stored payload into the class named by the giventypeName.<T> @Nullable TpayloadToStored(@Nullable Object payload, Class<T> representation) Converts the given deadlinepayloadinto the given storedrepresentation,byte[]orString.Converts the given stored scope descriptor into the class named by the givenclassName.<T> @Nullable TConverts the givenvalueinto the given storedrepresentation, such asbyte[]orString.static StringtypeNameOf(@Nullable Object payload) Returns the type name to store for the givenpayload: its class name, or "empty" if there is no payload.
-
Field Details
-
EMPTY_TYPE
The stored type name of a deadline without a payload. Axon Framework 4 nodes read it back as anullpayload without loading a class.- See Also:
-
-
Constructor Details
-
StoredDeadlineConverter
Creates aStoredDeadlineConverterconverting with the givenconverter.- Parameters:
converter- the converter matching the stored form of the deadlines
-
-
Method Details
-
typeNameOf
Returns the type name to store for the givenpayload: its class name, or "empty" if there is no payload.- Parameters:
payload- the payload of the deadline to store- Returns:
- the type name to store with the payload
-
messageTypeOf
Returns theMessageTypeof a deadline carrying the givenpayload, derived from the payload's class, as the stored form keeps no message type.- Parameters:
payload- the payload of the deadline- Returns:
- the message type derived from the payload's class
-
payloadToStored
Converts the given deadlinepayloadinto the given storedrepresentation,byte[]orString. Without a payload, this is the serializednull, the JSONnull, as Axon Framework 4'sJacksonSerializerwrote it: Axon Framework 4 nodes do not read the data stored under the type name "empty", but reject a job whose data is missing. AStringorbyte[]payload is stored as Axon Framework 4 stored it in the configured converter's format.- Type Parameters:
T- the stored representation- Parameters:
payload- the payload of the deadline to store, if anyrepresentation- the stored representation,byte[]orString- Returns:
- the stored form of the given
payload - Throws:
DeadlineException- if the payload is aStringorbyte[], and the configured converter writes neither JSON nor XStream XML
-
toStored
Converts the givenvalueinto the given storedrepresentation, such asbyte[]orString.- Type Parameters:
T- the stored representation- Parameters:
value- the payload, metadata or scope descriptor to storerepresentation- the stored representation- Returns:
- the stored form of the given
value, ornullif it isnull
-
fromStored
Converts the given storeddatainto the giventype, for stored structures that are converted as a whole, such as JobRunr'sDeadlineDetails.- Type Parameters:
T- the type to convert the stored data into- Parameters:
data- the stored datatype- the type to convert the stored data into- Returns:
- the converted data
- Throws:
DeadlineException- if the data converts tonull
-
payload
Converts the given stored payload into the class named by the giventypeName.- Parameters:
typeName- the stored type name of the payloadrevision- the stored revision of the payload type, read but not used for the conversiondata- the stored payload- Returns:
nullfor the type name "empty", anUnknownDeadlinePayloadif the type name resolves to no class, and the converted payload otherwise- Throws:
DeadlineException- if aStringorbyte[]payload is stored in neither form Axon Framework 4 stored it in
-
scope
Converts the given stored scope descriptor into the class named by the givenclassName.- Parameters:
className- the stored class name of the scope descriptordata- the stored scope descriptor- Returns:
- the converted scope descriptor
- Throws:
DeadlineException- if the class name resolves to noScopeDescriptorclass, or the data converts to no scope descriptor
-
metadata
Converts the given stored metadata intoMetadata. Each value becomes aString: strings stay as they are, numbers and booleans become their string value, and maps and lists are rendered as JSON. A nested value read through anXStreamConverterarrives as itstoString(), as that converter already turns every metadata value into a string.- Parameters:
data- the stored metadata, ornullif none was stored- Returns:
- the converted metadata, empty if none was stored
-