Class UpstreamServer

java.lang.Object
org.omegazero.proxy.net.UpstreamServer
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
LoopbackUpstreamServer

public class UpstreamServer extends Object implements Serializable
Contains information about another server where requests can be forwarded to.
See Also:
  • Field Details

    • PROTOCOLS_DEFAULT

      public static final Collection<String> PROTOCOLS_DEFAULT
      An immutable collection containing the single default supported procotol, HTTP/1.1, used if no protocols are passed in the constructor.
    • PROTOCOLS_ALL

      public static final Collection<String> PROTOCOLS_ALL
      An immutable collection representing support for all protocols.
    • LOCALHOST_IPV4

      public static final InetAddress LOCALHOST_IPV4
      Contains the IPv4 localhost address 127.0.0.1.
      Since:
      3.11.1
    • LOCALHOST_IPV6

      public static final InetAddress LOCALHOST_IPV6
      Contains the IPv6 localhost address ::1.
      Since:
      3.11.1
    • addressNegativeTTL

      public static final int addressNegativeTTL
      The amount of seconds to wait for a retry when an attempt to re-resolve an address, after its TTL expired, fails. If -1 (the default), the same as the (positive) TTL configured for an UpstreamServer.
      Since:
      3.10.3
  • Constructor Details

    • UpstreamServer

      public UpstreamServer()
      Creates an UpstreamServer instance with no parameters set, and protocols set to PROTOCOLS_ALL.

      This may be used by plugins to create "virtual" upstream servers, where the plugin returns this instance of an UpstreamServer in selectUpstreamServer and then responds to requests with that upstream server. When an UpstreamServer with address set to null is selected for a request, all request events are run normally as if the request is being proxied, but no upstream connection actually exists. Any handler must respond in the onHTTPRequestEnded event or before, otherwise an error is returned.

      Since:
      3.7.2
    • UpstreamServer

      public UpstreamServer(InetAddress address, int plainPort, int securePort)
      Creates an UpstreamServer instance.
      Parameters:
      address - The address of the server
      plainPort - The port on which the server listens for plaintext connections. -1 means there is no such port
      securePort - The port on which the server listens for encrypted connections. -1 means there is no such port
    • UpstreamServer

      public UpstreamServer(InetAddress address, int plainPort, int securePort, Collection<String> protocols)
      Creates an UpstreamServer instance.
      Parameters:
      address - The address of the server
      plainPort - The port on which the server listens for plaintext connections. -1 means there is no such port
      securePort - The port on which the server listens for encrypted connections. -1 means there is no such port
      protocols - The list of protocol names the server supports
      Since:
      3.3.1
    • UpstreamServer

      public UpstreamServer(InetAddress address, int addressTTL, int plainPort, int securePort, Collection<String> protocols)
      Creates an UpstreamServer instance.
      Parameters:
      address - The address of the server
      addressTTL - The time in seconds to cache a resolved address. See getAddressTTL()
      plainPort - The port on which the server listens for plaintext connections. -1 means there is no such port
      securePort - The port on which the server listens for encrypted connections. -1 means there is no such port
      protocols - The list of protocol names the server supports. If null, the default set is used
      Since:
      3.4.1
    • UpstreamServer

      public UpstreamServer(InetAddress address, int addressTTL, int plainPort, int securePort, Collection<String> protocols, String clientImplOverride)
      Creates an UpstreamServer instance.
      Parameters:
      address - The address of the server
      addressTTL - The time in seconds to cache a resolved address. See getAddressTTL()
      plainPort - The port on which the server listens for plaintext connections. -1 means there is no such port
      securePort - The port on which the server listens for encrypted connections. -1 means there is no such port
      protocols - The list of protocol names the server supports. If null, the default set is used
      clientImplOverride - If not null, overrides the client manager namespace to use to connect to this server
      Since:
      3.10.2
    • UpstreamServer

      public UpstreamServer(InetAddress address, int addressTTL, InetAddress localAddress, int plainPort, int securePort, Collection<String> protocols, String clientImplOverride)
      Creates an UpstreamServer instance.
      Parameters:
      address - The address of the server
      addressTTL - The time in seconds to cache a resolved address. See getAddressTTL()
      localAddress - The local address to use to connect to the server
      plainPort - The port on which the server listens for plaintext connections. -1 means there is no such port
      securePort - The port on which the server listens for encrypted connections. -1 means there is no such port
      protocols - The list of protocol names the server supports. If null, the default set is used
      clientImplOverride - If not null, overrides the client manager namespace to use to connect to this server
      Throws:
      IllegalArgumentException - If address and localAddress are both given but they do not have the same type
      Since:
      3.10.4
  • Method Details

    • getAddress

      public InetAddress getAddress()
      Returns the address of this UpstreamServer. May be null.

      If addressTTL was set in the constructor, this method may re-resolve the configured address if necessary.

      Returns:
      The address of this UpstreamServer
    • getLocalAddress

      public InetAddress getLocalAddress()
      Returns the local address of this UpstreamServer. May be null.
      Returns:
      The local address to use to connect to this UpstreamServer
      Since:
      3.10.4
    • getAddressTTL

      public int getAddressTTL()
      Returns the number of seconds to cache a resolved InetAddress. After this time expires, the address is re-resolved using InetAddress.getByName(java.lang.String). -1 means there is no timeout. Note that the InetAddress implementation may also cache name resolutions internally (see InetAddress).

      This only applies to the remote address.

      Returns:
      The address TTL in seconds
    • getPlainPort

      public int getPlainPort()
      Returns the port on which this UpstreamServer listens for plaintext connections. -1 means there is no such port.
      Returns:
      The plaintext port
    • getSecurePort

      public int getSecurePort()
      Returns the port on which this UpstreamServer listens for encrypted connections. -1 means there is no such port.
      Returns:
      The encrypted port
    • isProtocolSupported

      public boolean isProtocolSupported(String proto)
      Returns true if this UpstreamServer was configured to support the given protocol name.
      Parameters:
      proto - The name of the protocol
      Returns:
      true if the given protocol is supported
      Since:
      3.3.1
    • getSupportedProcotols

      public Collection<String> getSupportedProcotols()
      Returns the unmodifiable list of protocol names this UpstreamServer supports, in the order of preference (from high to low).

      This list may be identity equal to PROTOCOLS_ALL (containing a null element), indicating this UpstreamServer was configured to support all protocols.

      Returns:
      The list of procotols
      Since:
      3.9.1
    • getClientImplOverride

      public String getClientImplOverride()
      Returns an override for the client manager namespace to use to connect to this server. If null, the default implementation should be used.
      Returns:
      ID of the client manager
      Since:
      3.10.2
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object