View Javadoc
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;
17  
18  import java.net.SocketAddress;
19  
20  import static io.netty5.util.internal.ObjectUtil.checkPositive;
21  
22  /**
23   * Represents the properties of a {@link Channel} implementation.
24   */
25  public final class ChannelMetadata {
26  
27      private final boolean hasDisconnect;
28      private final int defaultMaxMessagesPerRead;
29  
30      /**
31       * Create a new instance
32       *
33       * @param hasDisconnect     {@code true} if and only if the channel has the {@code disconnect()} operation
34       *                          that allows a user to disconnect and then call {@link Channel#connect(SocketAddress)}
35       *                          again, such as UDP/IP.
36       */
37      public ChannelMetadata(boolean hasDisconnect) {
38          this(hasDisconnect, 1);
39      }
40  
41      /**
42       * Create a new instance
43       *
44       * @param hasDisconnect     {@code true} if and only if the channel has the {@code disconnect()} operation
45       *                          that allows a user to disconnect and then call {@link Channel#connect(SocketAddress)}
46       *                          again, such as UDP/IP.
47       * @param defaultMaxMessagesPerRead If a {@link MaxMessagesRecvBufferAllocator} is in use, then this value will be
48       * set for {@link MaxMessagesRecvBufferAllocator#maxMessagesPerRead()}. Must be {@code > 0}.
49       */
50      public ChannelMetadata(boolean hasDisconnect, int defaultMaxMessagesPerRead) {
51          checkPositive(defaultMaxMessagesPerRead, "defaultMaxMessagesPerRead");
52          this.hasDisconnect = hasDisconnect;
53          this.defaultMaxMessagesPerRead = defaultMaxMessagesPerRead;
54      }
55  
56      /**
57       * Returns {@code true} if and only if the channel has the {@code disconnect()} operation
58       * that allows a user to disconnect and then call {@link Channel#connect(SocketAddress)} again,
59       * such as UDP/IP.
60       */
61      public boolean hasDisconnect() {
62          return hasDisconnect;
63      }
64  
65      /**
66       * If a {@link MaxMessagesRecvBufferAllocator} is in use, then this is the default value for
67       * {@link MaxMessagesRecvBufferAllocator#maxMessagesPerRead()}.
68       */
69      public int defaultMaxMessagesPerRead() {
70          return defaultMaxMessagesPerRead;
71      }
72  }