Class SerializationMemoizingMessage

java.lang.Object
org.graylog2.indexer.messages.SerializationMemoizingMessage
All Implemented Interfaces:
ImmutableMessage, Indexable, Acknowledgeable

public class SerializationMemoizingMessage extends Object implements ImmutableMessage
Wraps a Message by making it immutable and caching the result of serialize(SerializationContext) calls.

For more details about the caching behavior, see serialize(SerializationContext)

  • Constructor Details

    • SerializationMemoizingMessage

      public SerializationMemoizingMessage(Message delegate)
  • Method Details

    • serialize

      public byte[] serialize(SerializationContext context) throws IOException
      Serializes a message to JSON and memoizes the result as a SoftReference.

      As long as the same SerializationContext.objectMapper() is used in consecutive calls, the result will be memoized. If a context with a different object mapper is used, the memoized serialized byte array will be replaced with a newly serialized value.

      The serialization result will be maintained as a SoftReference. If the JVM experiences memory pressure, the memoized value might be cleared, and consecutive calls will cause the serialization operation to execute again. In that case, a warning will be logged.

      Specified by:
      serialize in interface Indexable
      Parameters:
      context - Context required to perform the serialization
      Returns:
      The serialized value. May return a memoized value according to the rules described above.
      Throws:
      IOException - If serialization goes wrong.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getId

      @Deprecated public String getId()
      Deprecated.
      Description copied from interface: Indexable
      Returns the id to address the document in Elasticsearch. Depending on the implementation this might return a UUID or ULID This method should only be used where backwards compatibility is needed. Newer code should use Indexable.getMessageId() instead.
      Specified by:
      getId in interface ImmutableMessage
      Specified by:
      getId in interface Indexable
    • getMessageId

      public String getMessageId()
      Description copied from interface: Indexable
      Returns the id to address the document in Elasticsearch. The message id is represented as a ULID
      Specified by:
      getMessageId in interface Indexable
    • getSize

      public long getSize()
      Specified by:
      getSize in interface Indexable
    • getReceiveTime

      public org.joda.time.DateTime getReceiveTime()
      Specified by:
      getReceiveTime in interface Indexable
    • toElasticSearchObject

      public Map<String,Object> toElasticSearchObject(com.fasterxml.jackson.databind.ObjectMapper objectMapper, @Nonnull com.codahale.metrics.Meter invalidTimestampMeter)
      Specified by:
      toElasticSearchObject in interface Indexable
    • getTimestamp

      public org.joda.time.DateTime getTimestamp()
      Specified by:
      getTimestamp in interface Indexable
    • supportsFailureHandling

      public boolean supportsFailureHandling()
      Description copied from interface: Indexable
      Guides the failure handling framework when deciding whether this particular message should be accepted for the further failure processing. By default disabled for all messages.
      Specified by:
      supportsFailureHandling in interface Indexable
    • getIndexSets

      public com.google.common.collect.ImmutableSet<IndexSet> getIndexSets()
      Specified by:
      getIndexSets in interface ImmutableMessage
    • getFields

      public com.google.common.collect.ImmutableMap<String,Object> getFields()
      Specified by:
      getFields in interface ImmutableMessage
    • getMessage

      public String getMessage()
      Specified by:
      getMessage in interface ImmutableMessage
    • getField

      public Object getField(String key)
      Specified by:
      getField in interface ImmutableMessage
    • getSource

      public String getSource()
      Specified by:
      getSource in interface ImmutableMessage
    • getStreamIds

      public com.google.common.collect.ImmutableSet<String> getStreamIds()
      Specified by:
      getStreamIds in interface ImmutableMessage
    • getMessageQueueId

      public Object getMessageQueueId()
      Specified by:
      getMessageQueueId in interface Acknowledgeable