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.kqueue;
17  
18  import io.netty.channel.IoEvent;
19  
20  /**
21   * {@link IoEvent} to use with {@link KQueueIoHandler}.
22   */
23  public final class KQueueIoEvent implements IoEvent {
24      private int ident;
25      private short filter;
26      private short flags;
27      private int fflags;
28      private long data;
29  
30      /**
31       * Creates a new {@link KQueueIoEvent}.
32       *
33       * @param ident     the identifier for this event.
34       * @param filter    the filter for this event.
35       * @param flags     the general flags.
36       * @param fflags    filter-specific flags.
37       * @return          {@link KQueueIoEvent}.
38       */
39      public static KQueueIoEvent newEvent(int ident, short filter, short flags, int fflags) {
40          return new KQueueIoEvent(ident, filter, flags, fflags, 0);
41      }
42  
43      private KQueueIoEvent(int ident, short filter, short flags, int fflags, long data) {
44          this.ident = ident;
45          this.filter = filter;
46          this.flags = flags;
47          this.fflags = fflags;
48          this.data = data;
49      }
50  
51      KQueueIoEvent() {
52          this(0, (short) 0, (short) 0, 0, 0);
53      }
54  
55      // Only used internally for re-use.
56      void update(int ident, short filter, short flags, int fflags, long data) {
57          this.ident = ident;
58          this.filter = filter;
59          this.flags = flags;
60          this.fflags = fflags;
61          this.data = data;
62      }
63  
64      /**
65       * Returns the identifier for this event.
66       *
67       * @return  ident.
68       */
69      public int ident() {
70          return ident;
71      }
72  
73      /**
74       * Returns the filter for this event.
75       *
76       * @return filter.
77       */
78      public short filter() {
79          return filter;
80      }
81  
82      /**
83       * Returns the general flags.
84       *
85       * @return flags.
86       */
87      public short flags() {
88          return flags;
89      }
90  
91      /**
92       * Returns filter-specific flags.
93       *
94       * @return fflags.
95       */
96      public int fflags() {
97          return fflags;
98      }
99  
100     /**
101      * Returns filter-specific data.
102      *
103      * @return data.
104      */
105     public long data() {
106         return data;
107     }
108 
109     @Override
110     public String toString() {
111         return "KQueueIoEvent{" +
112                 "ident=" + ident +
113                 ", filter=" + filter +
114                 ", flags=" + flags +
115                 ", fflags=" + fflags +
116                 ", data=" + data +
117                 '}';
118     }
119 }