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