Class RequestHolder<Req,Res>

java.lang.Object
com.oracle.coherence.grpc.RequestHolder<Req,Res>
Type Parameters:
Req - the type of the request
Res - the result type
Direct Known Subclasses:
CacheRequestHolder

public abstract class RequestHolder<Req,Res> extends Object
A class that holds a gRPC request and Binary converters.
Since:
23.03
Author:
Jonathan Knight 2023.02.03
  • Field Details

    • f_request

      protected final Req f_request
      The request.
    • f_sFormat

      protected final String f_sFormat
      The name of the serializer used to serialize the request payloads.
    • f_executor

      protected final Executor f_executor
      The Executor to use to hand off asynchronous tasks.
    • f_service

      protected final Service f_service
      The Service managing the resource.
    • m_converterDown

      protected Converter<Binary,Binary> m_converterDown
      The converter used to convert between a Binary serialized in the request format to a Binary serialized in the cache format.
    • m_converterUp

      protected Converter<Binary,Binary> m_converterUp
      The converter used to convert between a Binary serialized in the cache format to a Binary serialized in the request format.
    • f_serializer

      protected final Serializer f_serializer
      The Serializer used by the request.
    • m_result

      protected Object m_result
      A result value.
  • Constructor Details

    • RequestHolder

      public RequestHolder(Req request, String sFormat, Serializer serializer, Service service, Executor executor)
      Create a RequestHolder.
      Parameters:
      request - the cache request
      sFormat - the name of the serializer used to serialize the request payloads
      serializer - the Serializer used by the request
      executor - the executor for asynchronous processing
  • Method Details

    • getRequest

      public Req getRequest()
      Obtain the cache request.
      Returns:
      the cache request
    • getResult

      public Res getResult()
      Obtain the holder's result value.
      Returns:
      the holder's result value
    • getServiceSerializer

      public Serializer getServiceSerializer()
      Obtain the cache's Serializer.
      Returns:
      the cache's Serializer
    • getDeserializedResult

      public <T> T getDeserializedResult()
      Obtain the holder's deserialized result value, assuming that the result value is a serialized Binary.
      Type Parameters:
      T - the deserialized type
      Returns:
      the holder's deserialized result value
    • fromBinary

      public <T> T fromBinary(Binary binary)
      Obtain the value deserialized from the specified Binary using the cache's serializer.
      Type Parameters:
      T - the deserialized type
      Parameters:
      binary - the Binary of the serialized object
      Returns:
      the deserialized value
    • deserialize

      public <T> T deserialize(Binary binary)
      Obtain the deserialized Binary value using the cache's serializer.
      Type Parameters:
      T - the deserialized type
      Parameters:
      binary - the Binary of the serialized object
      Returns:
      the deserialized Binary value using the cache's serializer
    • deserializeRequest

      public <T> T deserializeRequest(com.google.protobuf.ByteString bytes)
      Obtain the deserialized ByteString value using the request's serializer.
      Type Parameters:
      T - the deserialized type
      Parameters:
      bytes - the ByteString of the serialized object
      Returns:
      the deserialized ByteString value using the request's serializer
    • setResult

      public <T> RequestHolder<Req,T> setResult(T t)
      Set the holder's result value.
      Type Parameters:
      T - the type of the result value
      Parameters:
      t - the result value
      Returns:
      this RequestHolder cast to the new result type
    • getSerializer

      public Serializer getSerializer()
      Obtain the request's Serializer.
      Returns:
      the request's Serializer
    • convertUp

      public Binary convertUp(Binary binary)
      Convert a Binary in the cache's serialization format to a Binary in the request's serialization format.
      Parameters:
      binary - the Binary to convert
      Returns:
      a Binary in the request's serialization format
    • convertDown

      public Binary convertDown(Supplier<com.google.protobuf.ByteString> supplier)
      Convert the ByteString data serialized in the request format to a Binary serialized in the cache's serialization format.
      Parameters:
      supplier - the supplier of the ByteString to convert
      Returns:
      a Binary in the cache's serialization format
    • convertDown

      public Binary convertDown(com.google.protobuf.ByteString bytes)
      Convert the ByteString data serialized in the request format to a Binary serialized in the cache's serialization format.
      Parameters:
      bytes - the ByteString to convert
      Returns:
      a Binary in the cache's serialization format
    • convertDown

      public Binary convertDown(Binary binary)
      Convert the Binary data serialized in the request format to a Binary serialized in the cache's serialization format.
      Parameters:
      binary - the Binary to convert
      Returns:
      a Binary in the cache's serialization format
    • deserializeToBytesValue

      public com.google.protobuf.BytesValue deserializeToBytesValue(Binary binary)
      Convert the Binary serialized in the cache's serialization format to a BytesValue serialized in the request's serialization format.

      The assumption is that the Binary deserializes to another Binary.

      Parameters:
      binary - the Binary to convert
      Returns:
      a BytesValue in the request's serialization format
    • toBytesValue

      public com.google.protobuf.BytesValue toBytesValue(Binary binary)
      Convert the Binary serialized in the cache's serialization format to a BytesValue serialized in the request's serialization format.
      Parameters:
      binary - the Binary to convert
      Returns:
      a BytesValue in the request's serialization format
    • toByteString

      public com.google.protobuf.ByteString toByteString(Binary binary)
      Convert the Binary serialized in the cache's serialization format to a ByteString serialized in the request's serialization format.
      Parameters:
      binary - the Binary to convert
      Returns:
      a ByteString in the request's serialization format
    • toEntry

      public com.oracle.coherence.grpc.Entry toEntry(Binary binKey, Binary binValue)
      Convert a Map.Entry of Binary key and value serialized in the cache's serialization format into an Entry with a key and value serialized in the request's serialization format.
      Parameters:
      binKey - the Binary key
      binValue - the Binary value
      Returns:
      a Entry in the request's serialization format
    • toEntryResult

      public com.oracle.coherence.grpc.EntryResult toEntryResult(Map.Entry<Binary,Binary> entry)
      Convert a Map.Entry of Binary key and value serialized in the cache's serialization format into an EntryResult with a key and value serialized in the request's serialization format.
      Parameters:
      entry - the Binary to convert
      Returns:
      a EntryResult in the request's serialization format
    • toOptionalValue

      public com.oracle.coherence.grpc.OptionalValue toOptionalValue(Binary binary)
      Convert a Binary serialized with the cache's serializer to an OptionalValue containing an optional Binary serialized with the request's serializer.
      Parameters:
      binary - the optional Binary value
      Returns:
      a OptionalValue in the request's serialization format
    • ensureConverterDown

      public Converter<Binary,Binary> ensureConverterDown()
      Obtain the Converter used to convert between the request format and the cache format; creating the Converter if required.
      Returns:
      the Converter used to convert between the request format and the cache format
    • createConverterDown

      protected abstract Converter<Object,Binary> createConverterDown()
      Create the Converter to use to convert from Object form to internal Binary form.
      Returns:
      the Converter to use to convert from Object form to internal Binary form
    • getCacheFormat

      public static String getCacheFormat(Service service)
      Returns the serializer format name for the specified Service's serializer.
      Parameters:
      service - the Service to obtain the serializer format from
      Returns:
      the serializer format name for the specified Service's serializer.
    • ensureConverterUp

      public Converter<Binary,Binary> ensureConverterUp()
      Obtain the Converter used to convert between the cache format and the request format; creating the Converter if required.
      Returns:
      the Converter used to convert between the cache format and the request format