Record Class ReadCoalescingFilter

java.lang.Object
java.lang.Record
com.loomcache.server.handler.ReadCoalescingFilter

public record ReadCoalescingFilter(DataOperationHandler handler, RequestCoalescer coalescer) extends Record
A filter that wraps a DataOperationHandler to add read request coalescing.

Read operations (GET, CONTAINS_KEY, SIZE) are intercepted and coalesced to reduce redundant work under high concurrency. Write operations (PUT, DELETE, etc.) are passed through unchanged.

Coalescing is configurable and can be toggled on/off at runtime.

Thread-safe: Delegates to the underlying handler and RequestCoalescer, both of which are thread-safe.

Since:
1.0
  • Constructor Details

    • ReadCoalescingFilter

      public ReadCoalescingFilter(DataOperationHandler handler)
      Create a new ReadCoalescingFilter.
      Parameters:
      handler - the underlying DataOperationHandler to wrap (non-null)
      Throws:
      NullPointerException - if handler is null
    • ReadCoalescingFilter

      public ReadCoalescingFilter(DataOperationHandler handler, RequestCoalescer coalescer)
      Create a new ReadCoalescingFilter with a custom RequestCoalescer.
      Parameters:
      handler - the underlying DataOperationHandler to wrap (non-null)
      coalescer - the RequestCoalescer to use (non-null)
      Throws:
      NullPointerException - if handler or coalescer is null
  • Method Details

    • handle

      public @Nullable Message handle(Message message)
      Handle a message, applying coalescing for read operations.

      If the operation is a read operation (GET, CONTAINS_KEY, SIZE) and coalescing is enabled, the request is coalesced. Otherwise, it is passed through directly.

      Parameters:
      message - the incoming message (non-null)
      Returns:
      the response message
      Throws:
      NullPointerException - if message is null
    • coalescer

      public RequestCoalescer coalescer()
      Get the underlying RequestCoalescer.
      Returns:
      the coalescer
    • handler

      public DataOperationHandler handler()
      Get the underlying handler.
      Returns:
      the DataOperationHandler
    • 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.