Class PowerSetPartitionMap<T extends AsyncCloseable>
- java.lang.Object
-
- io.servicetalk.client.api.internal.partition.PowerSetPartitionMap<T>
-
- Type Parameters:
T- The partition type.
- All Implemented Interfaces:
PartitionMap<T>,AsyncCloseable,ListenableAsyncCloseable
public final class PowerSetPartitionMap<T extends AsyncCloseable> extends java.lang.Object implements PartitionMap<T>
APartitionMapthat creates the full power set using the individual attributes inPartitionAttributeses to create partitions for eachadd(PartitionAttributes).
-
-
Constructor Summary
Constructors Constructor Description PowerSetPartitionMap(java.util.function.Function<PartitionAttributes,T> valueFactory, java.util.function.IntFunction<PartitionAttributesBuilder> partitionAttributesBuilderFunc)Create a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<T>add(PartitionAttributes partition)Add a newPartitionAttributesthat is absolutely specified.CompletablecloseAsync()Used to close/shutdown a resource.CompletablecloseAsyncGracefully()Used to close/shutdown a resource, similar toAsyncCloseable.closeAsync(), but attempts to cleanup state before abruptly closing.Tget(PartitionAttributes wildCardAttributes)Get the partition value corresponding to thePartitionAttributesparameter.CompletableonClose()Returns aCompletablethat is notified once theListenableAsyncCloseablewas closed.java.util.List<T>remove(PartitionAttributes partition)Remove aPartitionAttributesthat was previously added viaPartitionMap.add(PartitionAttributes).
-
-
-
Constructor Detail
-
PowerSetPartitionMap
public PowerSetPartitionMap(java.util.function.Function<PartitionAttributes,T> valueFactory, java.util.function.IntFunction<PartitionAttributesBuilder> partitionAttributesBuilderFunc)
Create a new instance.- Parameters:
valueFactory- Generates values for new partitions.partitionAttributesBuilderFunc- Generates newPartitionAttributesobjects, this factory must be consistent with the factory used to build thePartitionAttributesobjects foradd(PartitionAttributes)andremove(PartitionAttributes)to ensureObject.hashCode()andObject.equals(Object)are consistent.
-
-
Method Detail
-
get
public T get(@Nullable PartitionAttributes wildCardAttributes)
Description copied from interface:PartitionMapGet the partition value corresponding to thePartitionAttributesparameter.This may be called from any thread.
- Specified by:
getin interfacePartitionMap<T extends AsyncCloseable>- Parameters:
wildCardAttributes- APartitionAttributeswhich identifies the partition. Note that this may not be fully specified, and this is where the "wild card" terminology comes from.- Returns:
- the partition value corresponding to the
PartitionAttributesparameter.
-
add
public java.util.List<T> add(PartitionAttributes partition)
Description copied from interface:PartitionMapAdd a newPartitionAttributesthat is absolutely specified. This may create new partitions.The terminology "absolutely"/"fully" here is meant to clarify that
partitioncontains all the attributes to uniquely identify a single host. This is typically called when notification is received fromServiceDiscovererand that address is translated to the correspondingPartitionAttributes.This method is not guaranteed to provide any thread safety or visibility with respect to calls to this method or
PartitionMap.remove(PartitionAttributes). If these methods are called from multiple threads you may need to provide external synchronization.- Specified by:
addin interfacePartitionMap<T extends AsyncCloseable>- Parameters:
partition- A fully specifiedPartitionAttributes.- Returns:
- The partitions that
partitionbelongs to. These may (or may not) be new partitions.
-
remove
public java.util.List<T> remove(PartitionAttributes partition)
Description copied from interface:PartitionMapRemove aPartitionAttributesthat was previously added viaPartitionMap.add(PartitionAttributes).New partitions typically are not created as a result of this method call.
This method is not guaranteed to provide any thread safety or visibility with respect to calls to this method or
PartitionMap.add(PartitionAttributes). If these methods are called from multiple threads you may need to provide external synchronization.- Specified by:
removein interfacePartitionMap<T extends AsyncCloseable>- Parameters:
partition- A fully specifiedPartitionAttributes.- Returns:
- The partitions that
partitionbelongs to.
-
onClose
public Completable onClose()
Description copied from interface:ListenableAsyncCloseableReturns aCompletablethat is notified once theListenableAsyncCloseablewas closed.- Specified by:
onClosein interfaceListenableAsyncCloseable- Returns:
- the
Completablethat is notified on close.
-
closeAsync
public Completable closeAsync()
Description copied from interface:AsyncCloseableUsed to close/shutdown a resource.- Specified by:
closeAsyncin interfaceAsyncCloseable- Returns:
- A
Completablethat is notified once the close is complete.
-
closeAsyncGracefully
public Completable closeAsyncGracefully()
Description copied from interface:AsyncCloseableUsed to close/shutdown a resource, similar toAsyncCloseable.closeAsync(), but attempts to cleanup state before abruptly closing. This provides a hint that implementations can use to stop accepting new work and finish in flight work. This method is implemented on a "best effort" basis and may be equivalent toAsyncCloseable.closeAsync().Note: Implementations may or may not apply a timeout for this operation to complete, if a caller does not want to wait indefinitely, and are unsure if the implementation applies a timeout, it is advisable to apply a timeout and force a call to
AsyncCloseable.closeAsync().- Specified by:
closeAsyncGracefullyin interfaceAsyncCloseable- Returns:
- A
Completablethat is notified once the close is complete.
-
-