SelectionKey Ready Operations Bitmask¶
The Ready Operations Bitmask is an integer value used within Java NIO (specifically the SelectionKey class) to identify the operation categories for which a channel has been detected to be ready by its selector.^[600-developer__big-data__netty__netty-01.md]
State Initialization and Lifecycle¶
The ready set is initialized to zero when the key is created^[600-developer__big-data__netty__netty-01.md]. In the context of frameworks like Netty, channels such as NioServerSocketChannel and NioSocketChannel are registered with an initial interest of 0^[600-developer__big-data__netty__netty-01.md].
This value is subsequently updated by the selector during a selection operation (often triggered by an event firing mechanism) and cannot be updated directly^[600-developer__big-data__netty__netty-01.md].
Bitwise Operations¶
Because the state is represented as a bitmask, checking for a specific operation involves bitwise AND comparison.^[600-developer__big-data__netty__netty-01.md] For example, to check if a channel is ready for reading, one would evaluate: readyOps() & OP_READ) != 0^[600-developer__big-data__netty__netty-01.md].
Operation Constants¶
The specific operations are defined using bit shifting, resulting in the following decimal values^[600-developer__big-data__netty__netty-01.md]:
- OP_READ:
1 << 0(Value: 1) - OP_WRITE:
1 << 2(Value: 4) - OP_CONNECT:
1 << 3(Value: 8) - OP_ACCEPT:
1 << 4(Value: 16)
This implies that at any single moment, a SocketChannel's readyOps() returns a composite bitmask representing the sum of all currently ready operations^[600-developer__big-data__netty__netty-01.md].
Related Concepts¶
- [[Netty]]
- [[Java NIO]]
Sources¶
- 600-developer__big-data__netty__netty-01.md