View Javadoc
1   /*
2    * Copyright 2025 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.uring;
17  
18  import io.netty.channel.ChannelOption;
19  import io.netty.channel.RecvByteBufAllocator;
20  import io.netty.util.internal.ObjectUtil;
21  
22  import java.util.Map;
23  
24  abstract class IoUringStreamChannelConfig extends IoUringChannelConfig {
25  
26      private volatile short bufferGroupId = -1;
27  
28      IoUringStreamChannelConfig(AbstractIoUringChannel channel) {
29          super(channel);
30      }
31  
32      IoUringStreamChannelConfig(AbstractIoUringChannel channel, RecvByteBufAllocator allocator) {
33          super(channel, allocator);
34      }
35  
36      @SuppressWarnings("unchecked")
37      @Override
38      public <T> T getOption(ChannelOption<T> option) {
39          if (option == IoUringChannelOption.IO_URING_BUFFER_GROUP_ID) {
40              return (T) Short.valueOf(getBufferGroupId());
41          }
42          return super.getOption(option);
43      }
44  
45      @Override
46      public <T> boolean setOption(ChannelOption<T> option, T value) {
47          if (option == IoUringChannelOption.IO_URING_BUFFER_GROUP_ID) {
48              setBufferGroupId((Short) value);
49              return true;
50          }
51          return super.setOption(option, value);
52      }
53  
54      @Override
55      public Map<ChannelOption<?>, Object> getOptions() {
56          return getOptions(super.getOptions(), IoUringChannelOption.IO_URING_BUFFER_GROUP_ID);
57      }
58  
59      short getBufferGroupId() {
60          return bufferGroupId;
61      }
62  
63      IoUringStreamChannelConfig setBufferGroupId(short bufferGroupId) {
64          this.bufferGroupId = (short) ObjectUtil.checkPositiveOrZero(bufferGroupId, "bufferGroupId");
65          return this;
66      }
67  }