N
- The type of the namespace.T
- The type of the values stored in this ReducingState
.W
- Generic type that extends both the underlying ValueState
and KvState
.public class GenericReducingState<N,T,W extends ValueState<T> & KvState<N>> extends Object implements ReducingState<T>, KvState<N>
ReducingState
based on a wrapped ValueState
.Constructor and Description |
---|
GenericReducingState(ValueState<T> wrappedState,
ReduceFunction<T> reduceFunction)
Creates a new
ReducingState that wraps the given ValueState . |
Modifier and Type | Method and Description |
---|---|
void |
add(T value)
Updates the operator state accessible by
AppendingState.get() by adding the given value
to the list of values. |
void |
clear()
Removes the value mapped under the current key.
|
T |
get()
Returns the current value for the state.
|
byte[] |
getSerializedValue(byte[] serializedKeyAndNamespace)
Returns the serialized value for the given key and namespace.
|
void |
setCurrentNamespace(N namespace)
Sets the current namespace, which will be used when using the state access methods.
|
public GenericReducingState(ValueState<T> wrappedState, ReduceFunction<T> reduceFunction)
ReducingState
that wraps the given ValueState
. The
ValueState
must have a default value of null
.wrappedState
- The wrapped ValueState
reduceFunction
- The ReduceFunction
to use for combining values.public void setCurrentNamespace(N namespace)
KvState
setCurrentNamespace
in interface KvState<N>
namespace
- The namespace.public byte[] getSerializedValue(byte[] serializedKeyAndNamespace) throws Exception
KvState
If no value is associated with key and namespace, null
is returned.
getSerializedValue
in interface KvState<N>
serializedKeyAndNamespace
- Serialized key and namespacenull
if no value is associated
with the key and namespace.Exception
- Exceptions during serialization are forwardedpublic T get() throws Exception
AppendingState
NOTE TO IMPLEMENTERS: if the state is empty, then this method
should return null
.
get
in interface AppendingState<T,T>
null
if the state is empty.Exception
- Thrown if the system cannot access the state.public void add(T value) throws Exception
AppendingState
AppendingState.get()
by adding the given value
to the list of values. The next time AppendingState.get()
is called (for the same state
partition) the returned state will represent the updated list.add
in interface AppendingState<T,T>
value
- The new value for the state.IOException
- Thrown if the system cannot access the state.Exception
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.