1 /* 2 * Copyright 2012 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package io.netty5.channel.nio; 17 18 import java.nio.channels.SelectableChannel; 19 import java.nio.channels.SelectionKey; 20 import java.nio.channels.Selector; 21 22 /** 23 * An arbitrary task that can be executed by {@link NioHandler} when a {@link SelectableChannel} becomes ready. 24 * 25 * @see NioHandler#register(SelectableChannel, int, NioTask) 26 */ 27 public interface NioTask<C extends SelectableChannel> { 28 /** 29 * Invoked when the {@link SelectableChannel} has been selected by the {@link Selector}. 30 */ 31 void channelReady(C ch, SelectionKey key) throws Exception; 32 33 /** 34 * Invoked when the {@link SelectionKey} of the specified {@link SelectableChannel} has been cancelled and thus 35 * this {@link NioTask} will not be notified anymore. 36 * 37 * @param cause the cause of the unregistration. {@code null} if a user called {@link SelectionKey#cancel()} or 38 * the event loop has been shut down. 39 */ 40 void channelUnregistered(C ch, Throwable cause) throws Exception; 41 }