Class MultiClusterContainer<T>
- java.lang.Object
-
- org.apache.cassandra.spark.bulkwriter.cloudstorage.coordinated.MultiClusterContainer<T>
-
- Type Parameters:
T- value type
- All Implemented Interfaces:
java.io.Serializable,MultiClusterSupport<T>
public class MultiClusterContainer<T> extends java.lang.Object implements java.io.Serializable, MultiClusterSupport<T>
A container to hold values per cluster. Each value is identified by its belonging cluster id. It is compatible with single cluster, i.e. no cluster id is defined for the value. Pass null clusterId to get the value. However, the container does not permit holding values for both multi-cluster case and single cluster case; otherwise,IllegalStateExceptionis thrown.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MultiClusterContainer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAll(java.util.Map<java.lang.String,T> clusters)Add all values from the mapbooleanequals(java.lang.Object obj)voidforEach(java.util.function.BiConsumer<java.lang.String,T> action)Iterate through all valuesTgetAnyValue()TgetAnyValueOrThrow()TgetValueOrNull(java.lang.String clusterId)Look up a value based on clusterIdinthashCode()static <T> MultiClusterContainer<T>ofSingle(T value)voidsetValue(java.lang.String clusterId, T value)Set the value for a clusterintsize()voidupdateValue(java.lang.String clusterId, java.util.function.UnaryOperator<T> valueUpdater)Update the value associated with the clusterId-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.spark.bulkwriter.cloudstorage.coordinated.MultiClusterSupport
getValueOrThrow
-
-
-
-
Method Detail
-
ofSingle
public static <T> MultiClusterContainer<T> ofSingle(T value)
-
getValueOrNull
@Nullable public T getValueOrNull(@Nullable java.lang.String clusterId)
Description copied from interface:MultiClusterSupportLook up a value based on clusterId- Specified by:
getValueOrNullin interfaceMultiClusterSupport<T>- Parameters:
clusterId- cluster id- Returns:
- the value of type T associated with the clusterId, or null if not found
-
getAnyValue
@Nullable public T getAnyValue()
- Returns:
- any value in the container. Null is returned if the container is empty.
-
getAnyValueOrThrow
@NotNull public T getAnyValueOrThrow() throws java.util.NoSuchElementException
- Returns:
- any value in the container
- Throws:
java.util.NoSuchElementException- when no value can be found
-
size
public int size()
- Specified by:
sizein interfaceMultiClusterSupport<T>- Returns:
- the total number of clusters
-
forEach
public void forEach(java.util.function.BiConsumer<java.lang.String,T> action)
Description copied from interface:MultiClusterSupportIterate through all values- Specified by:
forEachin interfaceMultiClusterSupport<T>- Parameters:
action- function to consume the values
-
setValue
public void setValue(@Nullable java.lang.String clusterId, @NotNull T value)Set the value for a cluster- Parameters:
clusterId- nullable cluster id. When the value is null, it reads from the single value
-
updateValue
public void updateValue(@Nullable java.lang.String clusterId, java.util.function.UnaryOperator<T> valueUpdater)Update the value associated with the clusterId- Parameters:
clusterId- nullable cluster id. When the value is null, it updates the single valuevalueUpdater- function to update the value; if not prior value exist, the updater receives null as input, If the updater returns null, the value associated with the cluster is removed
-
addAll
public void addAll(java.util.Map<java.lang.String,T> clusters)
Add all values from the map- Parameters:
clusters- map of value per cluster
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-