Class KeyValuesCollectionListenerAdapter
- All Implemented Interfaces:
WatchClient.UnitListener
KeyValuesCollectionListener into a WatchClient.UnitListener.
Useful for watches that want to keep an in-memory
structure of key values for easy streaming parsability via a
KeyValuesCollectionParser.
This implementation is stateful, essentially turning delta-based watch responses
into key value collections that represent the collective state. As
such, the initialization of this listener needs to be handled carefully.
Callers must be sure to call publishInitial(HeaderResponse, KeyValuesCollection)
after creation, but before actually installing the listener.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates the adapter. -
Method Summary
Modifier and TypeMethodDescriptionvoidInvoked on completion.voidInvoked on errors.voidonNext(@NotNull WatchResponseUnit unit) Invoked on new events.voidpublishInitial(HeaderResponse initialHeader, KeyValuesCollection initialState) Initialize the state.
-
Constructor Details
-
KeyValuesCollectionListenerAdapter
Creates the adapter.The idea is that collection represents the whole known state from some point in time (usually recent). The known time is represented by the header. This state is usually from a recent
GetPrefixResponse, but it can come from other sources. Once the state is known, the watch can be created as appropriate to receive the relevant watch responses to update the state in an efficient (delta-based) manner.- Parameters:
listener- the listener
-
-
Method Details
-
publishInitial
Initialize the state.- Parameters:
initialHeader- the initial headerinitialState- the initial state - all keys and values starting at the GetPrefix root
-
onNext
Description copied from interface:WatchClient.UnitListenerInvoked on new events.Can be called many times but is never called after
WatchClient.UnitListener.onError(Throwable)orWatchClient.UnitListener.onCompleted()are called.- Specified by:
onNextin interfaceWatchClient.UnitListener- Parameters:
unit- the watch response unit
-
onError
Description copied from interface:WatchClient.UnitListenerInvoked on errors.May only be called once and if called it must be the last method called.
- Specified by:
onErrorin interfaceWatchClient.UnitListener- Parameters:
throwable- the error
-
onCompleted
public void onCompleted()Description copied from interface:WatchClient.UnitListenerInvoked on completion.May only be called once and if called it must be the last method called.
- Specified by:
onCompletedin interfaceWatchClient.UnitListener
-