Class Event<C,R>
- All Implemented Interfaces:
berlin.yuna.typemap.model.TypeInfo<berlin.yuna.typemap.model.TypeMap>,berlin.yuna.typemap.model.TypeMapI<berlin.yuna.typemap.model.TypeMap>,Serializable,Cloneable,Map<Object,Object>
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Contextprotected Throwableprotected final AtomicBooleanprotected Cprotected R -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionMarks the event as acknowledged without providing a response body.async(boolean async) Sets the event to asynchronous mode, allowing the response to be handled by a listener.Sets the event to asynchronous mode, allowing the response to be handled by a listener.broadcast(boolean broadcast) Sets the broadcast flag.channel()Returns the name of theChannel.booleanReturnstrueif the resolved payload is itself anEvent.containsEvent(boolean containsEvent) Sets the internal flag indicating that the payload contains a nested event.context()Returns the context associated with this event.booleanTwo events are equal when their underlying map content is equal and they share the same channel, context, listener, and payload supplier.error()Returns the most relevant error for this event.Attaches an error to this event.Applies a predicate to this event and returns aTypewrapper containing either this event (when the predicate passes) ornull.inthashCode()booleanIndicates whether the event has been acknowledged viarespond(Object)oracknowledge().booleanisAsync()Returnstrueif a response listener is installed (i.e., the event is asynchronous).booleanReturns whether this event is marked as broadcast.listener()Returns the currently configured response listener, if any.payload()Returns the payload, resolving the supplier on first access and caching the result.Sets the payload of the event.Acknowledges the event and returns the resolved payload.payloadAckAsync(Consumer<C> consumer) Acknowledges first, then resolves the payload asynchronously and passes it to the consumer.Acknowledges the event and returns the payload if present.payloadAsync(Consumer<C> consumer) Resolves the payload asynchronously on theContextexecutor and passes it to the consumer.Returns the resolved payload if present.Invokes the given consumer with this event and returns this instance.Puts the key/value into the underlying map and returnsthisfor fluent chaining.Completes the event with a response and marks it as acknowledged.response()Returns the response value set viarespond(Object).Returns the response as anOptional.<T> Optional<T> responseOpt(Class<T> type) Returns the response as anOptionalonly if it is compatible withtype.send()Sends the event to the Nano instance for processing.sendR()Sends the event to the Nano instance for processing.toString()Returns a JSON-like representation with selected fields for diagnostics.Methods inherited from class berlin.yuna.typemap.model.TypeMap
addR, convertAndMap, convertAndMap, mapOf, treeGetMethods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from interface berlin.yuna.typemap.model.TypeInfo
addPath, addPathR, as, asArray, asArray, asAtomicBoolean, asAtomicBooleanOpt, asAtomicInteger, asAtomicIntegerOpt, asAtomicLong, asAtomicLongOpt, asBigDecimal, asBigDecimalOpt, asBigInteger, asBigIntegerOpt, asBoolean, asBooleanOpt, asBooleans, asByte, asByteOpt, asBytes, asCalendar, asCalendarOpt, asCalendars, asCharacter, asCharacterOpt, asCharacters, asCharset, asCharsetOpt, asCharsets, asDate, asDateOpt, asDates, asDouble, asDoubleOpt, asDoubles, asFile, asFileOpt, asFiles, asFloat, asFloatOpt, asFloats, asInet4Address, asInet4Addresses, asInet4AddressOpt, asInet6Address, asInet6Addresses, asInet6AddressOpt, asInetAddress, asInetAddresses, asInetAddressOpt, asInstant, asInstantOpt, asInstants, asInt, asIntOpt, asInts, asList, asList, asList, asLocalDate, asLocalDateOpt, asLocalDates, asLocalDateTime, asLocalDateTimeOpt, asLocalDateTimes, asLocalTime, asLocalTimeOpt, asLocalTimes, asLong, asLongOpt, asLongs, asMap, asMap, asMap, asMap, asMap, asMap, asNumber, asNumberOpt, asNumbers, asOffsetDateTime, asOffsetDateTimeOpt, asOffsetDateTimes, asOpt, asOpt, asPath, asPathOpt, asPaths, asShort, asShortOpt, asShorts, asSqlDate, asSqlDateOpt, asSqlDates, asString, asStringOpt, asStrings, asThrowable, asThrowableOpt, asThrowables, asTime, asTimeOpt, asTimes, asTimestamp, asTimestampOpt, asTimestamps, asURI, asURIOpt, asURIs, asURL, asURLOpt, asURLs, asUUID, asUUIDOpt, asUUIDs, asZonedDateTime, asZonedDateTimeOpt, asZonedDateTimes, containsPath, filter, flatMap, flatOpt, get, ifPresent, ifPresentOrElse, isEmpty, isPresent, map, or, orElse, orElseGet, orElseThrow, orElseThrow, putPath, putPathR, setPath, setPathR, stream, toJson, toJsonMethods inherited from interface berlin.yuna.typemap.model.TypeMapI
typeListOpt, typeMapOpt
-
Field Details
-
channel
-
context
-
responseListener
-
payload
-
payloadRaw
-
response
-
error
-
isAcknowledged
-
-
Constructor Details
-
Event
Constructs an instance of the Event class with specified payload, context, payload, and response listener. This event object can be used to trigger specific actions or responses based on the event payload and payload.
-
-
Method Details
-
channel
Returns the name of theChannel.- Returns:
- the name of the
Channel.
-
channel
-
async
Sets the event to asynchronous mode, allowing the response to be handled by a listener.- Returns:
- self for chaining
-
async
Sets the event to asynchronous mode, allowing the response to be handled by a listener.- Parameters:
responseListener- A consumer that handles the response of the event processing. It can be used to execute actions based on the event's outcome or data.- Returns:
- self for chaining
-
payload
Sets the payload of the event.- Parameters:
payload- The data or object that is associated with this event. This can be any relevant information that needs to be passed along with the event.- Returns:
- self for chaining
-
payloadAck
Acknowledges the event and returns the resolved payload.Equivalent to
acknowledge().payload().- Returns:
- the payload value
-
payloadOpt
Returns the resolved payload if present.- Returns:
- optional payload
-
payloadAckOpt
Acknowledges the event and returns the payload if present.If the payload exists,
respond(Object)is invoked withnullto mark acknowledgement and the payload is returned.- Returns:
- optional payload after acknowledgement
-
payloadAsync
Resolves the payload asynchronously on theContextexecutor and passes it to the consumer. Does nothing if no payload has been set.- Parameters:
consumer- callback receiving the resolved payload- Returns:
- this event for chaining
-
payloadAckAsync
Acknowledges first, then resolves the payload asynchronously and passes it to the consumer.- Parameters:
consumer- callback receiving the resolved payload- Returns:
- this event for chaining
-
payload
Returns the payload, resolving the supplier on first access and caching the result.If the resolved value is an
Event, this instance recordscontainsEvent=trueand sets aparentEventlink on the nested event to support acknowledgement and error propagation.- Returns:
- the payload value; may be
nullif no supplier/value were provided
-
isAcknowledged
public boolean isAcknowledged()Indicates whether the event has been acknowledged viarespond(Object)oracknowledge().- Returns:
trueif acknowledged; otherwisefalse
-
acknowledge
Marks the event as acknowledged without providing a response body.Shorthand for
respond(null).- Returns:
- this event for chaining
-
isBroadcast
public boolean isBroadcast()Returns whether this event is marked as broadcast.Broadcast is a lightweight flag stored in the event map; routing components may use it to fan out delivery.
- Returns:
trueif broadcast; otherwisefalse
-
broadcast
Sets the broadcast flag.- Parameters:
broadcast- whether the event should be treated as broadcast- Returns:
- this event for chaining
-
context
Returns the context associated with this event.- Returns:
- the context
-
isAsync
public boolean isAsync()Returnstrueif a response listener is installed (i.e., the event is asynchronous).- Returns:
truewhen async; otherwisefalse
-
containsEvent
public boolean containsEvent()Returnstrueif the resolved payload is itself anEvent.- Returns:
- whether the payload contains a nested event
-
containsEvent
Sets the internal flag indicating that the payload contains a nested event.- Parameters:
containsEvent-trueif payload is an event- Returns:
- this event for chaining
-
listener
Returns the currently configured response listener, if any.- Returns:
- the listener or
nullif synchronous
-
respond
Completes the event with a response and marks it as acknowledged.If a listener is present, it is invoked with the response. Acknowledgement is also propagated to a parent or nested event when applicable.
- Parameters:
response- the response value (maybenull)- Returns:
- this event for chaining
-
response
Returns the response value set viarespond(Object).- Returns:
- the response; may be
nullif none
-
responseOpt
Returns the response as anOptional.- Returns:
- optional response
-
responseOpt
Returns the response as anOptionalonly if it is compatible withtype.- Type Parameters:
T- desired response view- Parameters:
type- target class to check against the channel's response type- Returns:
- optional typed response when assignable; otherwise empty
-
peek
Invokes the given consumer with this event and returns this instance.Useful for debugging or fluent side-effects without breaking the chain.
- Parameters:
peek- consumer observing this event- Returns:
- this event for chaining
-
putR
Puts the key/value into the underlying map and returnsthisfor fluent chaining.- Parameters:
key- map keyvalue- map value- Returns:
- this event for chaining
-
filter
Applies a predicate to this event and returns aTypewrapper containing either this event (when the predicate passes) ornull.The
Typeclass integrates nicely with the project’sTypeMapusage.- Parameters:
predicate- filter to evaluate- Returns:
- a
Typecontaining this event ornull
-
error
Returns the most relevant error for this event.If a direct error has been set via
error(Throwable), it is returned. Otherwise, the method attempts to retrieve an error from the parent event or a nested payload event (if present).- Returns:
- the error or
nullif none found
-
error
Attaches an error to this event.- Parameters:
error- the throwable to associate- Returns:
- this event for chaining
-
send
Sends the event to the Nano instance for processing.- Returns:
- self for chaining
-
sendR
Sends the event to the Nano instance for processing.- Returns:
Contextfor chaining
-
toString
Returns a JSON-like representation with selected fields for diagnostics.- Overrides:
toStringin classAbstractMap<Object,Object>
-
equals
Two events are equal when their underlying map content is equal and they share the same channel, context, listener, and payload supplier. -
hashCode
public int hashCode()
-