View Javadoc
1   /*
2    * Copyright 2014 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  
17  package io.netty.handler.proxy;
18  
19  import io.netty.util.internal.ObjectUtil;
20  import io.netty.util.internal.StringUtil;
21  
22  import java.net.SocketAddress;
23  
24  public final class ProxyConnectionEvent {
25  
26      private final String protocol;
27      private final String authScheme;
28      private final SocketAddress proxyAddress;
29      private final SocketAddress destinationAddress;
30      private String strVal;
31  
32      /**
33       * Creates a new event that indicates a successful connection attempt to the destination address.
34       */
35      public ProxyConnectionEvent(
36              String protocol, String authScheme, SocketAddress proxyAddress, SocketAddress destinationAddress) {
37          this.protocol = ObjectUtil.checkNotNull(protocol, "protocol");
38          this.authScheme = ObjectUtil.checkNotNull(authScheme, "authScheme");
39          this.proxyAddress = ObjectUtil.checkNotNull(proxyAddress, "proxyAddress");
40          this.destinationAddress = ObjectUtil.checkNotNull(destinationAddress, "destinationAddress");
41      }
42  
43      /**
44       * Returns the name of the proxy protocol in use.
45       */
46      public String protocol() {
47          return protocol;
48      }
49  
50      /**
51       * Returns the name of the authentication scheme in use.
52       */
53      public String authScheme() {
54          return authScheme;
55      }
56  
57      /**
58       * Returns the address of the proxy server.
59       */
60      @SuppressWarnings("unchecked")
61      public <T extends SocketAddress> T proxyAddress() {
62          return (T) proxyAddress;
63      }
64  
65      /**
66       * Returns the address of the destination.
67       */
68      @SuppressWarnings("unchecked")
69      public <T extends SocketAddress> T destinationAddress() {
70          return (T) destinationAddress;
71      }
72  
73      @Override
74      public String toString() {
75          if (strVal != null) {
76              return strVal;
77          }
78  
79          StringBuilder buf = new StringBuilder(128)
80              .append(StringUtil.simpleClassName(this))
81              .append('(')
82              .append(protocol)
83              .append(", ")
84              .append(authScheme)
85              .append(", ")
86              .append(proxyAddress)
87              .append(" => ")
88              .append(destinationAddress)
89              .append(')');
90  
91          return strVal = buf.toString();
92      }
93  }