1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.bootstrap;
17
18 import io.netty.channel.Channel;
19 import io.netty.channel.ChannelHandler;
20 import io.netty.channel.ChannelOption;
21 import io.netty.channel.EventLoopGroup;
22 import io.netty.util.AttributeKey;
23 import io.netty.util.internal.ObjectUtil;
24 import io.netty.util.internal.StringUtil;
25
26 import java.net.SocketAddress;
27 import java.util.Map;
28
29
30
31
32 public abstract class AbstractBootstrapConfig<B extends AbstractBootstrap<B, C>, C extends Channel> {
33
34 protected final B bootstrap;
35
36 protected AbstractBootstrapConfig(B bootstrap) {
37 this.bootstrap = ObjectUtil.checkNotNull(bootstrap, "bootstrap");
38 }
39
40
41
42
43 public final SocketAddress localAddress() {
44 return bootstrap.localAddress();
45 }
46
47
48
49
50 @SuppressWarnings("deprecation")
51 public final ChannelFactory<? extends C> channelFactory() {
52 return bootstrap.channelFactory();
53 }
54
55
56
57
58 public final ChannelHandler handler() {
59 return bootstrap.handler();
60 }
61
62
63
64
65 public final Map<ChannelOption<?>, Object> options() {
66 return bootstrap.options();
67 }
68
69
70
71
72 public final Map<AttributeKey<?>, Object> attrs() {
73 return bootstrap.attrs();
74 }
75
76
77
78
79 @SuppressWarnings("deprecation")
80 public final EventLoopGroup group() {
81 return bootstrap.group();
82 }
83
84 @Override
85 public String toString() {
86 StringBuilder buf = new StringBuilder()
87 .append(StringUtil.simpleClassName(this))
88 .append('(');
89 EventLoopGroup group = group();
90 if (group != null) {
91 buf.append("group: ")
92 .append(StringUtil.simpleClassName(group))
93 .append(", ");
94 }
95 @SuppressWarnings("deprecation")
96 ChannelFactory<? extends C> factory = channelFactory();
97 if (factory != null) {
98 buf.append("channelFactory: ")
99 .append(factory)
100 .append(", ");
101 }
102 SocketAddress localAddress = localAddress();
103 if (localAddress != null) {
104 buf.append("localAddress: ")
105 .append(localAddress)
106 .append(", ");
107 }
108
109 Map<ChannelOption<?>, Object> options = options();
110 if (!options.isEmpty()) {
111 buf.append("options: ")
112 .append(options)
113 .append(", ");
114 }
115 Map<AttributeKey<?>, Object> attrs = attrs();
116 if (!attrs.isEmpty()) {
117 buf.append("attrs: ")
118 .append(attrs)
119 .append(", ");
120 }
121 ChannelHandler handler = handler();
122 if (handler != null) {
123 buf.append("handler: ")
124 .append(handler)
125 .append(", ");
126 }
127 if (buf.charAt(buf.length() - 1) == '(') {
128 buf.append(')');
129 } else {
130 buf.setCharAt(buf.length() - 2, ')');
131 buf.setLength(buf.length() - 1);
132 }
133 return buf.toString();
134 }
135 }