Class StateObjectCollection<T extends StateObject>
- java.lang.Object
-
- org.apache.flink.runtime.checkpoint.StateObjectCollection<T>
-
- Type Parameters:
T
- type of the contained state objects.
- All Implemented Interfaces:
Serializable
,Iterable<T>
,Collection<T>
,StateObject
public class StateObjectCollection<T extends StateObject> extends Object implements Collection<T>, StateObject
This class represents a generic collection forStateObject
s. Being a state object itself, it delegatesdiscardState()
to all contained state objects and computesgetStateSize()
as sum of the state sizes of all contained objects.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.runtime.state.StateObject
StateObject.StateObjectLocation, StateObject.StateObjectSizeStatsCollector
-
-
Constructor Summary
Constructors Constructor Description StateObjectCollection()
Creates a new StateObjectCollection that is backed by anArrayList
.StateObjectCollection(Collection<T> stateObjects)
Creates a new StateObjectCollection wraps the given collection and delegates to it.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T t)
boolean
addAll(Collection<? extends T> c)
List<T>
asList()
void
clear()
void
collectSizeStats(StateObject.StateObjectSizeStatsCollector collector)
Collects statistics about state size and location from the state object.boolean
contains(Object o)
boolean
containsAll(Collection<?> c)
void
discardState()
Discards the state referred to and solemnly owned by this handle, to free up resources in the persistent storage.static <T extends StateObject>
StateObjectCollection<T>empty()
static <T extends StateObject>
StateObjectCollection<T>emptyIfNull(StateObjectCollection<T> collection)
boolean
equals(Object o)
long
getCheckpointedSize()
long
getStateSize()
Returns the size of the state in bytes.int
hashCode()
boolean
hasState()
Returns true if this contains at least oneStateObject
.boolean
isEmpty()
Iterator<T>
iterator()
boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
boolean
removeIf(Predicate<? super T> filter)
boolean
retainAll(Collection<?> c)
static <T extends StateObject>
StateObjectCollection<T>singleton(T stateObject)
static <T extends StateObject>
StateObjectCollection<T>singletonOrEmpty(T stateObject)
int
size()
Object[]
toArray()
<T1> T1[]
toArray(T1[] a)
String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, spliterator, stream, toArray
-
-
-
-
Constructor Detail
-
StateObjectCollection
public StateObjectCollection()
Creates a new StateObjectCollection that is backed by anArrayList
.
-
StateObjectCollection
public StateObjectCollection(Collection<T> stateObjects)
Creates a new StateObjectCollection wraps the given collection and delegates to it.- Parameters:
stateObjects
- collection of state objects to wrap.
-
-
Method Detail
-
size
public int size()
- Specified by:
size
in interfaceCollection<T extends StateObject>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<T extends StateObject>
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<T extends StateObject>
-
iterator
public Iterator<T> iterator()
- Specified by:
iterator
in interfaceCollection<T extends StateObject>
- Specified by:
iterator
in interfaceIterable<T extends StateObject>
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<T extends StateObject>
-
toArray
public <T1> T1[] toArray(T1[] a)
- Specified by:
toArray
in interfaceCollection<T extends StateObject>
-
add
public boolean add(T t)
- Specified by:
add
in interfaceCollection<T extends StateObject>
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<T extends StateObject>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<T extends StateObject>
-
addAll
public boolean addAll(Collection<? extends T> c)
- Specified by:
addAll
in interfaceCollection<T extends StateObject>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interfaceCollection<T extends StateObject>
-
removeIf
public boolean removeIf(Predicate<? super T> filter)
- Specified by:
removeIf
in interfaceCollection<T extends StateObject>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interfaceCollection<T extends StateObject>
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<T extends StateObject>
-
discardState
public void discardState() throws Exception
Description copied from interface:StateObject
Discards the state referred to and solemnly owned by this handle, to free up resources in the persistent storage. This method is called when the state represented by this object will not be used anymore.- Specified by:
discardState
in interfaceStateObject
- Throws:
Exception
-
getStateSize
public long getStateSize()
Description copied from interface:StateObject
Returns the size of the state in bytes. If the size is not known, this method should return0
.The values produced by this method are only used for informational purposes and for metrics/monitoring. If this method returns wrong values, the checkpoints and recovery will still behave correctly. However, efficiency may be impacted (wrong space pre-allocation) and functionality that depends on metrics (like monitoring) will be impacted.
Note for implementors: This method should not perform any I/O operations while obtaining the state size (hence it does not declare throwing an
IOException
). Instead, the state size should be stored in the state object, or should be computable from the state stored in this object. The reason is that this method is called frequently by several parts of the checkpointing and issuing I/O requests from this method accumulates a heavy I/O load on the storage system at higher scale.- Specified by:
getStateSize
in interfaceStateObject
- Returns:
- Size of the state in bytes.
-
collectSizeStats
public void collectSizeStats(StateObject.StateObjectSizeStatsCollector collector)
Description copied from interface:StateObject
Collects statistics about state size and location from the state object.- Specified by:
collectSizeStats
in interfaceStateObject
- Parameters:
collector
- the statistics collector.
-
getCheckpointedSize
public long getCheckpointedSize()
-
hasState
public boolean hasState()
Returns true if this contains at least oneStateObject
.
-
equals
public boolean equals(Object o)
- Specified by:
equals
in interfaceCollection<T extends StateObject>
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceCollection<T extends StateObject>
- Overrides:
hashCode
in classObject
-
empty
public static <T extends StateObject> StateObjectCollection<T> empty()
-
emptyIfNull
public static <T extends StateObject> StateObjectCollection<T> emptyIfNull(@Nullable StateObjectCollection<T> collection)
-
singleton
public static <T extends StateObject> StateObjectCollection<T> singleton(T stateObject)
-
singletonOrEmpty
public static <T extends StateObject> StateObjectCollection<T> singletonOrEmpty(@Nullable T stateObject)
-
-