Package com.oracle.coherence.grpc
Class RequestHolder<Req,Res>
- java.lang.Object
-
- com.oracle.coherence.grpc.RequestHolder<Req,Res>
-
- Type Parameters:
Req
- the type of the requestRes
- the result type
- Direct Known Subclasses:
CacheRequestHolder
public abstract class RequestHolder<Req,Res> extends Object
A class that holds a gRPC request andBinary
converters.- Since:
- 23.03
- Author:
- Jonathan Knight 2023.02.03
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
RequestHolder.DownConverter
protected static class
RequestHolder.ErrorHandlingConverter<F,T>
protected static class
RequestHolder.UpConverter
-
Field Summary
Fields Modifier and Type Field Description protected Executor
f_executor
TheExecutor
to use to hand off asynchronous tasks.protected Req
f_request
The request.protected Serializer
f_serializer
TheSerializer
used by the request.protected Service
f_service
TheService
managing the resource.protected String
f_sFormat
The name of the serializer used to serialize the request payloads.protected Converter<Binary,Binary>
m_converterDown
protected Converter<Binary,Binary>
m_converterUp
protected Object
m_result
A result value.
-
Constructor Summary
Constructors Constructor Description RequestHolder(Req request, String sFormat, Serializer serializer, Service service, Executor executor)
Create aRequestHolder
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Binary
convertDown(com.google.protobuf.ByteString bytes)
Convert theByteString
data serialized in the request format to aBinary
serialized in the cache's serialization format.Binary
convertDown(Binary binary)
Binary
convertDown(Supplier<com.google.protobuf.ByteString> supplier)
Convert theByteString
data serialized in the request format to aBinary
serialized in the cache's serialization format.Binary
convertUp(Binary binary)
protected abstract Converter<Object,Binary>
createConverterDown()
<T> T
deserialize(Binary binary)
Obtain the deserializedBinary
value using the cache's serializer.<T> T
deserializeRequest(com.google.protobuf.ByteString bytes)
Obtain the deserializedByteString
value using the request's serializer.com.google.protobuf.BytesValue
deserializeToBytesValue(Binary binary)
Convert theBinary
serialized in the cache's serialization format to aBytesValue
serialized in the request's serialization format.Converter<Binary,Binary>
ensureConverterDown()
Converter<Binary,Binary>
ensureConverterUp()
<T> T
fromBinary(Binary binary)
Obtain the value deserialized from the specifiedBinary
using the cache's serializer.static String
getCacheFormat(Service service)
Returns the serializer format name for the specifiedService
's serializer.<T> T
getDeserializedResult()
Obtain the holder's deserialized result value, assuming that the result value is a serializedBinary
.Req
getRequest()
Obtain the cache request.Res
getResult()
Obtain the holder's result value.Serializer
getSerializer()
Obtain the request'sSerializer
.Serializer
getServiceSerializer()
Obtain the cache'sSerializer
.<T> RequestHolder<Req,T>
setResult(T t)
Set the holder's result value.com.google.protobuf.ByteString
toByteString(Binary binary)
Convert theBinary
serialized in the cache's serialization format to aByteString
serialized in the request's serialization format.com.google.protobuf.BytesValue
toBytesValue(Binary binary)
Convert theBinary
serialized in the cache's serialization format to aBytesValue
serialized in the request's serialization format.com.oracle.coherence.grpc.Entry
toEntry(Binary binKey, Binary binValue)
com.oracle.coherence.grpc.EntryResult
toEntryResult(Map.Entry<Binary,Binary> entry)
com.oracle.coherence.grpc.OptionalValue
toOptionalValue(Binary binary)
-
-
-
Field Detail
-
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_serializer
protected final Serializer f_serializer
TheSerializer
used by the request.
-
m_result
protected Object m_result
A result value.
-
-
Constructor Detail
-
RequestHolder
public RequestHolder(Req request, String sFormat, Serializer serializer, Service service, Executor executor)
Create aRequestHolder
.- Parameters:
request
- the cache requestsFormat
- the name of the serializer used to serialize the request payloadsserializer
- theSerializer
used by the requestexecutor
- the executor for asynchronous processing
-
-
Method Detail
-
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'sSerializer
.- Returns:
- the cache's
Serializer
-
getDeserializedResult
public <T> T getDeserializedResult()
Obtain the holder's deserialized result value, assuming that the result value is a serializedBinary
.- 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 specifiedBinary
using the cache's serializer.- Type Parameters:
T
- the deserialized type- Parameters:
binary
- theBinary
of the serialized object- Returns:
- the deserialized value
-
deserialize
public <T> T deserialize(Binary binary)
Obtain the deserializedBinary
value using the cache's serializer.
-
deserializeRequest
public <T> T deserializeRequest(com.google.protobuf.ByteString bytes)
Obtain the deserializedByteString
value using the request's serializer.- Type Parameters:
T
- the deserialized type- Parameters:
bytes
- theByteString
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'sSerializer
.- Returns:
- the request's
Serializer
-
convertDown
public Binary convertDown(Supplier<com.google.protobuf.ByteString> supplier)
Convert theByteString
data serialized in the request format to aBinary
serialized in the cache's serialization format.- Parameters:
supplier
- the supplier of theByteString
to convert- Returns:
- a
Binary
in the cache's serialization format
-
convertDown
public Binary convertDown(com.google.protobuf.ByteString bytes)
Convert theByteString
data serialized in the request format to aBinary
serialized in the cache's serialization format.- Parameters:
bytes
- theByteString
to convert- Returns:
- a
Binary
in the cache's serialization format
-
deserializeToBytesValue
public com.google.protobuf.BytesValue deserializeToBytesValue(Binary binary)
Convert theBinary
serialized in the cache's serialization format to aBytesValue
serialized in the request's serialization format.The assumption is that the
Binary
deserializes to anotherBinary
.- Parameters:
binary
- theBinary
to convert- Returns:
- a
BytesValue
in the request's serialization format
-
toBytesValue
public com.google.protobuf.BytesValue toBytesValue(Binary binary)
Convert theBinary
serialized in the cache's serialization format to aBytesValue
serialized in the request's serialization format.- Parameters:
binary
- theBinary
to convert- Returns:
- a
BytesValue
in the request's serialization format
-
toByteString
public com.google.protobuf.ByteString toByteString(Binary binary)
Convert theBinary
serialized in the cache's serialization format to aByteString
serialized in the request's serialization format.- Parameters:
binary
- theBinary
to convert- Returns:
- a
ByteString
in the request's serialization format
-
toEntryResult
public com.oracle.coherence.grpc.EntryResult toEntryResult(Map.Entry<Binary,Binary> entry)
Convert aMap.Entry
ofBinary
key and value serialized in the cache's serialization format into anEntryResult
with a key and value serialized in the request's serialization format.- Parameters:
entry
- theBinary
to convert- Returns:
- a
EntryResult
in the request's serialization format
-
toOptionalValue
public com.oracle.coherence.grpc.OptionalValue toOptionalValue(Binary binary)
Convert aBinary
serialized with the cache's serializer to anOptionalValue
containing an optionalBinary
serialized with the request's serializer.- Parameters:
binary
- the optionalBinary
value- Returns:
- a
OptionalValue
in the request's serialization format
-
ensureConverterDown
public Converter<Binary,Binary> ensureConverterDown()
Obtain theConverter
used to convert between the request format and the cache format; creating theConverter
if required.- Returns:
- the
Converter
used to convert between the request format and the cache format
-
getCacheFormat
public static String getCacheFormat(Service service)
Returns the serializer format name for the specifiedService
's serializer.
-
-