Netty Promise¶
Netty Promise is an extension of the Netty Future interface, serving as a specialized writable future that allows the user to mark the operation as successful or failed manually.^[600-developer__big-data__netty__netty-Future.md]
Overview¶
In Netty's asynchronous framework, a Promise acts as a placeholder for the result of a computation that is initially unknown. Unlike standard futures which are often read-only, a Promise provides the necessary methods to control the lifecycle of the operation, enabling the creator to set its success or failure state.^[600-developer__big-data__netty__netty-Future.md]
Architecture and Inheritance¶
The Promise interface fits into Netty's concurrency hierarchy, which differs from the standard JDK concurrency utilities.^[600-developer__big-data__netty__netty-Future.md]
JDK Comparison¶
The JDK provides the base interfaces for asynchronous tasks:
- java.util.concurrent.Future
- java.util.concurrent.FutureTask^[600-developer__big-data__netty__netty-Future.md]
Netty Implementation¶
Netty extends these concepts with its own set of interfaces to handle I/O operations and channel events:
- io.netty.util.concurrent.Future (Extends java.util.concurrent.Future)
- io.netty.util.concurrent.Promise
- io.netty.channel.ChannelFuture^[600-developer__big-data__netty__netty-Future.md]
Operation States¶
A Netty Promise (like Future) transitions through specific states during its lifecycle.^[600-developer__big-data__netty__netty-Future.md]
- Uncompleted: The initial state where
isDone()returnsfalse. In this state,isSuccess()andisCancelled()are alsofalse, andcause()isnull.^[600-developer__big-data__netty__netty-Future.md] - Completed Successfully: The operation finished as intended.
isDone()istrueandisSuccess()istrue.^[600-developer__big-data__netty__netty-Future.md] - Completed with Failure: The operation finished with an exception.
isDone()istrueandcause()returns a non-null object describing the failure.^[600-developer__big-data__netty__netty-Future.md] - Completed by Cancellation: The operation was cancelled before completion.
isDone()istrueandisCancelled()istrue.^[600-developer__big-data__netty__netty-Future.md]
Related Concepts¶
- Netty Future
- [[Asynchronous programming]]
- [[Event Loop]]
Sources¶
600-developer__big-data__netty__netty-Future.md