Class NettyNamedCacheService

All Implemented Interfaces:
GrpcProxyService, NamedCacheService

public class NettyNamedCacheService extends BaseNamedCacheServiceImpl implements NamedCacheService
An async gRPC NamedCacheService.

This class uses AsyncNamedCache and asynchronous CompletionStage wherever possible. This makes the code more complex but the advantages of not blocking the gRPC request thread or the Coherence service thread will outweigh the downside of complexity.

The asynchronous processing of CompletionStages is done using an DaemonPoolExecutor so as not to consume or block threads in the Fork Join Pool. The DaemonPoolExecutor is configurable so that its thread counts can be controlled.

Since:
20.06
Author:
Jonathan Knight 2020.09.22
  • Constructor Details

  • Method Details

    • newInstance

      public static NettyNamedCacheService newInstance(NamedCacheService.Dependencies deps)
      Create an instance of NettyNamedCacheService using the default dependencies configuration.
      Parameters:
      deps - the NamedCacheService.Dependencies to use to create the service
      Returns:
      an instance of NettyNamedCacheService
    • newInstance

      public static NettyNamedCacheService newInstance()
      Create an instance of NettyNamedCacheService using the default dependencies configuration.
      Returns:
      an instance of NettyNamedCacheService
    • addIndex

      public void addIndex(com.oracle.coherence.grpc.AddIndexRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> observer)
      Description copied from interface: NamedCacheService
      Add an index to a cache.
      Specified by:
      addIndex in interface NamedCacheService
      Parameters:
      request - the AddIndexRequest containing the name of the cache to add the index to, the serialized ValueExtractor to use to create the index and the optional serialized Comparator to sort the index
      observer - the StreamObserver to receive the response
    • aggregate

      public void aggregate(com.oracle.coherence.grpc.AggregateRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Description copied from interface: NamedCacheService
      Execute an AggregateRequest against a cache and return the result serialized in a BytesValue.
      Specified by:
      aggregate in interface NamedCacheService
      Parameters:
      request - the AggregateRequest to execute
      observer - the StreamObserver to receive the response
    • containsEntry

      public void containsEntry(com.oracle.coherence.grpc.ContainsEntryRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BoolValue> observer)
      Description copied from interface: NamedCacheService
      Returns true if this map contains a mapping for the specified key to the specified value.
      Specified by:
      containsEntry in interface NamedCacheService
      Parameters:
      request - the request which contains the key and value whose presence in this map is to be tested
      observer - the StreamObserver to receive the response
      See Also:
    • containsEntry

      protected CompletionStage<CacheRequestHolder<com.oracle.coherence.grpc.ContainsEntryRequest,Binary>> containsEntry(CacheRequestHolder<com.oracle.coherence.grpc.ContainsEntryRequest,Void> holder)
      Execute the ContainsEntryRequest request and return a CompletionStage that will complete when the AsyncNamedCache request completes and will contain a CacheRequestHolder holding the result of the contains entry request as a serialized Boolean.
      Parameters:
      holder - the CacheRequestHolder containing the ContainsEntryRequest request
      Returns:
      a CompletionStage that completes with a CacheRequestHolder containing the serialized Boolean result of executing the ContainsEntryRequest request
    • containsKey

      public void containsKey(com.oracle.coherence.grpc.ContainsKeyRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BoolValue> observer)
      Description copied from interface: NamedCacheService
      Returns true if this map contains a mapping for the specified key.
      Specified by:
      containsKey in interface NamedCacheService
      Parameters:
      request - the request which contains the key whose presence in this map is to be tested
      observer - the StreamObserver to receive the response
      See Also:
    • containsKey

      protected CompletionStage<CacheRequestHolder<com.oracle.coherence.grpc.ContainsKeyRequest,Boolean>> containsKey(CacheRequestHolder<com.oracle.coherence.grpc.ContainsKeyRequest,Void> holder)
      Execute the ContainsKeyRequest request and return a CompletionStage that will complete when the AsyncNamedCache request completes and will contain a CacheRequestHolder holding the result of the contains key request.
      Parameters:
      holder - the CacheRequestHolder containing the ContainsKeyRequest request
      Returns:
      a CompletionStage that completes with a CacheRequestHolder containing the Boolean result of executing the ContainsKeyRequest request
    • containsValue

      public void containsValue(com.oracle.coherence.grpc.ContainsValueRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BoolValue> observer)
      Description copied from interface: NamedCacheService
      Returns true if this map contains a mapping for the specified value.
      Specified by:
      containsValue in interface NamedCacheService
      Parameters:
      request - the request which contains the value whose presence in this map is to be tested
      observer - the StreamObserver to receive the response
      See Also:
    • containsValue

      protected CompletionStage<CacheRequestHolder<com.oracle.coherence.grpc.ContainsValueRequest,Integer>> containsValue(CacheRequestHolder<com.oracle.coherence.grpc.ContainsValueRequest,Void> holder)
      Execute the ContainsValueRequest request and return a CompletionStage that will complete when the AsyncNamedCache request completes and will contain a CacheRequestHolder holding the result of the contains value request as a serialized Boolean.
      Parameters:
      holder - the CacheRequestHolder containing the ContainsValueRequest request
      Returns:
      a CompletionStage that completes with a CacheRequestHolder containing the serialized Boolean result of executing the ContainsValueRequest request
    • entrySet

      public void entrySet(com.oracle.coherence.grpc.EntrySetRequest request, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Description copied from interface: NamedCacheService
      Stream a set of cache entries to a StreamObserver.
      Specified by:
      entrySet in interface NamedCacheService
      Parameters:
      request - the EntrySetRequest to execute
      observer - the StreamObserver to stream the entries to
      See Also:
    • entrySet

      protected Void entrySet(CacheRequestHolder<com.oracle.coherence.grpc.EntrySetRequest,Void> holder, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Execute the EntrySetRequest request and send the results to the StreamObserver.
      Parameters:
      holder - the CacheRequestHolder containing the EntrySetRequest request
      observer - the StreamObserver which will receive results
      Returns:
      always return Void
    • get

      public void get(com.oracle.coherence.grpc.GetRequest request, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.OptionalValue> observer)
      Description copied from interface: NamedCacheService
      Get a value for a given key from a cache.
      Specified by:
      get in interface NamedCacheService
      Parameters:
      request - the GetRequest to execute
      observer - the StreamObserver to receive events
      See Also:
    • get

      protected CompletionStage<CacheRequestHolder<com.oracle.coherence.grpc.GetRequest,Binary>> get(CacheRequestHolder<com.oracle.coherence.grpc.GetRequest,Void> holder)
      Execute the GetRequest request and return a CompletionStage that will complete when the AsyncNamedCache request completes and will contain a CacheRequestHolder holding the result of the GetRequest request as a serialized Boolean.
      Parameters:
      holder - the CacheRequestHolder containing the GetRequest request
      Returns:
      a CompletionStage that completes with a CacheRequestHolder containing the serialized Binary result of executing the GetRequest request
    • getAll

      public void getAll(com.oracle.coherence.grpc.GetAllRequest request, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Description copied from interface: NamedCacheService
      Obtain a stream of mappings of keys to values for all the specified keys.
      Specified by:
      getAll in interface NamedCacheService
      Parameters:
      request - the GetAllRequest request containing the cache name and collection of keys to obtain the mappings for
      observer - the StreamObserver to stream the results back to
    • getAll

      protected Void getAll(CacheRequestHolder<com.oracle.coherence.grpc.GetAllRequest,Void> holder, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Execute the GetAllRequest request and send the results to the StreamObserver.
      Parameters:
      holder - the CacheRequestHolder containing the GetAllRequest request
      observer - the StreamObserver which will receive results
      Returns:
      always return Void
    • invoke

      public void invoke(com.oracle.coherence.grpc.InvokeRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Description copied from interface: NamedCacheService
      Invoke an InvocableMap.EntryProcessor against an entry in a cache.
      Specified by:
      invoke in interface NamedCacheService
      Parameters:
      request - the InvokeRequest containing the serialized key of the entry and the serialized InvocableMap.EntryProcessor
      observer - the StreamObserver to stream the results back to
    • invoke

      protected CompletionStage<CacheRequestHolder<com.oracle.coherence.grpc.InvokeRequest,Binary>> invoke(CacheRequestHolder<com.oracle.coherence.grpc.InvokeRequest,Void> holder)
      Execute the InvokeRequest request and return a CompletionStage that will complete when the AsyncNamedCache request completes and will contain a CacheRequestHolder holding the result of the InvokeRequest request as a serialized Boolean.
      Parameters:
      holder - the CacheRequestHolder containing the InvokeRequest request
      Returns:
      a CompletionStage that completes with a CacheRequestHolder containing the serialized Binary result of executing the InvokeRequest request
    • invokeAll

      public void invokeAll(com.oracle.coherence.grpc.InvokeAllRequest request, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Description copied from interface: NamedCacheService
      Invoke an InvocableMap.EntryProcessor against multiple entries in a cache.
      Specified by:
      invokeAll in interface NamedCacheService
      Parameters:
      request - the InvokeRequest containing the serialized keys or serialized Filter to use to identify the entries and the serialized InvocableMap.EntryProcessor
      observer - the StreamObserver to observer the invocation results
    • invokeAllWithFilter

      protected CompletionStage<Void> invokeAllWithFilter(com.oracle.coherence.grpc.InvokeAllRequest request, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Execute the filtered InvokeAllRequest request passing the results to the provided StreamObserver.
      Parameters:
      request - the InvokeAllRequest
      observer - the StreamObserver which will receive the results
      Returns:
      always returns a CompletionStage returning Void
    • invokeAllWithFilter

      protected CompletionStage<Void> invokeAllWithFilter(CacheRequestHolder<com.oracle.coherence.grpc.InvokeAllRequest,Void> holder, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Execute the filtered InvokeAllRequest request passing the results to the provided StreamObserver.
      Parameters:
      holder - the CacheRequestHolder containing the InvokeAllRequest
      observer - the StreamObserver which will receive the results
      Returns:
      always returns a CompletionStage returning Void
    • invokeAllWithKeys

      protected CompletionStage<Void> invokeAllWithKeys(com.oracle.coherence.grpc.InvokeAllRequest request, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Execute the key-based InvokeAllRequest request passing the results to the provided StreamObserver.
      Parameters:
      request - the InvokeAllRequest
      observer - the StreamObserver which will receive the results
      Returns:
      always returns a CompletionStage returning Void
    • invokeAllWithKeys

      protected CompletionStage<Void> invokeAllWithKeys(CacheRequestHolder<com.oracle.coherence.grpc.InvokeAllRequest,Void> holder, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Execute the key-based InvokeAllRequest request passing the results to the provided StreamObserver.
      Parameters:
      holder - the CacheRequestHolder containing the InvokeAllRequest
      observer - the StreamObserver which will receive the results
      Returns:
      always returns a CompletionStage returning Void
    • isEmpty

      public void isEmpty(com.oracle.coherence.grpc.IsEmptyRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BoolValue> observer)
      Description copied from interface: NamedCacheService
      Determine whether a cache is empty.
      Specified by:
      isEmpty in interface NamedCacheService
      Parameters:
      request - the IsEmptyRequest to execute
      observer - the StreamObserver to observer the invocation results
      See Also:
    • isReady

      public void isReady(com.oracle.coherence.grpc.IsReadyRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BoolValue> observer)
      Description copied from interface: NamedCacheService
      Determine whether a cache is Ready.
      Specified by:
      isReady in interface NamedCacheService
      Parameters:
      request - the IsReadyRequest to execute
      observer - the StreamObserver to observer the invocation results
      See Also:
    • keySet

      public void keySet(com.oracle.coherence.grpc.KeySetRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Description copied from interface: NamedCacheService
      Stream a set of cache keys to a StreamObserver.
      Specified by:
      keySet in interface NamedCacheService
      Parameters:
      request - the KeySetRequest to execute
      observer - the StreamObserver to stream the keys to
      See Also:
    • keySet

      protected Void keySet(CacheRequestHolder<com.oracle.coherence.grpc.KeySetRequest,Void> holder, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Execute the key-based KeySetRequest request passing the results to the provided StreamObserver.
      Parameters:
      holder - the CacheRequestHolder containing the KeySetRequest
      observer - the StreamObserver which will receive the results
      Returns:
      always returns Void
    • nextKeySetPage

      public void nextKeySetPage(com.oracle.coherence.grpc.PageRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Description copied from interface: NamedCacheService
      Obtain the next page of a paged key set request.
      Specified by:
      nextKeySetPage in interface NamedCacheService
      Parameters:
      request - the PageRequest to execute
      observer - the StreamObserver that will receive the responses
    • nextEntrySetPage

      public void nextEntrySetPage(com.oracle.coherence.grpc.PageRequest request, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.EntryResult> observer)
      Description copied from interface: NamedCacheService
      Obtain the next page of a paged entry set request.
      Specified by:
      nextEntrySetPage in interface NamedCacheService
      Parameters:
      request - the PageRequest to execute
      observer - the StreamObserver that will receive the responses
    • put

      public void put(com.oracle.coherence.grpc.PutRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Description copied from interface: NamedCacheService
      Associate the specified value with the specified key in this cache. If the cache previously contained a mapping for the key, the old value is replaced by the specified value.
      Specified by:
      put in interface NamedCacheService
      Parameters:
      request - the PutRequest to execute
      observer - the StreamObserver that will receive the responses
      See Also:
    • put

      protected CompletionStage<com.google.protobuf.BytesValue> put(CacheRequestHolder<com.oracle.coherence.grpc.PutRequest,Void> holder)
      Execute a put request.
      Parameters:
      holder - the CacheRequestHolder containing the PutRequest request
      Returns:
      a CompletionStage that completes with a BytesValue containing the serialized result of executing the PutRequest request
    • putAll

      public void putAll(com.oracle.coherence.grpc.PutAllRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> observer)
      Description copied from interface: NamedCacheService
      Add the specified key value pair mappings to this cache. If the cache previously contained a mappings for the keys, the old value is replaced by the specified value.
      Specified by:
      putAll in interface NamedCacheService
      Parameters:
      request - the PutAllRequest to execute
      observer - the StreamObserver that will receive the responses
      See Also:
    • putAll

      protected CompletionStage<com.google.protobuf.Empty> putAll(CacheRequestHolder<com.oracle.coherence.grpc.PutAllRequest,Void> holder)
      Execute a putAll request.
      Parameters:
      holder - the CacheRequestHolder containing the PutAllRequest request
      Returns:
      a CompletionStage that completes after executing the PutAllRequest request
    • putIfAbsent

      public void putIfAbsent(com.oracle.coherence.grpc.PutIfAbsentRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Description copied from interface: NamedCacheService
      If the specified key is not already associated with a value (or is mapped to null) associate it with the given value and returns null, else return the current value.
      Specified by:
      putIfAbsent in interface NamedCacheService
      Parameters:
      request - the PutIfAbsentRequest to execute
      observer - the StreamObserver that will receive the responses
      See Also:
    • putIfAbsent

      protected CompletableFuture<com.google.protobuf.BytesValue> putIfAbsent(CacheRequestHolder<com.oracle.coherence.grpc.PutIfAbsentRequest,Void> holder)
      Execute a PutIfAbsentRequest request.
      Parameters:
      holder - the CacheRequestHolder containing the PutIfAbsentRequest request
      Returns:
      a CompletionStage that completes with a BytesValue containing the serialized result of executing the PutIfAbsentRequest request
    • remove

      public void remove(com.oracle.coherence.grpc.RemoveRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Description copied from interface: NamedCacheService
      Remove the mapping that is associated with the specified key.
      Specified by:
      remove in interface NamedCacheService
      Parameters:
      request - the RemoveRequest to execute
      observer - the StreamObserver that will receive the responses
      See Also:
    • remove

      protected CompletableFuture<Binary> remove(CacheRequestHolder<com.oracle.coherence.grpc.RemoveRequest,Void> holder)
      Execute a RemoveRequest request.
      Parameters:
      holder - the CacheRequestHolder containing the RemoveRequest request
      Returns:
      a CompletionStage that completes with a Binary containing the serialized result of executing the RemoveRequest request
    • removeIndex

      public void removeIndex(com.oracle.coherence.grpc.RemoveIndexRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> observer)
      Description copied from interface: NamedCacheService
      Remove an index from a cache.
      Specified by:
      removeIndex in interface NamedCacheService
      Parameters:
      request - the RemoveIndexRequest containing the name of the cache to remove the index from, the serialized ValueExtractor that was used to create the index
      observer - the StreamObserver that will receive the responses
    • removeMapping

      public void removeMapping(com.oracle.coherence.grpc.RemoveMappingRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BoolValue> observer)
      Description copied from interface: NamedCacheService
      Remove the mapping that is associated with the specified key only if the mapping exists in the cache.
      Specified by:
      removeMapping in interface NamedCacheService
      Parameters:
      request - the RemoveMappingRequest to execute
      observer - the StreamObserver that will receive the responses
      See Also:
    • removeMapping

      protected CompletionStage<CacheRequestHolder<com.oracle.coherence.grpc.RemoveMappingRequest,Boolean>> removeMapping(CacheRequestHolder<com.oracle.coherence.grpc.RemoveMappingRequest,Void> holder)
      Execute the RemoveMappingRequest request and return a CompletionStage that will complete when the AsyncNamedCache request completes and will contain a CacheRequestHolder holding the result of the RemoveMappingRequest request as a serialized Boolean.
      Parameters:
      holder - the CacheRequestHolder containing the RemoveMappingRequest request
      Returns:
      a CompletionStage that completes with a CacheRequestHolder containing the serialized Binary result of executing the RemoveMappingRequest request
    • replace

      public void replace(com.oracle.coherence.grpc.ReplaceRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Description copied from interface: NamedCacheService
      Replace the entry for the specified key only if it is currently mapped to some value.
      Specified by:
      replace in interface NamedCacheService
      Parameters:
      request - the ReplaceRequest to execute
      observer - the StreamObserver that will receive the responses
      See Also:
    • replace

      protected CompletableFuture<Binary> replace(CacheRequestHolder<com.oracle.coherence.grpc.ReplaceRequest,Void> holder)
      Execute a ReplaceRequest request.
      Parameters:
      holder - the CacheRequestHolder containing the ReplaceRequest request
      Returns:
      a CompletionStage that completes with a Binary containing the serialized result of executing the ReplaceRequest request
    • replaceMapping

      public void replaceMapping(com.oracle.coherence.grpc.ReplaceMappingRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BoolValue> observer)
      Description copied from interface: NamedCacheService
      Replace the mapping for the specified key only if currently mapped to the specified value.
      Specified by:
      replaceMapping in interface NamedCacheService
      Parameters:
      request - the ReplaceMappingRequest to execute
      observer - the StreamObserver that will receive the responses
      See Also:
    • replaceMapping

      protected CompletableFuture<Binary> replaceMapping(CacheRequestHolder<com.oracle.coherence.grpc.ReplaceMappingRequest,Void> holder)
      Execute a ReplaceMappingRequest request.
      Parameters:
      holder - the CacheRequestHolder containing the ReplaceMappingRequest request
      Returns:
      a CompletionStage that completes with a Binary containing the serialized result of executing the ReplaceMappingRequest request
    • size

      public void size(com.oracle.coherence.grpc.SizeRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Int32Value> observer)
      Description copied from interface: NamedCacheService
      Determine the number of entries in a cache.
      Specified by:
      size in interface NamedCacheService
      Parameters:
      request - the SizeRequest to execute
      observer - the StreamObserver that will receive the responses
      See Also:
    • truncate

      public void truncate(com.oracle.coherence.grpc.TruncateRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.Empty> observer)
      Description copied from interface: NamedCacheService
      Removes all mappings from this map.

      Note: the removal of entries caused by this truncate operation will not be observable. This includes any registered listeners, triggers, or interceptors. However, a CacheLifecycleEvent is raised to notify subscribers of the execution of this operation.

      Specified by:
      truncate in interface NamedCacheService
      Parameters:
      request - the TruncateRequest containing the name of the cache to truncate
      observer - the StreamObserver that will receive the responses
    • values

      public void values(com.oracle.coherence.grpc.ValuesRequest request, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Execute the ValuesRequest request passing the results to the provided StreamObserver.
      Specified by:
      values in interface NamedCacheService
      Parameters:
      request - the ValuesRequest
      observer - the StreamObserver which will receive the results
      See Also:
    • values

      protected Void values(CacheRequestHolder<com.oracle.coherence.grpc.ValuesRequest,Void> holder, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Execute the ValuesRequest request passing the results to the provided StreamObserver.
      Parameters:
      holder - the CacheRequestHolder containing the ValuesRequest
      observer - the StreamObserver which will receive the results
      Returns:
      always returns Void
    • convertKeys

      protected CompletionStage<List<Binary>> convertKeys(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