Package com.oracle.coherence.grpc.proxy
Class MapListenerProxy
- java.lang.Object
-
- com.oracle.coherence.grpc.proxy.MapListenerProxy
-
- All Implemented Interfaces:
com.tangosol.util.MapListener<Object,Object>,io.grpc.stub.StreamObserver<MapListenerRequest>,EventListener
public class MapListenerProxy extends Object implements io.grpc.stub.StreamObserver<MapListenerRequest>, com.tangosol.util.MapListener<Object,Object>
A class to encapsulate bidirectional streaming of map events for a single cache.- Since:
- 20.06
- Author:
- Jonathan Knight 2019.12.03
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classMapListenerProxy.DeactivationListenerNamedCacheDeactivationListenerthat will communicate cache truncation and destruction events over the proxy.protected static classMapListenerProxy.FilterInfoA holder for filter information.protected static classMapListenerProxy.KeyConverterConverter for cache key instances.static classMapListenerProxy.WrapperPrimingListenerMapListenerSupport.PrimingListenerthat delegates calls to the wrappedMapListener.
-
Field Summary
Fields Modifier and Type Field Description protected com.tangosol.util.MapListener<Object,Object>f_listenerDeactivationThe listener used to detect cache deactivation.protected com.tangosol.util.ConcurrentMap<com.tangosol.util.Filter<?>,MapListenerProxy.FilterInfo>f_mapFilterThe map ofFiltersthat thisMapListenerProxywas registered with.protected com.tangosol.util.ConcurrentMap<Object,Integer>f_mapKeysThe map of keys that thisMapListenerProxywas registered with.protected SafeStreamObserver<MapListenerResponse>f_observerTheStreamObserverto streamMapEventinstances to.protected NamedCacheServicef_serviceThe owningNamedCacheService.protected Set<Object>f_setKeysThe set of keys that thisMapListenerProxywas registered with.static intLITEConstant to indicate that the listener is registered for "lite" events.protected booleanm_fCompletedprotected CacheRequestHolder<MapListenerRequest,Void>m_holderTheCacheRequestHolderto hold theMapListenerRequestthat can convert between different serialization formats.protected MapListenerProxy.WrapperPrimingListenerm_primingListenerWrapper map event listener.static intPRIMINGConstant to indicate that the listener is registered for "priming" events.
-
Constructor Summary
Constructors Constructor Description MapListenerProxy(NamedCacheService service, io.grpc.stub.StreamObserver<MapListenerResponse> observer)Create aMapListenerProxyto handle aMapListenersubscription to a cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddListener(com.tangosol.util.Filter<?> filter, long filterId, boolean lite, boolean priming)Add this MapListenerProxy as a filter-based listener of the given NamedCache.protected voidaddListener(Object key, boolean lite, boolean priming)Add this MapListenerProxy as a key-based listener of the given NamedCache.protected voidaddListener(Object key, boolean lite, boolean priming, boolean register)Add this MapListenerProxy as a key-based listener of the given NamedCache.protected MapEventResponsecreateMapEventResponse(com.tangosol.util.MapEvent<?,?> mapEvent)Factory method to create newMapEventResponseinstances using the information in the suppliedMapEvent.protected com.tangosol.util.MapListenerSupport.PrimingListener<Object,Object>ensurePrimingListener()Return the priming listener, or it not already cached, create it.voidentryDeleted(com.tangosol.util.MapEvent<Object,Object> mapEvent)voidentryInserted(com.tangosol.util.MapEvent<Object,Object> mapEvent)voidentryUpdated(com.tangosol.util.MapEvent<Object,Object> mapEvent)protected MapListenerErrorResponseerror(String uid, Throwable t)Create aMapListenerErrorResponse.com.tangosol.util.MapListener<Object,Object>getDeactivationListener()Return theMapListenerProxy.DeactivationListenerfor this proxy.voidonCompleted()voidonError(Throwable throwable)protected voidonFilterRequest(MapListenerRequest request, com.tangosol.util.MapTrigger<com.tangosol.util.Binary,com.tangosol.util.Binary> trigger)Invoked whenMapListenerRequest.RequestTypeisKEY.protected voidonKeyRequest(MapListenerRequest request, com.tangosol.util.MapTrigger<?,?> trigger)Invoked whenMapListenerRequest.RequestTypeisKEY.protected voidonMapEvent(com.tangosol.util.MapEvent<?,?> event)Convert aMapEventinto aMapEventResponseand send it to theStreamObserver, converting theBinarykey and values if required.voidonNext(MapListenerRequest request)
-
-
-
Field Detail
-
LITE
public static final int LITE
Constant to indicate that the listener is registered for "lite" events.- See Also:
- Constant Field Values
-
PRIMING
public static final int PRIMING
Constant to indicate that the listener is registered for "priming" events.- See Also:
- Constant Field Values
-
m_fCompleted
protected volatile boolean m_fCompleted
-
f_service
protected final NamedCacheService f_service
The owningNamedCacheService.
-
f_observer
protected final SafeStreamObserver<MapListenerResponse> f_observer
TheStreamObserverto streamMapEventinstances to.
-
f_mapFilter
protected final com.tangosol.util.ConcurrentMap<com.tangosol.util.Filter<?>,MapListenerProxy.FilterInfo> f_mapFilter
The map ofFiltersthat thisMapListenerProxywas registered with.
-
f_mapKeys
protected final com.tangosol.util.ConcurrentMap<Object,Integer> f_mapKeys
The map of keys that thisMapListenerProxywas registered with.
-
f_setKeys
protected final Set<Object> f_setKeys
The set of keys that thisMapListenerProxywas registered with.
-
f_listenerDeactivation
protected final com.tangosol.util.MapListener<Object,Object> f_listenerDeactivation
The listener used to detect cache deactivation.
-
m_holder
protected CacheRequestHolder<MapListenerRequest,Void> m_holder
TheCacheRequestHolderto hold theMapListenerRequestthat can convert between different serialization formats.
-
m_primingListener
protected volatile MapListenerProxy.WrapperPrimingListener m_primingListener
Wrapper map event listener. This listener registration should force a synthetic event containing the current value to the requesting client.
-
-
Constructor Detail
-
MapListenerProxy
public MapListenerProxy(NamedCacheService service, io.grpc.stub.StreamObserver<MapListenerResponse> observer)
Create aMapListenerProxyto handle aMapListenersubscription to a cache.- Parameters:
service- theNamedCacheServiceto proxyobserver- theStreamObserverto streamMapEventinstances to
-
-
Method Detail
-
onNext
public void onNext(MapListenerRequest request)
- Specified by:
onNextin interfaceio.grpc.stub.StreamObserver<MapListenerRequest>
-
onError
public void onError(Throwable throwable)
- Specified by:
onErrorin interfaceio.grpc.stub.StreamObserver<MapListenerRequest>
-
onCompleted
public void onCompleted()
- Specified by:
onCompletedin interfaceio.grpc.stub.StreamObserver<MapListenerRequest>
-
getDeactivationListener
public com.tangosol.util.MapListener<Object,Object> getDeactivationListener()
Return theMapListenerProxy.DeactivationListenerfor this proxy.- Returns:
- the
MapListenerProxy.DeactivationListenerfor this proxy
-
onKeyRequest
protected void onKeyRequest(MapListenerRequest request, com.tangosol.util.MapTrigger<?,?> trigger)
Invoked whenMapListenerRequest.RequestTypeisKEY.- Parameters:
request- theMapListenerRequesttrigger- theMapTrigger
-
onFilterRequest
protected void onFilterRequest(MapListenerRequest request, com.tangosol.util.MapTrigger<com.tangosol.util.Binary,com.tangosol.util.Binary> trigger)
Invoked whenMapListenerRequest.RequestTypeisKEY.- Parameters:
request- theMapListenerRequesttrigger- theMapTrigger
-
addListener
protected void addListener(com.tangosol.util.Filter<?> filter, long filterId, boolean lite, boolean priming)Add this MapListenerProxy as a filter-based listener of the given NamedCache.- Parameters:
filter- the Filter to listen tofilterId- the unique positive identifier of the Filterlite- true to add a "lite" listenerpriming- true if the listener is a priming listener
-
addListener
protected void addListener(Object key, boolean lite, boolean priming)
Add this MapListenerProxy as a key-based listener of the given NamedCache.- Parameters:
key- the key to listen to deserialized in Object formlite-trueto add a "lite" listenerpriming-trueif the listener is a priming listener
-
addListener
protected void addListener(Object key, boolean lite, boolean priming, boolean register)
Add this MapListenerProxy as a key-based listener of the given NamedCache.- Parameters:
key- the key to listen to deserialized in Object formlite-trueto add a "lite" listenerpriming-trueif the listener is a priming listenerregister-trueif the listener should be added to the underlying cache
-
ensurePrimingListener
protected com.tangosol.util.MapListenerSupport.PrimingListener<Object,Object> ensurePrimingListener()
Return the priming listener, or it not already cached, create it.- Returns:
- the priming listener
-
onMapEvent
protected void onMapEvent(com.tangosol.util.MapEvent<?,?> event)
Convert aMapEventinto aMapEventResponseand send it to theStreamObserver, converting theBinarykey and values if required.- Parameters:
event- the event to send to the observer
-
createMapEventResponse
protected MapEventResponse createMapEventResponse(com.tangosol.util.MapEvent<?,?> mapEvent)
Factory method to create newMapEventResponseinstances using the information in the suppliedMapEvent.- Parameters:
mapEvent- theMapEventused to configure the newly createdMapEventResponse- Returns:
- a
MapEventResponsecreated from theMapEvent
-
error
protected MapListenerErrorResponse error(String uid, Throwable t)
Create aMapListenerErrorResponse.- Parameters:
uid- the UID of the requestt- the error that occurred- Returns:
- a
MapListenerErrorResponse.
-
-