Package io.aether.utils.streams
Interface Value<T>
-
- Type Parameters:
T- The type of data contained in this value
- All Superinterfaces:
io.aether.utils.ToString
- All Known Implementing Classes:
ValueAddRequest,ValueClose,ValueExclusiveOnReject,ValueForce,ValueMap,ValueMap2,ValueNotClose,ValueOfData,ValueOfDataForceOnDrop,ValueOfForce,ValueOfForceOnDrop,ValueOfOnDrop,ValueOfRequest,ValueOnDrop,ValueOnEnter,ValueOnReject,ValueProxy,ValueProxyTimeout,ValueRequest,ValueWithClose,ValueWithForce,ValueWithSubValues
public interface Value<T> extends io.aether.utils.ToStringInterface representing a value that can be processed in a stream-like manner in reactive programming. Values act as data containers that flow through processing pipelines, with lifecycle management capabilities.Key features:
- Lifecycle management (enter/reject/success)
- Priority-based processing
- Special value types (force, request, close)
- Timeout handling
- Data transformation capabilities
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.concurrent.atomic.AtomicLongBLOCK_COUNTERstatic Value<?>CLOSE_INSTANCEstatic Value<?>FORCE_INSTANCEstatic longTIMEOUT
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default @NotNull Value<T>addRequest()Creates a new value with request semantics added.Tdata()Retrieves the data payload contained in this value.voidenter(java.lang.Object owner)Marks the beginning of value processing by a handler.default longgetRequestDataId()default booleanisClose()Checks if this value signals stream/processing closure.booleanisData()Checks if this value contains processable data.default booleanisForce()Checks if this value is marked as "force".default booleanisOnlyRequestData()default booleanisRequestData()Determines if this value represents a data request.default Value<T>linkFuture(io.aether.utils.futures.AFuture res)default Value<T>linkOnRejectExclusive(ValueExclusiveOnReject.Listener task)Attaches an exclusive reject handler that replaces default reject behavior.default <T2> Value<T2>map(io.aether.utils.interfaces.AFunction<T,T2> mapper)Transforms the contained data using a mapping function.default <T2> Value<T2>map2(T2 val)Transforms this value into a new value with different data.default Value<T>notClose()Creates a new value with the same data but not marked as "close".static <T> Value<T>of(T data)Creates a simple data-carrying value.static <T> Value<T>of(T data, boolean force, io.aether.utils.interfaces.AConsumer<java.lang.Object> onDrop)Creates a value with data, force flag, and success handler.static <T> Value<T>of(T data, boolean force, java.util.Collection<Value<?>> subValues)Creates a new value with data, force flag, and sub-values.static <T> Value<T>of(T data, io.aether.utils.interfaces.AConsumer<java.lang.Object> onDrop)Creates a data-carrying value with success handler.static <T> Value<T>ofClose()Creates a stream close value.static <K> Value<K>ofForce()Creates a generic force-marked value without data.static <T> Value<T>ofForce(T data)Creates a force-marked data-carrying value.static <T> Value<T>ofForce(T data, io.aether.utils.interfaces.AConsumer<java.lang.Object> onDrop)Creates a force-marked value with data and success handler.static <T> @NotNull Value<T>ofRequest()Creates a data request value.static <T> @NotNull Value<T>ofRequest(long id)default Value<T>onEnter(io.aether.utils.interfaces.AConsumer<java.lang.Object> f)Attaches a handler to be called when this value enters processing.default Value<T>onReject(ValueOnReject.Listener task)Adds an reject handler to be called when this value is rejected.default Value<T>onSuccess(io.aether.utils.interfaces.AConsumer<java.lang.Object> task)Adds a success handler to be called when this value is succeed.default intpriority()Returns the processing priority of this value.default voidreject(java.lang.Object owner)voidreject(java.lang.Object owner, long blockId)Rejects the value sending process due to a stream being blocked.voidsuccess(java.lang.Object owner)Releases resources associated with this value when it's no longer needed.default Value<T>timeout(long time)Sets a processing timeout for this value.default Value<T>timeout(long time, io.aether.utils.interfaces.AConsumer<java.util.concurrent.ConcurrentLinkedQueue<java.lang.Object>> task)Enhanced timeout with custom action when timeout occurs.default Value<T>withClose()Creates a new value with the same data but marked as "close".default Value<T>withForce()Creates a new value with the same data but marked as "force".
-
-
-
Field Detail
-
BLOCK_COUNTER
static final java.util.concurrent.atomic.AtomicLong BLOCK_COUNTER
-
FORCE_INSTANCE
static final Value<?> FORCE_INSTANCE
-
CLOSE_INSTANCE
static final Value<?> CLOSE_INSTANCE
-
TIMEOUT
static final long TIMEOUT
- See Also:
- Constant Field Values
-
-
Method Detail
-
data
T data()
Retrieves the data payload contained in this value. The actual data type is determined by the generic parameter T.- Returns:
- The contained data object, which may be null for special values
-
priority
default int priority()
Returns the processing priority of this value. Higher priority values should be processed before lower priority ones. Default implementation returns 0 (normal priority).- Returns:
- Priority level as an integer (higher = more important)
-
isForce
default boolean isForce()
Checks if this value is marked as "force". Force values typically bypass normal processing constraints and must be handled immediately regardless of system state.- Returns:
- true if this is a force value, false otherwise
-
isRequestData
default boolean isRequestData()
Determines if this value represents a data request. Request values typically ask for data to be generated/sent rather than containing data themselves.- Returns:
- true if this is a request value, false otherwise
-
getRequestDataId
default long getRequestDataId()
-
isClose
default boolean isClose()
Checks if this value signals stream/processing closure. Close values typically indicate the end of a data stream or processing sequence.- Returns:
- true if this is a close signal, false otherwise
-
success
void success(java.lang.Object owner)
Releases resources associated with this value when it's no longer needed. This is the normal end-of-life operation for a value.- Parameters:
owner- The object initiating the success operation (for tracking/logging)
-
enter
void enter(java.lang.Object owner)
Marks the beginning of value processing by a handler. Called when a processor starts working with this value.- Parameters:
owner- The object that begins processing this value
-
reject
void reject(java.lang.Object owner, long blockId)Rejects the value sending process due to a stream being blocked.- Parameters:
owner- An object that provides information about the current state of the block.When the creator of the Value object receives an reject call, it understands that the stream is currently blocked and data cannot be sent at this moment.
If, at the same time, a Value object with the isRequestData flag arrives from the stream, a race condition can occur. To resolve this issue, the checkWritable method should be called to determine the actual state of the remote node.
blockId-
-
reject
default void reject(java.lang.Object owner)
-
timeout
default Value<T> timeout(long time)
Sets a processing timeout for this value. If the value isn't fully processed (either succeed or rejected) within the specified time, a warning will be logged including information about which processors entered the value.- Parameters:
time- Timeout duration in milliseconds- Returns:
- A new Value instance with timeout tracking behavior
-
timeout
default Value<T> timeout(long time, io.aether.utils.interfaces.AConsumer<java.util.concurrent.ConcurrentLinkedQueue<java.lang.Object>> task)
Enhanced timeout with custom action when timeout occurs. Similar to timeout(long) but executes the provided task when timeout occurs.- Parameters:
time- Timeout duration in millisecondstask- Action to execute when timeout occurs, receives enter tracking queue- Returns:
- A new Value instance with timeout tracking behavior
-
onEnter
default Value<T> onEnter(io.aether.utils.interfaces.AConsumer<java.lang.Object> f)
Attaches a handler to be called when this value enters processing. The original value remains unchanged - returns a new wrapper value.- Parameters:
f- Handler to call on enter- Returns:
- New Value instance with enter handler
-
map2
default <T2> Value<T2> map2(T2 val)
Transforms this value into a new value with different data. Useful for creating derivative values while maintaining the original's lifecycle.- Parameters:
val- The new data to wrap- Returns:
- New Value instance with different data type
-
map
default <T2> Value<T2> map(io.aether.utils.interfaces.AFunction<T,T2> mapper)
Transforms the contained data using a mapping function. The mapping occurs lazily when data() is first called on the returned value.- Parameters:
mapper- Function to transform the contained data- Returns:
- New Value instance with transformed data
-
linkOnRejectExclusive
default Value<T> linkOnRejectExclusive(ValueExclusiveOnReject.Listener task)
Attaches an exclusive reject handler that replaces default reject behavior. Only this handler will be called when the value is rejected.- Parameters:
task- Handler to call exclusively on reject- Returns:
- New Value instance with exclusive reject handler
-
onReject
default Value<T> onReject(ValueOnReject.Listener task)
Adds an reject handler to be called when this value is rejected. The handler runs in addition to the default reject behavior.- Parameters:
task- Handler to call on reject- Returns:
- New Value instance with additional reject handler
-
onSuccess
default Value<T> onSuccess(io.aether.utils.interfaces.AConsumer<java.lang.Object> task)
Adds a success handler to be called when this value is succeed. The handler runs in addition to the default success behavior.- Parameters:
task- Handler to call on success- Returns:
- New Value instance with additional success handler
-
isData
boolean isData()
Checks if this value contains processable data. Returns false for control values (force, request, close).- Returns:
- true if this value contains data, false otherwise
-
withForce
default Value<T> withForce()
Creates a new value with the same data but marked as "force". If this value is already a force value, returns itself.- Returns:
- Force-marked Value instance
-
withClose
default Value<T> withClose()
Creates a new value with the same data but marked as "close". If this value is already a close value, returns itself.- Returns:
- Close-marked Value instance
-
notClose
default Value<T> notClose()
Creates a new value with the same data but not marked as "close". If this value is already not a close value, returns itself.- Returns:
- Not-close-marked Value instance
-
addRequest
@NotNull default @NotNull Value<T> addRequest()
Creates a new value with request semantics added. Useful for creating values that both contain data and request more data.- Returns:
- New Value instance with request flag set
-
isOnlyRequestData
default boolean isOnlyRequestData()
-
of
static <T> Value<T> of(T data, boolean force, java.util.Collection<Value<?>> subValues)
Creates a new value with data, force flag, and sub-values. Sub-values allow creating hierarchical value structures.- Parameters:
data- The primary data payloadforce- Whether this value should be force-processedsubValues- Collection of child values- Returns:
- New Value instance with timeout applied
-
of
static <T> Value<T> of(T data)
Creates a simple data-carrying value.- Parameters:
data- The data payload- Returns:
- New Value instance with timeout applied
-
ofForce
static <T> Value<T> ofForce(T data)
Creates a force-marked data-carrying value.- Parameters:
data- The data payload- Returns:
- New force-marked Value instance with timeout applied
-
of
static <T> Value<T> of(T data, io.aether.utils.interfaces.AConsumer<java.lang.Object> onDrop)
Creates a data-carrying value with success handler.- Parameters:
data- The data payloadonDrop- Handler to call when value is succeed- Returns:
- New Value instance with success handler and timeout
-
of
static <T> Value<T> of(T data, boolean force, io.aether.utils.interfaces.AConsumer<java.lang.Object> onDrop)
Creates a value with data, force flag, and success handler.- Parameters:
data- The data payloadforce- Whether this value should be force-processedonDrop- Handler to call when value is succeed- Returns:
- New Value instance with specified properties and timeout
-
ofForce
static <T> Value<T> ofForce(T data, io.aether.utils.interfaces.AConsumer<java.lang.Object> onDrop)
Creates a force-marked value with data and success handler.- Parameters:
data- The data payloadonDrop- Handler to call when value is succeed- Returns:
- New force-marked Value instance with success handler and timeout
-
ofForce
static <K> Value<K> ofForce()
Creates a generic force-marked value without data.- Returns:
- Singleton force value instance
-
ofRequest
@NotNull static <T> @NotNull Value<T> ofRequest()
Creates a data request value.- Returns:
- Singleton request value instance
-
ofRequest
@NotNull static <T> @NotNull Value<T> ofRequest(long id)
-
ofClose
static <T> Value<T> ofClose()
Creates a stream close value.- Returns:
- Singleton close value instance
-
-