Class RouteTracker

  • All Implemented Interfaces:
    java.lang.Cloneable, RouteInfo

    public final class RouteTracker
    extends java.lang.Object
    implements RouteInfo, java.lang.Cloneable
    Helps tracking the steps in establishing a route.
    Since:
    4.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean connected
      Whether the first hop of the route is established.
      private RouteInfo.LayerType layered
      Whether the route is layered over a tunnel.
      private java.net.InetAddress localAddress
      The local address to connect from.
      private org.apache.hc.core5.http.HttpHost[] proxyChain
      The proxy chain, if any.
      private boolean secure
      Whether the route is secure.
      private org.apache.hc.core5.http.HttpHost targetHost
      The target host to connect to.
      private RouteInfo.TunnelType tunnelled
      Whether the the route is tunnelled end-to-end through proxies.
    • Constructor Summary

      Constructors 
      Constructor Description
      RouteTracker​(HttpRoute route)
      Creates a new tracker for the given route.
      RouteTracker​(org.apache.hc.core5.http.HttpHost target, java.net.InetAddress local)
      Creates a new route tracker.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()  
      void connectProxy​(org.apache.hc.core5.http.HttpHost proxy, boolean secure)
      Tracks connecting to the first proxy.
      void connectTarget​(boolean secure)
      Tracks connecting to the target.
      boolean equals​(java.lang.Object o)
      Compares this tracked route to another.
      int getHopCount()
      Obtains the number of hops in this route.
      org.apache.hc.core5.http.HttpHost getHopTarget​(int hop)
      Obtains the target of a hop in this route.
      RouteInfo.LayerType getLayerType()
      Obtains the layering type of this route.
      java.net.InetAddress getLocalAddress()
      Obtains the local address to connect from.
      org.apache.hc.core5.http.HttpHost getProxyHost()
      Obtains the first proxy host.
      org.apache.hc.core5.http.HttpHost getTargetHost()
      Obtains the target host.
      RouteInfo.TunnelType getTunnelType()
      Obtains the tunnel type of this route.
      int hashCode()
      Generates a hash code for this tracked route.
      boolean isConnected()  
      boolean isLayered()
      Checks whether this route includes a layered protocol.
      boolean isSecure()
      Checks whether this route is secure.
      boolean isTunnelled()
      Checks whether this route is tunnelled through a proxy.
      void layerProtocol​(boolean secure)
      Tracks layering a protocol.
      void reset()  
      HttpRoute toRoute()
      Obtains the tracked route.
      java.lang.String toString()
      Obtains a description of the tracked route.
      void tunnelProxy​(org.apache.hc.core5.http.HttpHost proxy, boolean secure)
      Tracks tunnelling to a proxy in a proxy chain.
      void tunnelTarget​(boolean secure)
      Tracks tunnelling to the target.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • targetHost

        private final org.apache.hc.core5.http.HttpHost targetHost
        The target host to connect to.
      • localAddress

        private final java.net.InetAddress localAddress
        The local address to connect from. null indicates that the default should be used.
      • connected

        private boolean connected
        Whether the first hop of the route is established.
      • proxyChain

        private org.apache.hc.core5.http.HttpHost[] proxyChain
        The proxy chain, if any.
      • tunnelled

        private RouteInfo.TunnelType tunnelled
        Whether the the route is tunnelled end-to-end through proxies.
      • secure

        private boolean secure
        Whether the route is secure.
    • Constructor Detail

      • RouteTracker

        public RouteTracker​(org.apache.hc.core5.http.HttpHost target,
                            java.net.InetAddress local)
        Creates a new route tracker. The target and origin need to be specified at creation time.
        Parameters:
        target - the host to which to route
        local - the local address to route from, or null for the default
      • RouteTracker

        public RouteTracker​(HttpRoute route)
        Creates a new tracker for the given route. Only target and origin are taken from the route, everything else remains to be tracked.
        Parameters:
        route - the route to track
    • Method Detail

      • reset

        public void reset()
        Since:
        4.2
      • connectTarget

        public void connectTarget​(boolean secure)
        Tracks connecting to the target.
        Parameters:
        secure - true if the route is secure, false otherwise
      • connectProxy

        public void connectProxy​(org.apache.hc.core5.http.HttpHost proxy,
                                 boolean secure)
        Tracks connecting to the first proxy.
        Parameters:
        proxy - the proxy connected to
        secure - true if the route is secure, false otherwise
      • tunnelTarget

        public void tunnelTarget​(boolean secure)
        Tracks tunnelling to the target.
        Parameters:
        secure - true if the route is secure, false otherwise
      • tunnelProxy

        public void tunnelProxy​(org.apache.hc.core5.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.
        Parameters:
        proxy - the proxy tunnelled to
        secure - true if the route is secure, false otherwise
      • layerProtocol

        public void layerProtocol​(boolean secure)
        Tracks layering a protocol.
        Parameters:
        secure - true if the route is secure, false otherwise
      • getTargetHost

        public org.apache.hc.core5.http.HttpHost getTargetHost()
        Description copied from interface: RouteInfo
        Obtains the target host.
        Specified by:
        getTargetHost in interface RouteInfo
        Returns:
        the target host
      • getLocalAddress

        public java.net.InetAddress getLocalAddress()
        Description copied from interface: RouteInfo
        Obtains the local address to connect from.
        Specified by:
        getLocalAddress in interface RouteInfo
        Returns:
        the local address, or null
      • getHopCount

        public int getHopCount()
        Description copied from interface: RouteInfo
        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 n proxies has n+1 hops.
        Specified by:
        getHopCount in interface RouteInfo
        Returns:
        the number of hops in this route
      • getHopTarget

        public org.apache.hc.core5.http.HttpHost getHopTarget​(int hop)
        Description copied from interface: RouteInfo
        Obtains the target of a hop in this route. The target of the last hop is the 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.
        Specified by:
        getHopTarget in interface RouteInfo
        Parameters:
        hop - index of the hop for which to get the target, 0 for first
        Returns:
        the target of the given hop
      • getProxyHost

        public org.apache.hc.core5.http.HttpHost getProxyHost()
        Description copied from interface: RouteInfo
        Obtains the first proxy host.
        Specified by:
        getProxyHost in interface RouteInfo
        Returns:
        the first proxy in the proxy chain, or null if this route is direct
      • isConnected

        public boolean isConnected()
      • getTunnelType

        public RouteInfo.TunnelType getTunnelType()
        Description copied from interface: RouteInfo
        Obtains the tunnel type of this route. If there is a proxy chain, only end-to-end tunnels are considered.
        Specified by:
        getTunnelType in interface RouteInfo
        Returns:
        the tunnelling type
      • isTunnelled

        public boolean isTunnelled()
        Description copied from interface: RouteInfo
        Checks whether this route is tunnelled through a proxy. If there is a proxy chain, only end-to-end tunnels are considered.
        Specified by:
        isTunnelled in interface RouteInfo
        Returns:
        true if tunnelled end-to-end through at least one proxy, false otherwise
      • getLayerType

        public RouteInfo.LayerType getLayerType()
        Description copied from interface: RouteInfo
        Obtains the layering type of this route. In the presence of proxies, only layering over an end-to-end tunnel is considered.
        Specified by:
        getLayerType in interface RouteInfo
        Returns:
        the layering type
      • isLayered

        public boolean isLayered()
        Description copied from interface: RouteInfo
        Checks whether this route includes a layered protocol. In the presence of proxies, only layering over an end-to-end tunnel is considered.
        Specified by:
        isLayered in interface RouteInfo
        Returns:
        true if layered, false otherwise
      • isSecure

        public boolean isSecure()
        Description copied from interface: RouteInfo
        Checks whether this route is secure.
        Specified by:
        isSecure in interface RouteInfo
        Returns:
        true if secure, false otherwise
      • toRoute

        public HttpRoute toRoute()
        Obtains the tracked route. If a route has been tracked, it is connected. If not connected, nothing has been tracked so far.
        Returns:
        the tracked route, or null if nothing has been tracked so far
      • equals

        public boolean equals​(java.lang.Object o)
        Compares this tracked route to another.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - the object to compare with
        Returns:
        true if the argument is the same tracked route, false
      • hashCode

        public int hashCode()
        Generates a hash code for this tracked route. Route trackers are modifiable and should therefore not be used as lookup keys. Use toRoute to obtain an unmodifiable representation of the tracked route.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code
      • toString

        public java.lang.String toString()
        Obtains a description of the tracked route.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a human-readable representation of the tracked route
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException