Class Proxy

java.lang.Object
org.omegazero.proxy.core.Proxy
All Implemented Interfaces:
org.omegazero.common.runtime.Application

public final class Proxy extends Object implements org.omegazero.common.runtime.Application
The main class of omz-proxy.
  • Field Details

  • Constructor Details

    • Proxy

      public Proxy()
  • Method Details

    • start

      public void start(org.omegazero.common.util.Args args) throws Exception
      Specified by:
      start in interface org.omegazero.common.runtime.Application
      Throws:
      Exception
    • init

      public void init(org.omegazero.common.util.Args args) throws IOException
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface org.omegazero.common.runtime.Application
      Throws:
      IOException
    • shutdown

      public void shutdown()
    • registerServerInstance

      @Deprecated public void registerServerInstance(Class<? extends org.omegazero.net.server.NetServer> c)
      Deprecated.
      Since 3.9.1, use getRegistry().registerServerInstance(c) instead
      Registers a new NetServer instance of the given type.

      A new instance of the given type is created and registered using registerServerInstance(NetServer). This requires that the given type has a constructor with no parameters. If the type requires additional arguments in the constructor, use Proxy.registerServerInstance(NetServer) directly instead.

      Parameters:
      c -
    • registerServerInstance

      @Deprecated public void registerServerInstance(org.omegazero.net.server.NetServer server)
      Deprecated.
      Registers a new NetServer instance. The instance is added to the list of registered instances and will be initialized at the beginning of the main initialization phase, meaning server instances must be registered during the ProxyEvents.PREINIT event.
      Parameters:
      server -
    • addHTTPEngineSelector

      @Deprecated public void addHTTPEngineSelector(Function<org.omegazero.net.socket.SocketConnection,Class<? extends HTTPEngine>> selector)
      Deprecated.
      Since 3.9.1, use getRegistry().
      invalid reference
      addHTTPEngineSelector(selector)
      instead
      Registers a new HTTPEngine selector.

      For incoming connections, an appropriate HTTPEngine must be selected. For this, every registered selector is called until one returns a non-null value, which will be the HTTPEngine used for the connection. If all selectors return null, an UnsupportedOperationException is thrown and the connection will be closed.

      Parameters:
      selector -
    • registerClientManager

      @Deprecated public void registerClientManager(org.omegazero.net.client.NetClientManager mgr)
      Deprecated.
      Since 3.7.1, use registerClientManager(String, NetClientManager). This method uses the full class name for the id parameter.
      Registers a new NetClientManager for outgoing connections.
      Parameters:
      mgr - The client manager
    • registerClientManager

      @Deprecated public void registerClientManager(String id, org.omegazero.net.client.NetClientManager mgr)
      Deprecated.
      Registers a new NetClientManager for outgoing connections.
      Parameters:
      id - The identifier for the client manager
      mgr - The client manager
      Since:
      3.7.1
    • reloadConfiguration

      public void reloadConfiguration() throws IOException
      Reloads the configuration from the configuration file and pushes the new configuration data to plugins.

      If no configuration file was used, this method does nothing.

      Throws:
      IOException
    • connection

      @Deprecated public org.omegazero.net.socket.SocketConnection connection(Class<? extends org.omegazero.net.client.NetClientManager> type, org.omegazero.net.client.params.ConnectionParameters parameters) throws IOException
      Deprecated.
      Since 3.7.1, use
      invalid reference
      #connection(String, ConnectionParameters)
      . This method uses the full class name of the given type as the cmid parameter.
      Creates a new connection instance for an outgoing proxy connection.
      Parameters:
      type - The NetClientManager type to use for this connection
      parameters - Parameters for this connection
      Returns:
      The new connection instance
      Throws:
      IOException
      IllegalArgumentException - If an NetClientManager type was given for which there is no active instance
      See Also:
      • NetClientManager.connection(ConnectionParameters)
    • connection

      public org.omegazero.net.socket.SocketConnection connection(String cmid, org.omegazero.net.client.params.ConnectionParameters parameters, org.omegazero.net.socket.SocketConnection downstreamConnection) throws IOException
      Creates a new connection instance for an outgoing proxy connection.
      Parameters:
      cmid - The client manager ID passed in registerClientManager(String, NetClientManager)
      parameters - Parameters for this connection
      downstreamConnection - The downstream connection, if available. Used to set the worker instance used for the new connection
      Returns:
      The new connection instance
      Throws:
      IOException
      IllegalArgumentException - If cmid is invalid
      Since:
      3.7.1
      See Also:
      • NetClientManager.connection(ConnectionParameters)
    • dispatchEvent

      public int dispatchEvent(org.omegazero.common.eventbus.Event event, Object... args)
      Delegates the given event to this proxy's EventBus.
      Parameters:
      event - The event to dispatch using this proxy's event bus
      args - The arguments to pass the event handlers
      Returns:
      The number of handlers executed
      See Also:
      • EventBus.dispatchEvent(Event, Object...)
    • dispatchEventRes

      public org.omegazero.common.eventbus.EventResult dispatchEventRes(org.omegazero.common.eventbus.Event event, Object... args)
      Delegates the given event to this proxy's EventBus.
      Parameters:
      event - The event to dispatch using this proxy's event bus
      args - The arguments to pass the event handlers
      Returns:
      An EventResult object containing information about this event execution
      See Also:
      • EventBus.dispatchEventRes(Event, Object...)
    • dispatchBooleanEvent

      public boolean dispatchBooleanEvent(org.omegazero.common.eventbus.Event event, boolean def, Object... args)
      Delegates the given event to this proxy's EventBus and returns a boolean value returned by the event handlers.

      If Event.isIncludeAllReturns() is false, the return value of the first event handler that returns a non-null value is returned. If all event handlers return null or there are none, def will be returned.
      Otherwise, if includeAllReturns is true, all event handlers will be executed and the value of def is returned if all event handlers return either null or the same value as def. Otherwise, the return value of the first event handler is returned that does not match the def value.

      Parameters:
      event - The event to dispatch using this proxy's event bus
      def - The value to return if all event handlers return null or there are none
      args - The arguments to pass the event handlers
      Returns:
      The boolean value returned by the first event handler that returns a non-null value, or def
    • debugStringForConnection

      public String debugStringForConnection(org.omegazero.net.socket.SocketConnection incoming, org.omegazero.net.socket.SocketConnection outgoing)
    • getState

      public State getState()
    • isRunning

      public boolean isRunning()
    • getConfig

      public ProxyConfiguration getConfig()
    • getInstanceType

      public String getInstanceType()
    • setInstanceType

      public void setInstanceType(String instanceType)
    • getInstanceVersion

      public String getInstanceVersion()
    • setInstanceVersion

      public void setInstanceVersion(String instanceVersion)
    • getInstanceNameAppendage

      public String getInstanceNameAppendage()
    • setInstanceNameAppendage

      public void setInstanceNameAppendage(String instanceNameAppendage)
    • getInstanceName

      public String getInstanceName()
    • isPluginLoaded

      public boolean isPluginLoaded(String id)
      Checks whether a plugins with the given id is loaded.
      Parameters:
      id - The id of the plugin to search for
      Returns:
      true if a plugin with the given id exists
    • getSslContext

      public SSLContext getSslContext()
      Returns the SSLContext for this proxy
      Returns:
      The configured SSL context for this proxy
    • getServerWorkerProvider

      public Proxy.ApplicationWorkerProvider getServerWorkerProvider()
      Returns the Proxy.ApplicationWorkerProvider for use by plugins for long-running tasks.
      Returns:
      The ApplicationWorkerProvider
    • getSessionWorkerProvider

      public Proxy.SessionWorkerProvider getSessionWorkerProvider(org.omegazero.net.socket.SocketConnection client)
      Returns a Proxy.SessionWorkerProvider for the given client connection. This method may be passed as a method reference to a NetworkApplicationBuilder as the worker creator.
      Parameters:
      client - The client connection
      Returns:
      The SessionWorkerProvider
      Since:
      3.7.1
    • getErrdoc

      public HTTPErrdoc getErrdoc(String type)
      Parameters:
      type - The MIME type of the error document
      Returns:
      A HTTPErrdoc instance of the given MIME type or the default error document if none was found
    • getDefaultErrdoc

      public HTTPErrdoc getDefaultErrdoc()
      Returns:
      The default error document
    • getErrdocForAccept

      public HTTPErrdoc getErrdocForAccept(String accept)
      Parameters:
      accept - The value of an Accept HTTP header
      Returns:
      A suitable HTTPErrdoc, or the default errdoc if none was found
      Since:
      3.3.1
      See Also:
    • setErrdoc

      @Deprecated public void setErrdoc(String type, HTTPErrdoc errdoc)
      Deprecated.
      Since 3.9.1, use getRegistry().setErrdoc(type, errdoc) instead
      Sets an error document for the given MIME type.
      Parameters:
      type - The content type to set this error document for
      errdoc - The HTTPErrdoc instance
    • getConnectionIdleTimeout

      public int getConnectionIdleTimeout()
      Returns the amount of time in seconds a connection with no traffic should persist before it is closed.
      Returns:
      The time in seconds
    • getDefaultUpstreamServer

      public UpstreamServer getDefaultUpstreamServer()
      Returns the default upstream server configured in the configuration file. May be null.
      Returns:
      The default upstream server
    • getUpstreamServer

      @Deprecated public UpstreamServer getUpstreamServer(String host, String path)
      Deprecated.
      Since 3.9.1, this method always returns the value returned by getDefaultUpstreamServer(). The selectUpstreamServer event was replaced by onHTTPRequestSelectServer
      Selects an upstream server based on the given hostname and path.

      This method uses the EventBus event selectUpstreamServer. If all event handlers return null, the default upstream server, which may also be null, is selected.

      Parameters:
      host - The hostname to choose a server for
      path - The request path
      Returns:
      The UpstreamServer instance for the given host, or null if no appropriate server was found
    • getRegistry

      public ProxyRegistry getRegistry()
      Returns the ProxyRegistry for this proxy.
      Returns:
      The registry
      Since:
      3.9.1
    • getInstance

      public static Proxy getInstance()
      Returns the currently active instance of Proxy, or null if there is none.
      Returns:
      The instance
    • getVersion

      public static String getVersion()
      Returns the version string of omz-proxy.
      Returns:
      The version string
      Since:
      3.7.1
    • getServerWorker

      public static org.omegazero.common.event.DelegatingTaskQueueExecutor getServerWorker()
      Returns the TaskQueueExecutor used to execute asynchronous tasks.

      Plugins and other external components SHOULD NOT use this method to queue asynchronous tasks, but use Proxy.getInstance().getServerWorkerProvider() instead.

      Returns:
      The TaskQueueExecutor
      Since:
      3.10.3