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