View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  package org.apache.hc.core5.reactor;
28  
29  import org.apache.hc.core5.annotation.Internal;
30  import org.apache.hc.core5.http.HttpHost;
31  import org.apache.hc.core5.net.NamedEndpoint;
32  import org.apache.hc.core5.net.Ports;
33  import org.apache.hc.core5.util.Args;
34  
35  /**
36   * Endpoint initialization parameters
37   *
38   * @since 5.1
39   */
40  @Internal
41  public final class EndpointParameters implements NamedEndpoint {
42  
43      private final String scheme;
44      private final String hostName;
45      private final int port;
46      private final Object attachment;
47  
48      public EndpointParameters(final String scheme, final String hostName, final int port, final Object attachment) {
49          this.scheme = Args.notBlank(scheme, "Protocol scheme");
50          this.hostName = Args.notBlank(hostName, "Endpoint name");
51          this.port = Ports.checkWithDefault(port);
52          this.attachment = attachment;
53      }
54  
55      public EndpointParameters(final HttpHost host, final Object attachment) {
56          Args.notNull(host, "HTTP host");
57          this.scheme = host.getSchemeName();
58          this.hostName = host.getHostName();
59          this.port = host.getPort();
60          this.attachment = attachment;
61      }
62  
63      public String getScheme() {
64          return scheme;
65      }
66  
67      @Override
68      public String getHostName() {
69          return hostName;
70      }
71  
72      @Override
73      public int getPort() {
74          return port;
75      }
76  
77      public Object getAttachment() {
78          return attachment;
79      }
80  
81      @Override
82      public String toString() {
83          return "EndpointParameters{" +
84                  "scheme='" + scheme + '\'' +
85                  ", name='" + hostName + '\'' +
86                  ", port=" + port +
87                  ", attachment=" + attachment +
88                  '}';
89      }
90  
91  }