Methods Summary |
---|
public java.lang.Object | clone()
return super.clone();
|
public final void | connectProxy(org.apache.http.HttpHost proxy, boolean secure)Tracks connecting to the first proxy.
if (proxy == null) {
throw new IllegalArgumentException("Proxy host may not be null.");
}
if (this.connected) {
throw new IllegalStateException("Already connected.");
}
this.connected = true;
this.proxyChain = new HttpHost[]{ proxy };
this.secure = secure;
|
public final void | connectTarget(boolean secure)Tracks connecting to the target.
if (this.connected) {
throw new IllegalStateException("Already connected.");
}
this.connected = true;
this.secure = secure;
|
public final boolean | equals(java.lang.Object o)Compares this tracked route to another.
if (o == this)
return true;
if (!(o instanceof RouteTracker))
return false;
RouteTracker that = (RouteTracker) o;
boolean equal = this.targetHost.equals(that.targetHost);
equal &=
( this.localAddress == that.localAddress) ||
((this.localAddress != null) &&
this.localAddress.equals(that.localAddress));
equal &=
( this.proxyChain == that.proxyChain) ||
((this.proxyChain != null) &&
(that.proxyChain != null) &&
(this.proxyChain.length == that.proxyChain.length));
// comparison of actual proxies follows below
equal &=
(this.connected == that.connected) &&
(this.secure == that.secure) &&
(this.tunnelled == that.tunnelled) &&
(this.layered == that.layered);
// chain length has been compared above, now check the proxies
if (equal && (this.proxyChain != null)) {
for (int i=0; equal && (i<this.proxyChain.length); i++)
equal = this.proxyChain[i].equals(that.proxyChain[i]);
}
return equal;
|
public final int | getHopCount()
int hops = 0;
if (this.connected) {
if (proxyChain == null)
hops = 1;
else
hops = proxyChain.length + 1;
}
return hops;
|
public final org.apache.http.HttpHost | getHopTarget(int hop)
if (hop < 0)
throw new IllegalArgumentException
("Hop index must not be negative: " + hop);
final int hopcount = getHopCount();
if (hop >= hopcount) {
throw new IllegalArgumentException
("Hop index " + hop +
" exceeds tracked route length " + hopcount +".");
}
HttpHost result = null;
if (hop < hopcount-1)
result = this.proxyChain[hop];
else
result = this.targetHost;
return result;
|
public final LayerType | getLayerType()
return this.layered;
|
public final java.net.InetAddress | getLocalAddress()
return this.localAddress;
|
public final org.apache.http.HttpHost | getProxyHost()
return (this.proxyChain == null) ? null : this.proxyChain[0];
|
public final org.apache.http.HttpHost | getTargetHost()
return this.targetHost;
|
public final TunnelType | getTunnelType()
return this.tunnelled;
|
public final int | hashCode()Generates a hash code for this tracked route.
Route trackers are modifiable and should therefore not be used
as lookup keys. Use {@link #toRoute toRoute} to obtain an
unmodifiable representation of the tracked route.
int hc = this.targetHost.hashCode();
if (this.localAddress != null)
hc ^= localAddress.hashCode();
if (this.proxyChain != null) {
hc ^= proxyChain.length;
for (int i=0; i<proxyChain.length; i++)
hc ^= proxyChain[i].hashCode();
}
if (this.connected)
hc ^= 0x11111111;
if (this.secure)
hc ^= 0x22222222;
hc ^= this.tunnelled.hashCode();
hc ^= this.layered.hashCode();
return hc;
|
public final boolean | isConnected()
return this.connected;
|
public final boolean | isLayered()
return (this.layered == LayerType.LAYERED);
|
public final boolean | isSecure()
return this.secure;
|
public final boolean | isTunnelled()
return (this.tunnelled == TunnelType.TUNNELLED);
|
public final void | layerProtocol(boolean secure)Tracks layering a protocol.
// it is possible to layer a protocol over a direct connection,
// although this case is probably not considered elsewhere
if (!this.connected) {
throw new IllegalStateException
("No layered protocol unless connected.");
}
this.layered = LayerType.LAYERED;
this.secure = secure;
|
public final org.apache.http.conn.routing.HttpRoute | toRoute()Obtains the tracked route.
If a route has been tracked, it is {@link #isConnected connected}.
If not connected, nothing has been tracked so far.
return !this.connected ?
null : new HttpRoute(this.targetHost, this.localAddress,
this.proxyChain, this.secure,
this.tunnelled, this.layered);
|
public final java.lang.String | toString()Obtains a description of the tracked route.
StringBuilder cab = new StringBuilder(50 + getHopCount()*30);
cab.append("RouteTracker[");
if (this.localAddress != null) {
cab.append(this.localAddress);
cab.append("->");
}
cab.append('{");
if (this.connected)
cab.append('c");
if (this.tunnelled == TunnelType.TUNNELLED)
cab.append('t");
if (this.layered == LayerType.LAYERED)
cab.append('l");
if (this.secure)
cab.append('s");
cab.append("}->");
if (this.proxyChain != null) {
for (int i=0; i<this.proxyChain.length; i++) {
cab.append(this.proxyChain[i]);
cab.append("->");
}
}
cab.append(this.targetHost);
cab.append(']");
return cab.toString();
|
public final void | tunnelProxy(org.apache.http.HttpHost proxy, boolean secure)Tracks tunnelling to a proxy in a proxy chain.
This will extend the tracked proxy chain, but it does not mark
the route as tunnelled. Only end-to-end tunnels are considered there.
if (proxy == null) {
throw new IllegalArgumentException("Proxy host may not be null.");
}
if (!this.connected) {
throw new IllegalStateException("No tunnel unless connected.");
}
if (this.proxyChain == null) {
throw new IllegalStateException("No proxy tunnel without proxy.");
}
// prepare an extended proxy chain
HttpHost[] proxies = new HttpHost[this.proxyChain.length+1];
System.arraycopy(this.proxyChain, 0,
proxies, 0, this.proxyChain.length);
proxies[proxies.length-1] = proxy;
this.proxyChain = proxies;
this.secure = secure;
|
public final void | tunnelTarget(boolean secure)Tracks tunnelling to the target.
if (!this.connected) {
throw new IllegalStateException("No tunnel unless connected.");
}
if (this.proxyChain == null) {
throw new IllegalStateException("No tunnel without proxy.");
}
this.tunnelled = TunnelType.TUNNELLED;
this.secure = secure;
|