public final class DefaultAsyncChannel<T>
extends Object
implements AsyncChannel
Default lock-based implementation of AsyncChannel.
Uses a ReentrantLock to coordinate access to the internal buffer and the waiting-sender/waiting-receiver queues. All operations return Awaitable immediately; the underlying CompletableFuture is completed asynchronously when matching counterparts arrive.
Every operation is arbitrated by a SelectClaim: the branches of a ChannelSelect share their select's claim, and a plain operation carries a private one. The claim is the sole owner of a parked operation's fate — a delivery commits it before it completes the future, and cancellation must commit it before it may touch the future — so a select over sends and receives on several channels commits exactly one transfer, and a losing branch never disturbs its channel.
Both waiting queues are concurrent deques so that a cancelled operation can withdraw itself without taking the channel lock: a ChannelSelect withdraws its losing branches from inside the winning channel's delivery, and taking a second channel's lock there could deadlock against a select completing on that channel.
T - the payload type| Constructor and description |
|---|
DefaultAsyncChannel() |
DefaultAsyncChannel(int capacity) |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public boolean |
close() |
|
public int |
getBufferedSize() |
|
public int |
getCapacity() |
|
public boolean |
isClosed() |
|
public Iterator<T> |
iterator()Returns a blocking iterator that receives values until the channel is closed and drained. |
|
public Awaitable<T> |
receive() |
|
public Awaitable<Void> |
send(T value) |
|
public String |
toString() |
Returns a blocking iterator that receives values until the channel
is closed and drained. Each next() call blocks until a value
is available. ChannelClosedException signals end-of-iteration.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.