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>
APartitionMap
that creates the full power set using the individual attributes inPartitionAttributes
es 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 newPartitionAttributes
that is absolutely specified.Completable
closeAsync()
Used to close/shutdown a resource.Completable
closeAsyncGracefully()
Used to close/shutdown a resource, similar toAsyncCloseable.closeAsync()
, but attempts to cleanup state before abruptly closing.T
get(PartitionAttributes wildCardAttributes)
Get the partition value corresponding to thePartitionAttributes
parameter.Completable
onClose()
Returns aCompletable
that is notified once theListenableAsyncCloseable
was closed.java.util.List<T>
remove(PartitionAttributes partition)
Remove aPartitionAttributes
that 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 newPartitionAttributes
objects, this factory must be consistent with the factory used to build thePartitionAttributes
objects 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:PartitionMap
Get the partition value corresponding to thePartitionAttributes
parameter.This may be called from any thread.
- Specified by:
get
in interfacePartitionMap<T extends AsyncCloseable>
- Parameters:
wildCardAttributes
- APartitionAttributes
which 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
PartitionAttributes
parameter.
-
add
public java.util.List<T> add(PartitionAttributes partition)
Description copied from interface:PartitionMap
Add a newPartitionAttributes
that is absolutely specified. This may create new partitions.The terminology "absolutely"/"fully" here is meant to clarify that
partition
contains all the attributes to uniquely identify a single host. This is typically called when notification is received fromServiceDiscoverer
and 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:
add
in interfacePartitionMap<T extends AsyncCloseable>
- Parameters:
partition
- A fully specifiedPartitionAttributes
.- Returns:
- The partitions that
partition
belongs to. These may (or may not) be new partitions.
-
remove
public java.util.List<T> remove(PartitionAttributes partition)
Description copied from interface:PartitionMap
Remove aPartitionAttributes
that 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:
remove
in interfacePartitionMap<T extends AsyncCloseable>
- Parameters:
partition
- A fully specifiedPartitionAttributes
.- Returns:
- The partitions that
partition
belongs to.
-
onClose
public Completable onClose()
Description copied from interface:ListenableAsyncCloseable
Returns aCompletable
that is notified once theListenableAsyncCloseable
was closed.- Specified by:
onClose
in interfaceListenableAsyncCloseable
- Returns:
- the
Completable
that is notified on close.
-
closeAsync
public Completable closeAsync()
Description copied from interface:AsyncCloseable
Used to close/shutdown a resource.- Specified by:
closeAsync
in interfaceAsyncCloseable
- Returns:
- A
Completable
that is notified once the close is complete.
-
closeAsyncGracefully
public Completable closeAsyncGracefully()
Description copied from interface:AsyncCloseable
Used 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:
closeAsyncGracefully
in interfaceAsyncCloseable
- Returns:
- A
Completable
that is notified once the close is complete.
-
-