Package org.omegazero.proxy.net
Class LoopbackUpstreamServer
java.lang.Object
org.omegazero.proxy.net.UpstreamServer
org.omegazero.proxy.net.LoopbackUpstreamServer
- All Implemented Interfaces:
Closeable,Serializable,AutoCloseable
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:
-
Field Summary
Fields inherited from class org.omegazero.proxy.net.UpstreamServer
addressNegativeTTL, LOCALHOST_IPV4, LOCALHOST_IPV6, PROTOCOLS_ALL, PROTOCOLS_DEFAULT -
Constructor Summary
ConstructorsConstructorDescriptionCreates anLoopbackUpstreamServerinstance.LoopbackUpstreamServer(Collection<String> protocols) Creates anLoopbackUpstreamServerinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()intReturns the virtual port number of thisLoopbackUpstreamServer.org.omegazero.net.util.LoopbackServerReturns theLoopbackServerinstance that receives the internal virtual connections.voidinit()Initializes aLoopbackServerand corresponding client manager, and registers the client manager under a unique name in the proxy registry.newVirtualInstance(int number) Creates a new virtualLoopbackUpstreamServerwith the same underlying client manager.toString()Methods inherited from class org.omegazero.proxy.net.UpstreamServer
equals, getAddress, getAddressTTL, getClientImplOverride, getLocalAddress, getPlainPort, getSecurePort, getSupportedProcotols, hashCode, isProtocolSupported
-
Constructor Details
-
LoopbackUpstreamServer
public LoopbackUpstreamServer()Creates anLoopbackUpstreamServerinstance. -
LoopbackUpstreamServer
Creates anLoopbackUpstreamServerinstance.- Parameters:
protocols- The list of protocol names the server supports. If not given ornull, the default set is used
-
-
Method Details
-
init
public void init()Initializes aLoopbackServerand corresponding client manager, and registers the client manager under a unique name in the proxy registry. When thisLoopbackUpstreamServerinstance 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
onPostInitevent or later.- Throws:
IllegalStateException- If this method was called already
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
newVirtualInstance
Creates a new virtualLoopbackUpstreamServerwith the same underlying client manager.Such an instance can be used to distinguish connections made to the server returned by
getServer(). Thenumberparameter 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 thegetLocalAddress()method of the receivedSocketConnectioninstance.- Parameters:
number- The virtual port number- Returns:
- The new instance
- See Also:
-
getNumber
public int getNumber()Returns the virtual port number of thisLoopbackUpstreamServer.For derived instances, this is the number given to
newVirtualInstance(int). The initialLoopbackUpstreamServercreated 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 theLoopbackServerinstance that receives the internal virtual connections. UseLoopbackServer.setConnectionCallback(java.util.function.Consumer<org.omegazero.net.socket.SocketConnection>)to add a connection handler and start serving requests.- Returns:
- The server instance
-
toString
- Overrides:
toStringin classUpstreamServer
-