MapEventsManager handles registration, de-registration of callbacks, and notification of MapEvents to callbacks. Since multiple callbacks can be registered for a single key / filter, this class relies on another internal class called ListenerGroup which maintains the collection of callbacks.

There are two maps that are maintained:

  1. A Map of string keys mapped to a ListenerGroup, which is used to identify the group of callbacks for a single key. We stringify the key since Javascript is not the same as Java's equals().

  2. A Map of filter => ListenerGroup that is used to identify the group of callbacks for a MapEventFilter.

When a filter is subscribed, the server responds with a unique filterID. This filterID is what is specified is a MapEvent. So, this class maintains a third Map of filterID to ListenerGroup for efficiently identifying the ListenerGroup for a filterID.

This class also lazily creates the "events" stream (a bidi stream). When the first callback is registered, this class calls the "events()" method on the NamedCacheClient and obtains the duplex stream. Similarly, it closes the stream when the last callback is unregistered.

Type Parameters

  • K

  • V

Hierarchy

  • MapEventsManager

Constructors

  • Constructs a new MapEventsManager

    Type Parameters

    • K

    • V

    Parameters

    • namedMap: NamedMap<K, V>

      the NamedMap to manage events for

    • session: Session

      the associated Session

    • client: NamedCacheServiceClient

      the gRPC interface for making requests

    • serializer: Serializer

      the Serializer used by this map

    • emitter: EventEmitter

      the EventEmitter to use

    Returns MapEventsManager<K, V>

Properties

client: NamedCacheServiceClient

The gRPC service client.

mapName: string

The map name for which events are received.

namedMap: NamedMap<K, V>

The NamedMap used as the source of the events.

reqFactory: RequestFactory<K, V>

Request factory.

Methods

  • Close this event stream.

    Returns Promise<void>

  • Create a BiDi stream lazily.

    Returns Promise<null | ClientDuplexStream<MapListenerRequest, MapListenerResponse>>

  • Add the filter ID and the group to the ID -> group mapping.

    Parameters

    • filterId: number

      the filter ID

    • group: ListenerGroup<K, V>

      the listener group

    Returns void

  • Unsubscribe the filter ID and filter from their associated maps.

    Parameters

    • filterId: number

      the filter ID

    • filter: MapEventFilter<K, V>

      the filter

    Returns void

  • Process incoming gRPC MapListenerResponses.

    Parameters

    • resp: MapListenerResponse

      the gRPC MapListenerResponse to process

    Returns void

  • Remove key from key group.

    Parameters

    • key: K

      the key to remove

    Returns void

  • Registers the specified listener to listen for events matching the provided filter.

    Parameters

    • listener: MapListener<K, V>
    • mapFilter: null | Filter

      the filter associated with the listener

    • isLite: boolean = false

      true if the event should only include the key, or false if the event should include old and new values as well as the key

    Returns Promise<void>

  • Registers the specified listener to listen for events matching the provided key.

    Parameters

    • listener: MapListener<K, V>
    • key: K

      the map key to listen to

    • isLite: boolean = false

      true if the event should only include the key, or false if the event should include old and new values as well as the key

    Returns Promise<void>

  • Removes the registration of the listener for the provided key.

    Parameters

    Returns Promise<void>

  • Write the provided gRPC MapListenerRequest.

    Parameters

    • request: MapListenerRequest

      the gRPC MapListenerRequest

    Returns Promise<void>