HTTPCLIENT-742: common interface for HttpRoute and RouteTracker

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@620254 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Roland Weber 2008-02-10 10:18:48 +00:00
parent 088cafdee7
commit 2c2dd57f72
7 changed files with 228 additions and 190 deletions

View File

@ -1,6 +1,9 @@
Changes since 4.0 Alpha 2
-------------------
* [HTTPCLIENT-742] common interface for HttpRoute and RouteTracker
Contributed by Roland Weber <rolandw at apache.org>
* [HTTPCLIENT-741] Fixed concurrency issues in AbstractClientConnAdapter.
Contributed by Oleg Kalnichevski <olegk at apache.org>

View File

@ -48,33 +48,7 @@ import org.apache.http.HttpHost;
*
* @since 4.0
*/
public final class HttpRoute implements Cloneable {
/**
* The tunnelling type of a route.
* Plain routes are established by connecting to the target or
* the first proxy.
* Tunnelled routes are established by connecting to the first proxy
* and tunnelling through all proxies to the target.
* Routes without a proxy cannot be tunnelled.
*/
public enum TunnelType { PLAIN, TUNNELLED };
/**
* The layering type of a route.
* Plain routes are established by connecting or tunnelling.
* Layered routes are established by layering a protocol such as TLS/SSL
* over an existing connection.
* Protocols can only be layered over a tunnel to the target, or
* or over a direct connection without proxies.
* <br/>
* Layering a protocol
* over a direct connection makes little sense, since the connection
* could be established with the new protocol in the first place.
* But we don't want to exclude that use case.
*/
public enum LayerType { PLAIN, LAYERED };
public final class HttpRoute implements RouteInfo, Cloneable {
/** The target host to connect to. */
private final HttpHost targetHost;
@ -279,55 +253,26 @@ public final class HttpRoute implements Cloneable {
}
/**
* Obtains the target host.
*
* @return the target host
*/
// non-JavaDoc, see interface RouteInfo
public final HttpHost getTargetHost() {
return this.targetHost;
}
/**
* Obtains the local address to connect from.
*
* @return the local address,
* or <code>null</code>
*/
// non-JavaDoc, see interface RouteInfo
public final InetAddress getLocalAddress() {
return this.localAddress;
}
/**
* Obtains the number of hops in this route.
* A direct route has one hop. A route through a proxy has two hops.
* A route through a chain of <i>n</i> proxies has <i>n+1</i> hops.
*
* @return the number of hops in this route
*/
// non-JavaDoc, see interface RouteInfo
public final int getHopCount() {
return (proxyChain == null) ? 1 : (proxyChain.length+1);
}
/**
* Obtains the target of a hop in this route.
* The target of the last hop is the {@link #getTargetHost target host},
* the target of previous hops is the respective proxy in the chain.
* For a route through exactly one proxy, target of hop 0 is the proxy
* and target of hop 1 is the target host.
*
* @param hop index of the hop for which to get the target,
* 0 for first
*
* @return the target of the given hop
*
* @throws IllegalArgumentException
* if the argument is negative or not less than
* {@link #getHopCount getHopCount()}
*/
// non-JavaDoc, see interface RouteInfo
public final HttpHost getHopTarget(int hop) {
if (hop < 0)
throw new IllegalArgumentException
@ -348,72 +293,37 @@ public final class HttpRoute implements Cloneable {
}
/**
* Obtains the first proxy host.
*
* @return the first proxy in the proxy chain, or
* <code>null</code> if this route is direct
*/
// non-JavaDoc, see interface RouteInfo
public final HttpHost getProxyHost() {
return (this.proxyChain == null) ? null : this.proxyChain[0];
}
/**
* Obtains the tunnel type of this route.
* If there is a proxy chain, only end-to-end tunnels are considered.
*
* @return the tunnelling type
*/
// non-JavaDoc, see interface RouteInfo
public final TunnelType getTunnelType() {
return this.tunnelled;
}
/**
* Checks whether this route is tunnelled through a proxy.
* If there is a proxy chain, only end-to-end tunnels are considered.
*
* @return <code>true</code> if tunnelled end-to-end through at least
* one proxy,
* <code>false</code> otherwise
*/
// non-JavaDoc, see interface RouteInfo
public final boolean isTunnelled() {
return (this.tunnelled == TunnelType.TUNNELLED);
}
/**
* Obtains the layering type of this route.
* In the presence of proxies, only layering over an end-to-end tunnel
* is considered.
*
* @return the layering type
*/
// non-JavaDoc, see interface RouteInfo
public final LayerType getLayerType() {
return this.layered;
}
/**
* Checks whether this route includes a layered protocol.
* In the presence of proxies, only layering over an end-to-end tunnel
* is considered.
*
* @return <code>true</code> if layered,
* <code>false</code> otherwise
*/
// non-JavaDoc, see interface RouteInfo
public final boolean isLayered() {
return (this.layered == LayerType.LAYERED);
}
/**
* Checks whether this route is secure.
*
* @return <code>true</code> if secure,
* <code>false</code> otherwise
*/
// non-JavaDoc, see interface RouteInfo
public final boolean isSecure() {
return this.secure;
}

View File

@ -0,0 +1,194 @@
/*
* $HeadURL$
* $Revision$
* $Date$
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.conn.routing;
import java.net.InetAddress;
import org.apache.http.HttpHost;
/**
* Read-only interface for route information.
*
* @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
*
*
* <!-- empty lines to avoid svn diff problems -->
* @version $Revision$
*
* @since 4.0
*/
public interface RouteInfo {
/**
* The tunnelling type of a route.
* Plain routes are established by connecting to the target or
* the first proxy.
* Tunnelled routes are established by connecting to the first proxy
* and tunnelling through all proxies to the target.
* Routes without a proxy cannot be tunnelled.
*/
public enum TunnelType { PLAIN, TUNNELLED };
/**
* The layering type of a route.
* Plain routes are established by connecting or tunnelling.
* Layered routes are established by layering a protocol such as TLS/SSL
* over an existing connection.
* Protocols can only be layered over a tunnel to the target, or
* or over a direct connection without proxies.
* <br/>
* Layering a protocol
* over a direct connection makes little sense, since the connection
* could be established with the new protocol in the first place.
* But we don't want to exclude that use case.
*/
public enum LayerType { PLAIN, LAYERED };
/**
* Obtains the target host.
*
* @return the target host
*/
HttpHost getTargetHost()
;
/**
* Obtains the local address to connect from.
*
* @return the local address,
* or <code>null</code>
*/
InetAddress getLocalAddress()
;
/**
* Obtains the number of hops in this route.
* A direct route has one hop. A route through a proxy has two hops.
* A route through a chain of <i>n</i> proxies has <i>n+1</i> hops.
*
* @return the number of hops in this route
*/
int getHopCount()
;
/**
* Obtains the target of a hop in this route.
* The target of the last hop is the {@link #getTargetHost target host},
* the target of previous hops is the respective proxy in the chain.
* For a route through exactly one proxy, target of hop 0 is the proxy
* and target of hop 1 is the target host.
*
* @param hop index of the hop for which to get the target,
* 0 for first
*
* @return the target of the given hop
*
* @throws IllegalArgumentException
* if the argument is negative or not less than
* {@link #getHopCount getHopCount()}
*/
HttpHost getHopTarget(int hop)
;
/**
* Obtains the first proxy host.
*
* @return the first proxy in the proxy chain, or
* <code>null</code> if this route is direct
*/
HttpHost getProxyHost()
;
/**
* Obtains the tunnel type of this route.
* If there is a proxy chain, only end-to-end tunnels are considered.
*
* @return the tunnelling type
*/
TunnelType getTunnelType()
;
/**
* Checks whether this route is tunnelled through a proxy.
* If there is a proxy chain, only end-to-end tunnels are considered.
*
* @return <code>true</code> if tunnelled end-to-end through at least
* one proxy,
* <code>false</code> otherwise
*/
boolean isTunnelled()
;
/**
* Obtains the layering type of this route.
* In the presence of proxies, only layering over an end-to-end tunnel
* is considered.
*
* @return the layering type
*/
LayerType getLayerType()
;
/**
* Checks whether this route includes a layered protocol.
* In the presence of proxies, only layering over an end-to-end tunnel
* is considered.
*
* @return <code>true</code> if layered,
* <code>false</code> otherwise
*/
boolean isLayered()
;
/**
* Checks whether this route is secure.
*
* @return <code>true</code> if secure,
* <code>false</code> otherwise
*/
boolean isSecure()
;
} // interface RouteInfo

View File

@ -34,8 +34,6 @@ package org.apache.http.conn.routing;
import java.net.InetAddress;
import org.apache.http.HttpHost;
import org.apache.http.conn.routing.HttpRoute.TunnelType;
import org.apache.http.conn.routing.HttpRoute.LayerType;
/**
@ -49,7 +47,7 @@ import org.apache.http.conn.routing.HttpRoute.LayerType;
*
* @since 4.0
*/
public final class RouteTracker implements Cloneable {
public final class RouteTracker implements RouteInfo, Cloneable {
/** The target host to connect to. */
private final HttpHost targetHost;
@ -212,37 +210,20 @@ public final class RouteTracker implements Cloneable {
}
/**
* Obtains the target host.
*
* @return the target host
*/
// non-JavaDoc, see interface RouteInfo
public final HttpHost getTargetHost() {
return this.targetHost;
}
/**
* Obtains the local address to connect from.
*
* @return the local address,
* or <code>null</code>
*/
// non-JavaDoc, see interface RouteInfo
public final InetAddress getLocalAddress() {
return this.localAddress;
}
/**
* Obtains the number of tracked hops.
* An unconnected route has no hops.
* Connecting directly to the target adds one hop.
* Connecting to a proxy adds two hops, one for the proxy and
* one for the target.
* Tunnelling to a proxy in a proxy chain adds one hop.
*
* @return the number of hops in the tracked route
*/
// non-JavaDoc, see interface RouteInfo
public final int getHopCount() {
int hops = 0;
if (this.connected) {
@ -255,18 +236,7 @@ public final class RouteTracker implements Cloneable {
}
/**
* Obtains the target of a hop in this route.
*
* @param hop index of the hop for which to get the target,
* 0 for first
*
* @return the target of the given hop
*
* @throws IllegalArgumentException
* if the argument is negative or not less than
* {@link #getHopCount getHopCount()}
*/
// non-JavaDoc, see interface RouteInfo
public final HttpHost getHopTarget(int hop) {
if (hop < 0)
throw new IllegalArgumentException
@ -288,82 +258,43 @@ public final class RouteTracker implements Cloneable {
}
/**
* Obtains the first proxy host.
*
* @return the first proxy host, or <code>null</code> if not tracked
*/
// non-JavaDoc, see interface RouteInfo
public final HttpHost getProxyHost() {
return (this.proxyChain == null) ? null : this.proxyChain[0];
}
/**
* Checks whether this route is connected to it's first hop.
*
* @return <code>true</code> if connected,
* <code>false</code> otherwise
*/
// non-JavaDoc, see interface RouteInfo
public final boolean isConnected() {
return this.connected;
}
/**
* Obtains the tunnel type of this route.
* If there is a proxy chain, only end-to-end tunnels are considered.
*
* @return the tunnelling type
*/
// non-JavaDoc, see interface RouteInfo
public final TunnelType getTunnelType() {
return this.tunnelled;
}
/**
* Checks whether this route is tunnelled through a proxy.
* If there is a proxy chain, only end-to-end tunnels are considered.
*
* @return <code>true</code> if tunnelled end-to-end through at least
* one proxy,
* <code>false</code> otherwise
*/
// non-JavaDoc, see interface RouteInfo
public final boolean isTunnelled() {
return (this.tunnelled == TunnelType.TUNNELLED);
}
/**
* Obtains the layering type of this route.
* In the presence of proxies, only layering over an end-to-end tunnel
* is considered.
*
* @return the layering type
*/
// non-JavaDoc, see interface RouteInfo
public final LayerType getLayerType() {
return this.layered;
}
/**
* Checks whether this route includes a layered protocol.
* In the presence of proxies, only layering over an end-to-end tunnel
* is considered.
*
* @return <code>true</code> if layered,
* <code>false</code> otherwise
*/
// non-JavaDoc, see interface RouteInfo
public final boolean isLayered() {
return (this.layered == LayerType.LAYERED);
}
/**
* Checks whether this route is secure.
*
* @return <code>true</code> if secure,
* <code>false</code> otherwise
*/
// non-JavaDoc, see interface RouteInfo
public final boolean isSecure() {
return this.secure;
}

View File

@ -41,8 +41,8 @@ import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.http.HttpHost;
import org.apache.http.conn.routing.HttpRoute.TunnelType;
import org.apache.http.conn.routing.HttpRoute.LayerType;
import org.apache.http.conn.routing.RouteInfo.TunnelType;
import org.apache.http.conn.routing.RouteInfo.LayerType;
/**

View File

@ -38,8 +38,8 @@ import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.http.HttpHost;
import org.apache.http.conn.routing.HttpRoute.TunnelType;
import org.apache.http.conn.routing.HttpRoute.LayerType;
import org.apache.http.conn.routing.RouteInfo.TunnelType;
import org.apache.http.conn.routing.RouteInfo.LayerType;
/**

View File

@ -40,8 +40,8 @@ import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.http.HttpHost;
import org.apache.http.conn.routing.HttpRoute.TunnelType;
import org.apache.http.conn.routing.HttpRoute.LayerType;
import org.apache.http.conn.routing.RouteInfo.TunnelType;
import org.apache.http.conn.routing.RouteInfo.LayerType;
/**