Record Class SimpleEntry<M extends Message>

java.lang.Object
java.lang.Record
org.axonframework.messaging.core.SimpleEntry<M>
Type Parameters:
M - The type of Message contained in this MessageStream.Entry implementation.
Record Components:
message - The Message of type M contained in this MessageStream.Entry.
context - Maintains additional contextual information of this entry.
All Implemented Interfaces:
Context, MessageStream.Entry<M>

public record SimpleEntry<M extends Message>(@Nullable M extends Message message, @Nonnull Context context) extends Record implements MessageStream.Entry<M>
Simple implementation of the MessageStream.Entry containing a single Message implementation of type M and a Context.
Since:
5.0.0
Author:
Steven van Beelen
  • Constructor Details

    • SimpleEntry

      public SimpleEntry(@Nullable M message)
      Construct a SimpleEntry with the given message and an empty Context.
      Parameters:
      message - The Message of type M contained in this MessageStream.Entry.
    • SimpleEntry

      public SimpleEntry(@Nullable M message, @Nonnull Context context)
      Compact construct asserting the context is not null.
      Parameters:
      message - The message for this entry
      context - The context for this entry
  • Method Details

    • map

      public <RM extends Message> MessageStream.Entry<RM> map(@Nonnull Function<M,RM> mapper)
      Description copied from interface: MessageStream.Entry
      Maps the MessageStream.Entry.message() by running it through the given mapper. This adjusts the contained MessageStream.Entry.message() into a Message implementation of type RM.
      Specified by:
      map in interface MessageStream.Entry<M extends Message>
      Type Parameters:
      RM - The declared type of Message resulting from the given mapper.
      Parameters:
      mapper - A Function mapping the MessageStream.Entry.message() of type M to a Message of type RM.
      Returns:
      The result of running the current MessageStream.Entry.message() through the given mapper.
    • containsResource

      public boolean containsResource(@Nonnull Context.ResourceKey<?> key)
      Description copied from interface: Context
      Indicates whether a resource has been registered with the given key in this Context.
      Specified by:
      containsResource in interface Context
      Parameters:
      key - The key of the resource to check.
      Returns:
      true if a resource is registered with this key, otherwise false.
    • getResource

      public <T> T getResource(@Nonnull Context.ResourceKey<T> key)
      Description copied from interface: Context
      Returns the resource currently registered under the given key, or null if no resource is present.
      Specified by:
      getResource in interface Context
      Type Parameters:
      T - The type of resource registered under the given key.
      Parameters:
      key - The key to retrieve the resource for.
      Returns:
      The resource currently registered under given key, or null if not present.
    • withResource

      public <T> MessageStream.Entry<M> withResource(@Nonnull Context.ResourceKey<T> key, @Nonnull T resource)
      Description copied from interface: Context
      Constructs a copy of this Context with an additional resource for given key.
      Specified by:
      withResource in interface Context
      Specified by:
      withResource in interface MessageStream.Entry<M extends Message>
      Type Parameters:
      T - The type of resource registered under the given key.
      Parameters:
      key - The key under which to register the resource.
      resource - The resource to register.
      Returns:
      A copy of this Context with the added given resources under the given key to the copy.
    • resources

      public Map<Context.ResourceKey<?>,Object> resources()
      Description copied from interface: Context
      Retrieves all resources contained within the current Context.

      Most of the time, none of the keys make any sense to the component that would retrieve them. Thus, this method is purely here for copying resources between Context instances, not for retrieval. For that, there's the Context.getResource(ResourceKey) method.

      Specified by:
      resources in interface Context
      Returns:
      A map containing all resources where each entry has a ResourceKey<?> as the key and the associated resource object as the value.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • message

      @Nullable public M message()
      Returns the value of the message record component.
      Specified by:
      message in interface MessageStream.Entry<M extends Message>
      Returns:
      the value of the message record component
    • context

      @Nonnull public Context context()
      Returns the value of the context record component.
      Returns:
      the value of the context record component