View Javadoc
1   /*
2    * Copyright 2016 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.bootstrap;
17  
18  import io.netty5.channel.ChannelHandler;
19  import io.netty5.channel.ChannelOption;
20  import io.netty5.channel.EventLoopGroup;
21  import io.netty5.channel.ServerChannel;
22  import io.netty5.channel.ServerChannelFactory;
23  import io.netty5.util.AttributeKey;
24  import io.netty5.util.internal.StringUtil;
25  
26  import java.util.Map;
27  
28  /**
29   * Exposes the configuration of a {@link ServerBootstrapConfig}.
30   */
31  public final class ServerBootstrapConfig extends AbstractBootstrapConfig<ServerBootstrap, ServerChannel,
32          ServerChannelFactory<? extends ServerChannel>> {
33  
34      ServerBootstrapConfig(ServerBootstrap bootstrap) {
35          super(bootstrap);
36      }
37  
38      /**
39       * Returns the configured {@link EventLoopGroup} which will be used for the child channels or {@code null}
40       * if non is configured yet.
41       */
42      @SuppressWarnings("deprecation")
43      public EventLoopGroup childGroup() {
44          return bootstrap.childGroup();
45      }
46  
47      /**
48       * Returns the configured {@link ChannelHandler} be used for the child channels or {@code null}
49       * if non is configured yet.
50       */
51      public ChannelHandler childHandler() {
52          return bootstrap.childHandler();
53      }
54  
55      /**
56       * Returns a copy of the configured options which will be used for the child channels.
57       */
58      public Map<ChannelOption<?>, Object> childOptions() {
59          return bootstrap.childOptions();
60      }
61  
62      /**
63       * Returns a copy of the configured attributes which will be used for the child channels.
64       */
65      public Map<AttributeKey<?>, Object> childAttrs() {
66          return bootstrap.childAttrs();
67      }
68  
69      @Override
70      public ServerChannelFactory<? extends ServerChannel> channelFactory() {
71          return bootstrap.channelFactory;
72      }
73  
74      @Override
75      public String toString() {
76          StringBuilder buf = new StringBuilder(super.toString());
77          buf.setLength(buf.length() - 1);
78          buf.append(", ");
79          EventLoopGroup childGroup = childGroup();
80          if (childGroup != null) {
81              buf.append("childGroup: ");
82              buf.append(StringUtil.simpleClassName(childGroup));
83              buf.append(", ");
84          }
85          Map<ChannelOption<?>, Object> childOptions = childOptions();
86          if (!childOptions.isEmpty()) {
87              buf.append("childOptions: ");
88              buf.append(childOptions);
89              buf.append(", ");
90          }
91          Map<AttributeKey<?>, Object> childAttrs = childAttrs();
92          if (!childAttrs.isEmpty()) {
93              buf.append("childAttrs: ");
94              buf.append(childAttrs);
95              buf.append(", ");
96          }
97          ChannelHandler childHandler = childHandler();
98          if (childHandler != null) {
99              buf.append("childHandler: ");
100             buf.append(childHandler);
101             buf.append(", ");
102         }
103         if (buf.charAt(buf.length() - 1) == '(') {
104             buf.append(')');
105         } else {
106             buf.setCharAt(buf.length() - 2, ')');
107             buf.setLength(buf.length() - 1);
108         }
109 
110         return buf.toString();
111     }
112 }