Class BaseNamedCacheServiceImpl
java.lang.Object
com.oracle.coherence.grpc.proxy.common.BaseGrpcServiceImpl
com.oracle.coherence.grpc.proxy.common.v0.BaseNamedCacheServiceImpl
- All Implemented Interfaces:
GrpcService
,GrpcProxyService
,NamedCacheService
- Direct Known Subclasses:
HelidonNamedCacheService
,NettyNamedCacheService
public abstract class BaseNamedCacheServiceImpl
extends BaseGrpcServiceImpl
implements NamedCacheService
A base class for gRPC
NamedCacheService
implementations.- Author:
- Jonathan Knight 2024.02.08
-
Nested Class Summary
Nested classes/interfaces inherited from class com.oracle.coherence.grpc.proxy.common.BaseGrpcServiceImpl
BaseGrpcServiceImpl.DefaultDependencies, BaseGrpcServiceImpl.Dependencies
Nested classes/interfaces inherited from interface com.oracle.coherence.grpc.proxy.common.v0.NamedCacheService
NamedCacheService.DefaultDependencies, NamedCacheService.Dependencies
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
The name to use for the management MBean.static final String
static final String
static final String
Fields inherited from class com.oracle.coherence.grpc.proxy.common.BaseGrpcServiceImpl
DEFAULT_TRANSFER_THRESHOLD, f_cacheFactorySupplier, f_dependencies, f_executor, f_metrics, f_serializerProducer, INVALID_CACHE_NAME_MESSAGE, transferThreshold, VOID
-
Constructor Summary
ConstructorsConstructorDescriptionBaseNamedCacheServiceImpl
(NamedCacheService.Dependencies dependencies) Create aBaseNamedCacheServiceImpl
. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.google.protobuf.Empty
addIndex
(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.AddIndexRequest, Void> holder) Execute theAddIndexRequest
request.protected CompletionStage
<com.google.protobuf.BytesValue> aggregateWithFilter
(com.oracle.coherence.grpc.messages.cache.v0.AggregateRequest request, Executor executor) Execute the filteredAggregateRequest
request.protected CompletionStage
<com.google.protobuf.BytesValue> aggregateWithFilter
(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.AggregateRequest, Void> holder, Executor executor) Execute the filteredAggregateRequest
request.protected CompletionStage
<com.google.protobuf.BytesValue> aggregateWithKeys
(com.oracle.coherence.grpc.messages.cache.v0.AggregateRequest request, Executor executor) Execute the key-basedAggregateRequest
request.protected CompletionStage
<com.google.protobuf.BytesValue> aggregateWithKeys
(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.AggregateRequest, Void> holder, Executor executor) Execute the filteredAggregateRequest
request.protected InvocableMap.EntryProcessor
<Binary, Binary, Binary> void
clear
(com.oracle.coherence.grpc.messages.cache.v0.ClearRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> observer) Clear a cache.convertKeysToBinary
(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.GetAllRequest, Void> holder) Convert the keys for aGetAllRequest
from the request's serialization format to the cache's serialization format.<Req> CompletionStage
<CacheRequestHolder<Req, Void>> createHolderAsync
(Req request, String sScope, String sCacheName, String format) Asynchronously create aCacheRequestHolder
for a given request.<Req> CacheRequestHolder
<Req, Void> createRequestHolder
(Req request, String sScope, String sCacheName, String format) Create aCacheRequestHolder
for a given request.<T> Comparator
<T> deserializeComparator
(com.google.protobuf.ByteString bytes, Serializer serializer) Obtain aComparator
from the serialized data in aByteString
.void
destroy
(com.oracle.coherence.grpc.messages.cache.v0.DestroyRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> observer) Destroy a cache.protected <V> com.google.protobuf.Empty
empty
(V ignored) A helper method that always returnsEmpty
.<T> Filter
<T> ensureFilter
(com.google.protobuf.ByteString bytes, Serializer serializer) Obtain aFilter
from the serialized data in aByteString
.ValueExtractor
<?, ?> ensureValueExtractor
(com.google.protobuf.ByteString bytes, Serializer serializer) Obtain aValueExtractor
from the serialized data in aByteString
.io.grpc.stub.StreamObserver
<com.oracle.coherence.grpc.messages.cache.v0.MapListenerRequest> events
(io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.messages.cache.v0.MapListenerResponse> observer) Add aMapListener
to a cache and stream the events received to theStreamObserver
.protected com.google.protobuf.Empty
Execute theRunnable
and return anEmpty
instance.protected <T> T
Execute theCallable
and return the result.protected CompletionStage
<AsyncNamedCache<Binary, Binary>> getAsyncCache
(String scope, String cacheName) Obtain anAsyncNamedCache
.<T> Filter
<T> getFilter
(com.google.protobuf.ByteString bytes, Serializer serializer) Obtain aFilter
from the serialized data in aByteString
.protected CompletionStage
<com.google.protobuf.Empty> partitionedPutAll
(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.PutAllRequest, Void> holder, Map<Binary, Binary> map) Perform aputAll
operation on a partitioned cache.protected CompletionStage
<com.google.protobuf.Empty> plainPutAll
(AsyncNamedCache<Binary, Binary> cache, Map<Binary, Binary> map, long cMillis) Perform aputAll
operation on a partitioned cache.protected com.google.protobuf.Empty
removeIndex
(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.RemoveIndexRequest, Void> holder) Execute theRemoveIndexRequest
request.protected com.google.protobuf.BoolValue
toBoolValue
(Binary binary, Serializer serializer) Deserialize aBinary
to a boolean value.Methods inherited from class com.oracle.coherence.grpc.proxy.common.BaseGrpcServiceImpl
createDefaultExecutor, getCache, getCCF, getDependencies, getExecutor, getMetrics, getPassThroughCache, getSerializer, getSerializer, getTransferThreshold
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.oracle.coherence.grpc.proxy.common.GrpcProxyService
getMetrics
Methods inherited from interface com.oracle.coherence.grpc.proxy.common.v0.NamedCacheService
addIndex, aggregate, containsEntry, containsKey, containsValue, entrySet, get, getAll, invoke, invokeAll, isEmpty, isReady, keySet, nextEntrySetPage, nextKeySetPage, put, putAll, putIfAbsent, remove, removeIndex, removeMapping, replace, replaceMapping, size, truncate, values
-
Field Details
-
MBEAN_NAME
The name to use for the management MBean.- See Also:
-
INVALID_REQUEST_MESSAGE
- See Also:
-
MISSING_PROCESSOR_MESSAGE
- See Also:
-
MISSING_EXTRACTOR_MESSAGE
- See Also:
-
MISSING_AGGREGATOR_MESSAGE
- See Also:
-
-
Constructor Details
-
BaseNamedCacheServiceImpl
Create aBaseNamedCacheServiceImpl
.- Parameters:
dependencies
- theNamedCacheService.Dependencies
to use to configure the service
-
-
Method Details
-
addIndex
protected com.google.protobuf.Empty addIndex(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.AddIndexRequest, Void> holder) Execute theAddIndexRequest
request.- Parameters:
holder
- theCacheRequestHolder
containing theAddIndexRequest
request- Returns:
BinaryHelper.EMPTY
-
aggregateWithFilter
protected CompletionStage<com.google.protobuf.BytesValue> aggregateWithFilter(com.oracle.coherence.grpc.messages.cache.v0.AggregateRequest request, Executor executor) Execute the filteredAggregateRequest
request.- Parameters:
request
- theAggregateRequest
- Returns:
- a
CompletionStage
that completes with aCacheRequestHolder
containing the serialized result of executing request
-
aggregateWithFilter
protected CompletionStage<com.google.protobuf.BytesValue> aggregateWithFilter(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.AggregateRequest, Void> holder, Executor executor) Execute the filteredAggregateRequest
request.- Parameters:
holder
- theCacheRequestHolder
containing theContainsEntryRequest
request- Returns:
- a
CompletionStage
that completes with aCacheRequestHolder
containing the serialized result of executing request
-
aggregateWithKeys
protected CompletionStage<com.google.protobuf.BytesValue> aggregateWithKeys(com.oracle.coherence.grpc.messages.cache.v0.AggregateRequest request, Executor executor) Execute the key-basedAggregateRequest
request.- Parameters:
request
- theAggregateRequest
- Returns:
- a
CompletionStage
that completes with aCacheRequestHolder
containing the serialized result of executing request
-
aggregateWithKeys
protected CompletionStage<com.google.protobuf.BytesValue> aggregateWithKeys(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.AggregateRequest, Void> holder, Executor executor) Execute the filteredAggregateRequest
request.- Parameters:
holder
- theCacheRequestHolder
containing theContainsEntryRequest
request- Returns:
- a
CompletionStage
that completes with aCacheRequestHolder
containing the serialized result of executing request
-
clear
public void clear(com.oracle.coherence.grpc.messages.cache.v0.ClearRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> observer) Description copied from interface:NamedCacheService
Clear a cache.- Specified by:
clear
in interfaceNamedCacheService
- Parameters:
request
- theClearRequest
to executeobserver
- theStreamObserver
to receive the response- See Also:
-
destroy
public void destroy(com.oracle.coherence.grpc.messages.cache.v0.DestroyRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> observer) Description copied from interface:NamedCacheService
Destroy a cache.- Specified by:
destroy
in interfaceNamedCacheService
- Parameters:
request
- theDestroyRequest
containing the name of the cache to destroyobserver
- theStreamObserver
to receive the response
-
events
public io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.messages.cache.v0.MapListenerRequest> events(io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.messages.cache.v0.MapListenerResponse> observer) Description copied from interface:NamedCacheService
Add aMapListener
to a cache and stream the events received to theStreamObserver
.- Specified by:
events
in interfaceNamedCacheService
- Parameters:
observer
- theStreamObserver
to receive events- Returns:
- a
StreamObserver
that will be closed by the client to end event subscription
-
convertKeysToBinary
protected List<Binary> convertKeysToBinary(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.GetAllRequest, Void> holder) Convert the keys for aGetAllRequest
from the request's serialization format to the cache's serialization format.- Parameters:
holder
- theCacheRequestHolder
containing theGetAllRequest
containing the keys to convert- Returns:
- A
CompletionStage
that completes with the converted keys
-
partitionedPutAll
protected CompletionStage<com.google.protobuf.Empty> partitionedPutAll(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.PutAllRequest, Void> holder, Map<Binary, Binary> map) Perform aputAll
operation on a partitioned cache.This method will split the map of entries into a map per storage member and execute the putAll invocation for each member separately. This is more efficient than sending the map of entries to all members.
- Parameters:
holder
- theCacheRequestHolder
containing thePutAllRequest
requestmap
- the map ofBinary
keys and values to put into the cache- Returns:
- a
CompletionStage
that completes when the putAll operation completes
-
plainPutAll
protected CompletionStage<com.google.protobuf.Empty> plainPutAll(AsyncNamedCache<Binary, Binary> cache, Map<Binary, Binary> map, long cMillis) Perform aputAll
operation on a partitioned cache.- Parameters:
cache
- theAsyncNamedCache
to updatemap
- the map ofBinary
keys and values to put into the cachecMillis
- the expiry delay to set on the entries- Returns:
- a
CompletionStage
that completes when theputAll
operation completes
-
removeIndex
protected com.google.protobuf.Empty removeIndex(CacheRequestHolder<com.oracle.coherence.grpc.messages.cache.v0.RemoveIndexRequest, Void> holder) Execute theRemoveIndexRequest
request.- Parameters:
holder
- theCacheRequestHolder
containing theRemoveIndexRequest
request- Returns:
BinaryHelper.EMPTY
-
empty
protected <V> com.google.protobuf.Empty empty(V ignored) A helper method that always returnsEmpty
.This method is to make
CompletionStage
handler code a little more elegant as it can use this method as a method reference.- Type Parameters:
V
- the type of the value- Parameters:
ignored
- the value- Returns:
- an
Empty
instance.
-
execute
Execute theRunnable
and return anEmpty
instance.- Parameters:
task
- the runnable to execute- Returns:
- always returns an
Empty
instance
-
execute
Execute theCallable
and return the result.- Type Parameters:
T
- the result type- Parameters:
task
- the runnable to execute- Returns:
- the result of executing the
Callable
-
toBoolValue
Deserialize aBinary
to a boolean value.- Parameters:
binary
- theBinary
to deserializeserializer
- theSerializer
to use- Returns:
- the deserialized boolean value
-
ensureValueExtractor
public ValueExtractor<?,?> ensureValueExtractor(com.google.protobuf.ByteString bytes, Serializer serializer) Obtain aValueExtractor
from the serialized data in aByteString
.- Parameters:
bytes
- theByteString
containing the serializedValueExtractor
serializer
- the serializer to use- Returns:
- a deserialized
ValueExtractor
- Throws:
io.grpc.StatusRuntimeException
- if theByteString
is null or empty
-
ensureFilter
Obtain aFilter
from the serialized data in aByteString
.If the
ByteString
isnull
orByteString.EMPTY
then anAlwaysFilter
is returned.- Specified by:
ensureFilter
in interfaceNamedCacheService
- Type Parameters:
T
- theFilter
type- Parameters:
bytes
- theByteString
containing the serializedFilter
serializer
- the serializer to use- Returns:
- a deserialized
Filter
-
getFilter
Obtain aFilter
from the serialized data in aByteString
.- Specified by:
getFilter
in interfaceNamedCacheService
- Type Parameters:
T
- theFilter
type- Parameters:
bytes
- theByteString
containing the serializedFilter
serializer
- the serializer to use- Returns:
- a deserialized
Filter
ornull
if no filter is set
-
deserializeComparator
public <T> Comparator<T> deserializeComparator(com.google.protobuf.ByteString bytes, Serializer serializer) Obtain aComparator
from the serialized data in aByteString
.- Type Parameters:
T
- theComparator
type- Parameters:
bytes
- theByteString
containing the serializedComparator
serializer
- the serializer to use- Returns:
- a deserialized
Comparator
ornull
if theByteString
isnull
orByteString.EMPTY
-
getAsyncCache
protected CompletionStage<AsyncNamedCache<Binary,Binary>> getAsyncCache(String scope, String cacheName) Obtain anAsyncNamedCache
.- Parameters:
scope
- the scope name to use to obtain the CCF to get the cache fromcacheName
- the name of the cache- Returns:
- the
AsyncNamedCache
with the specified name
-
castProcessor
protected InvocableMap.EntryProcessor<Binary,Binary, castProcessorBinary> (InvocableMap.EntryProcessor<Binary, Binary, ?> ep) - Parameters:
ep
- theInvocableMap.EntryProcessor
to cast- Returns:
- a
InvocableMap.EntryProcessor
that returns aBinary
result
-
createHolderAsync
public <Req> CompletionStage<CacheRequestHolder<Req,Void>> createHolderAsync(Req request, String sScope, String sCacheName, String format) Asynchronously create aCacheRequestHolder
for a given request.- Type Parameters:
Req
- the type of the request- Parameters:
request
- the request object to add to the holdersScope
- the scope name to use to identify the CCF to obtain the cache fromsCacheName
- the name of the cache that the request executes againstformat
- the optional serialization format used by requests that contain a payload- Returns:
- a
CompletionStage
that completes when theCacheRequestHolder
has been created
-
createRequestHolder
public <Req> CacheRequestHolder<Req,Void> createRequestHolder(Req request, String sScope, String sCacheName, String format) Create aCacheRequestHolder
for a given request.- Specified by:
createRequestHolder
in interfaceNamedCacheService
- Type Parameters:
Req
- the type of the request- Parameters:
request
- the request object to add to the holdersScope
- the scope name to use to identify the CCF to obtain the cache fromsCacheName
- the name of the cache that the request executes againstformat
- the optional serialization format used by requests that contain a payload- Returns:
- the
CacheRequestHolder
holding the request
-