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.Channel;
19  import io.netty5.channel.ChannelFactory;
20  import io.netty5.resolver.AddressResolverGroup;
21  
22  import java.net.SocketAddress;
23  
24  /**
25   * Exposes the configuration of a {@link Bootstrap}.
26   */
27  public final class BootstrapConfig extends
28                                     AbstractBootstrapConfig<Bootstrap, Channel, ChannelFactory<? extends Channel>> {
29  
30      BootstrapConfig(Bootstrap bootstrap) {
31          super(bootstrap);
32      }
33  
34      @Override
35      public ChannelFactory<? extends Channel> channelFactory() {
36          return bootstrap.channelFactory;
37      }
38  
39      /**
40       * Returns the configured remote address or {@code null} if non is configured yet.
41       */
42      public SocketAddress remoteAddress() {
43          return bootstrap.remoteAddress();
44      }
45  
46      /**
47       * Returns the configured {@link AddressResolverGroup} or the default if non is configured yet.
48       */
49      public AddressResolverGroup<?> resolver() {
50          return bootstrap.resolver();
51      }
52  
53      @Override
54      public String toString() {
55          StringBuilder buf = new StringBuilder(super.toString());
56          buf.setLength(buf.length() - 1);
57          buf.append(", resolver: ").append(resolver());
58          SocketAddress remoteAddress = remoteAddress();
59          if (remoteAddress != null) {
60              buf.append(", remoteAddress: ")
61                      .append(remoteAddress);
62          }
63          return buf.append(')').toString();
64      }
65  }