View Javadoc
1   /*
2    * Copyright 2024 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.netty.channel;
17  
18  import io.netty.util.concurrent.Future;
19  
20  /**
21   * A registration for IO.
22   *
23   */
24  public interface IoRegistration {
25  
26      /**
27       * Submit the {@link IoOps} to the registration.
28       *
29       * @param   ops ops.
30       * @return  an identifier for the operation, which might be unique or not (depending on the implementation).
31       */
32      long submit(IoOps ops) throws Exception;
33  
34      /**
35       * Returns {@code true} if the registration is still valid. Once {@link #cancel()} is called this
36       * will return {@code false}.
37       *
38       * @return  valid.
39       */
40      default boolean isValid() {
41          return !cancelFuture().isDone();
42      }
43  
44      /**
45       * Cancel the registration.
46       */
47      void cancel() throws Exception;
48  
49      /**
50       * The {@link IoHandler} to which this {@link IoRegistration} belongs too.
51       *
52       * @return  ioHandler.
53       */
54      IoHandler ioHandler();
55  
56      /**
57       * Returns a {@link Future} that is notified once this {@link IoRegistration} was cancelled.
58       *
59       * @return future that is notified once registration is cancelled.
60       */
61      Future<?> cancelFuture();
62  }