Class BaseNamedCacheServiceImpl

java.lang.Object
com.oracle.coherence.grpc.proxy.common.BaseGrpcServiceImpl
com.oracle.coherence.grpc.proxy.common.BaseNamedCacheServiceImpl
All Implemented Interfaces:
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
  • Field Details

  • Constructor Details

  • Method Details

    • addIndex

      protected com.google.protobuf.Empty addIndex(CacheRequestHolder<com.oracle.coherence.grpc.AddIndexRequest,Void> holder)
      Execute the AddIndexRequest request.
      Parameters:
      holder - the CacheRequestHolder containing the AddIndexRequest request
      Returns:
      BinaryHelper.EMPTY
    • aggregateWithFilter

      protected CompletionStage<com.google.protobuf.BytesValue> aggregateWithFilter(com.oracle.coherence.grpc.AggregateRequest request, Executor executor)
      Execute the filtered AggregateRequest request.
      Parameters:
      request - the AggregateRequest
      Returns:
      a CompletionStage that completes with a CacheRequestHolder containing the serialized result of executing request
    • aggregateWithFilter

      protected CompletionStage<com.google.protobuf.BytesValue> aggregateWithFilter(CacheRequestHolder<com.oracle.coherence.grpc.AggregateRequest,Void> holder, Executor executor)
      Execute the filtered AggregateRequest request.
      Parameters:
      holder - the CacheRequestHolder containing the ContainsEntryRequest request
      Returns:
      a CompletionStage that completes with a CacheRequestHolder containing the serialized result of executing request
    • aggregateWithKeys

      protected CompletionStage<com.google.protobuf.BytesValue> aggregateWithKeys(com.oracle.coherence.grpc.AggregateRequest request, Executor executor)
      Execute the key-based AggregateRequest request.
      Parameters:
      request - the AggregateRequest
      Returns:
      a CompletionStage that completes with a CacheRequestHolder containing the serialized result of executing request
    • aggregateWithKeys

      protected CompletionStage<com.google.protobuf.BytesValue> aggregateWithKeys(CacheRequestHolder<com.oracle.coherence.grpc.AggregateRequest,Void> holder, Executor executor)
      Execute the filtered AggregateRequest request.
      Parameters:
      holder - the CacheRequestHolder containing the ContainsEntryRequest request
      Returns:
      a CompletionStage that completes with a CacheRequestHolder containing the serialized result of executing request
    • clear

      public void clear(com.oracle.coherence.grpc.ClearRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> observer)
      Description copied from interface: NamedCacheService
      Clear a cache.
      Specified by:
      clear in interface NamedCacheService
      Parameters:
      request - the ClearRequest to execute
      observer - the StreamObserver to receive the response
      See Also:
    • destroy

      public void destroy(com.oracle.coherence.grpc.DestroyRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> observer)
      Description copied from interface: NamedCacheService
      Destroy a cache.
      Specified by:
      destroy in interface NamedCacheService
      Parameters:
      request - the DestroyRequest containing the name of the cache to destroy
      observer - the StreamObserver to receive the response
    • events

      public io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.MapListenerRequest> events(io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.MapListenerResponse> observer)
      Description copied from interface: NamedCacheService
      Add a MapListener to a cache and stream the events received to the StreamObserver.
      Specified by:
      events in interface NamedCacheService
      Parameters:
      observer - the StreamObserver 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.GetAllRequest,Void> holder)
      Convert the keys for a GetAllRequest from the request's serialization format to the cache's serialization format.
      Parameters:
      holder - the CacheRequestHolder containing the GetAllRequest 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.PutAllRequest,Void> holder, Map<Binary,Binary> map)
      Perform a putAll 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 - the CacheRequestHolder containing the PutAllRequest request
      map - the map of Binary 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 a putAll operation on a partitioned cache.
      Parameters:
      cache - the AsyncNamedCache to update
      map - the map of Binary keys and values to put into the cache
      cMillis - the expiry delay to set on the entries
      Returns:
      a CompletionStage that completes when the putAll operation completes
    • removeIndex

      protected com.google.protobuf.Empty removeIndex(CacheRequestHolder<com.oracle.coherence.grpc.RemoveIndexRequest,Void> holder)
      Execute the RemoveIndexRequest request.
      Parameters:
      holder - the CacheRequestHolder containing the RemoveIndexRequest request
      Returns:
      BinaryHelper.EMPTY
    • empty

      protected <V> com.google.protobuf.Empty empty(V ignored)
      A helper method that always returns Empty.

      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

      protected com.google.protobuf.Empty execute(Runnable task)
      Execute the Runnable and return an Empty instance.
      Parameters:
      task - the runnable to execute
      Returns:
      always returns an Empty instance
    • execute

      protected <T> T execute(Callable<T> task)
      Execute the Callable and return the result.
      Type Parameters:
      T - the result type
      Parameters:
      task - the runnable to execute
      Returns:
      the result of executing the Callable
    • toBoolValue

      protected com.google.protobuf.BoolValue toBoolValue(Binary binary, Serializer serializer)
      Deserialize a Binary to a boolean value.
      Parameters:
      binary - the Binary to deserialize
      serializer - the Serializer to use
      Returns:
      the deserialized boolean value
    • ensureValueExtractor

      public ValueExtractor<?,?> ensureValueExtractor(com.google.protobuf.ByteString bytes, Serializer serializer)
      Obtain a ValueExtractor from the serialized data in a ByteString.
      Parameters:
      bytes - the ByteString containing the serialized ValueExtractor
      serializer - the serializer to use
      Returns:
      a deserialized ValueExtractor
      Throws:
      io.grpc.StatusRuntimeException - if the ByteString is null or empty
    • ensureFilter

      public <T> Filter<T> ensureFilter(com.google.protobuf.ByteString bytes, Serializer serializer)
      Obtain a Filter from the serialized data in a ByteString.

      If the ByteString is null or ByteString.EMPTY then an AlwaysFilter is returned.

      Specified by:
      ensureFilter in interface NamedCacheService
      Type Parameters:
      T - the Filter type
      Parameters:
      bytes - the ByteString containing the serialized Filter
      serializer - the serializer to use
      Returns:
      a deserialized Filter
    • getFilter

      public <T> Filter<T> getFilter(com.google.protobuf.ByteString bytes, Serializer serializer)
      Obtain a Filter from the serialized data in a ByteString.
      Specified by:
      getFilter in interface NamedCacheService
      Type Parameters:
      T - the Filter type
      Parameters:
      bytes - the ByteString containing the serialized Filter
      serializer - the serializer to use
      Returns:
      a deserialized Filter or null if no filter is set
    • deserializeComparator

      public <T> Comparator<T> deserializeComparator(com.google.protobuf.ByteString bytes, Serializer serializer)
      Obtain a Comparator from the serialized data in a ByteString.
      Type Parameters:
      T - the Comparator type
      Parameters:
      bytes - the ByteString containing the serialized Comparator
      serializer - the serializer to use
      Returns:
      a deserialized Comparator or null if the ByteString is null or ByteString.EMPTY
    • getAsyncCache

      protected CompletionStage<AsyncNamedCache<Binary,Binary>> getAsyncCache(String scope, String cacheName)
      Obtain an AsyncNamedCache.
      Parameters:
      scope - the scope name to use to obtain the CCF to get the cache from
      cacheName - the name of the cache
      Returns:
      the AsyncNamedCache with the specified name
    • getPassThroughCache

      protected NamedCache<Binary,Binary> getPassThroughCache(String scope, String cacheName)
      Obtain an NamedCache.
      Parameters:
      scope - the scope name to use to obtain the CCF to get the cache from
      cacheName - the name of the cache
      Returns:
      the NamedCache with the specified name
    • getCCF

      protected ConfigurableCacheFactory getCCF(String sScope)
    • getCache

      protected NamedCache<Binary,Binary> getCache(String sScope, String sCacheName, boolean fPassThru)
      Obtain an NamedCache.
      Parameters:
      sScope - the scope name to use to obtain the CCF to get the cache from
      sCacheName - the name of the cache
      fPassThru - true to use a binary pass-thru cache
      Returns:
      the NamedCache with the specified name
    • castProcessor

      Parameters:
      ep - the InvocableMap.EntryProcessor to cast
      Returns:
      a InvocableMap.EntryProcessor that returns a Binary result
    • createHolderAsync

      public <Req> CompletionStage<CacheRequestHolder<Req,Void>> createHolderAsync(Req request, String sScope, String sCacheName, String format)
      Asynchronously create a CacheRequestHolder for a given request.
      Type Parameters:
      Req - the type of the request
      Parameters:
      request - the request object to add to the holder
      sScope - the scope name to use to identify the CCF to obtain the cache from
      sCacheName - the name of the cache that the request executes against
      format - the optional serialization format used by requests that contain a payload
      Returns:
      a CompletionStage that completes when the CacheRequestHolder has been created
    • createRequestHolder

      public <Req> CacheRequestHolder<Req,Void> createRequestHolder(Req request, String sScope, String sCacheName, String format)
      Create a CacheRequestHolder for a given request.
      Specified by:
      createRequestHolder in interface NamedCacheService
      Type Parameters:
      Req - the type of the request
      Parameters:
      request - the request object to add to the holder
      sScope - the scope name to use to identify the CCF to obtain the cache from
      sCacheName - the name of the cache that the request executes against
      format - the optional serialization format used by requests that contain a payload
      Returns:
      the CacheRequestHolder holding the request