Class LoopbackUpstreamServer

java.lang.Object
org.omegazero.proxy.net.UpstreamServer
org.omegazero.proxy.net.LoopbackUpstreamServer
All Implemented Interfaces:
Closeable, Serializable, AutoCloseable

public class LoopbackUpstreamServer extends UpstreamServer implements Closeable
Virtual upstream server to locally handle requests, based on LoopbackServer. After creation, init() must be called to create and register the LoopbackServer and client manager instances. Then, getServer() returns the server instance where a connection handler should be added to start serving requests.
Since:
3.11.1
See Also:
  • Constructor Details

    • LoopbackUpstreamServer

      public LoopbackUpstreamServer()
      Creates an LoopbackUpstreamServer instance.
    • LoopbackUpstreamServer

      public LoopbackUpstreamServer(Collection<String> protocols)
      Creates an LoopbackUpstreamServer instance.
      Parameters:
      protocols - The list of protocol names the server supports. If not given or null, the default set is used
  • Method Details

    • init

      public void init()
      Initializes a LoopbackServer and corresponding client manager, and registers the client manager under a unique name in the proxy registry. When this LoopbackUpstreamServer instance is used to serve a request, this client manager will be used to create the virtual loopback connection.

      This method must be called in the proxy onPostInit event or later.

      Throws:
      IllegalStateException - If this method was called already
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • newVirtualInstance

      public LoopbackUpstreamServer newVirtualInstance(int number)
      Creates a new virtual LoopbackUpstreamServer with the same underlying client manager.

      Such an instance can be used to distinguish connections made to the server returned by getServer(). The number parameter of this method will be the destination port number of virtual connections to the server, i.e. the port number in the address returned by the getLocalAddress() method of the received SocketConnection instance.

      Parameters:
      number - The virtual port number
      Returns:
      The new instance
      See Also:
    • getNumber

      public int getNumber()
      Returns the virtual port number of this LoopbackUpstreamServer.

      For derived instances, this is the number given to newVirtualInstance(int). The initial LoopbackUpstreamServer created using the constructor always has number 1.

      This method returns the same value as UpstreamServer.getPlainPort().

      Returns:
      The virtual port number
    • getServer

      public org.omegazero.net.util.LoopbackServer getServer()
      Returns the LoopbackServer instance that receives the internal virtual connections. Use LoopbackServer.setConnectionCallback(java.util.function.Consumer<org.omegazero.net.socket.SocketConnection>) to add a connection handler and start serving requests.
      Returns:
      The server instance
    • toString

      public String toString()
      Overrides:
      toString in class UpstreamServer