Skip to content

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() returns false. In this state, isSuccess() and isCancelled() are also false, and cause() is null.^[600-developer__big-data__netty__netty-Future.md]
  • Completed Successfully: The operation finished as intended. isDone() is true and isSuccess() is true.^[600-developer__big-data__netty__netty-Future.md]
  • Completed with Failure: The operation finished with an exception. isDone() is true and cause() 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() is true and isCancelled() is true.^[600-developer__big-data__netty__netty-Future.md]

Sources

  • 600-developer__big-data__netty__netty-Future.md