Package net.dona.doip.server

# Class DoipServer

java.lang.Object
net.dona.doip.server.DoipServer

public class DoipServer extends Object
A DOIP server. It is constructed via a `DoipServerConfig` and a `DoipProcessor` which determines request-handling logic. The DoipProcessor can be automatically instantiated and managed if not provided to the server on construction in which case the DoipServerConfig must specify the class name of the DoipProcessor. The DOIP server will set up a listener according to the DoipServerConfig, and when requests come in, will pass them to the DoipProcessor to populate the response.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DoipServer(DoipServerConfig config)`
  Constructs a DoipServer.
  `DoipServer(DoipServerConfig config, DoipProcessor doipProcessor)`
  Constructs a DoipServer with a previously instantiated `DoipProcessor`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getPort()`
  `void`
  `init()`
  Initializes the server listener and thread pool and begins serving requests.
  `void`
  `logAccess(String remoteHost, String clientId, String requestId, String operationId, String targetId, String status, Long responseTime)`
  `void`
  `shutdown()`
  Shuts down the server listener and thread pool.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### DoipServer

    public DoipServer(DoipServerConfig config)
    Constructs a DoipServer. The provided configuration must specify a `DoipProcessor` class name via `DoipServerConfig.processorClass` which will be used to instantiate a DoipProcessor when the server's `init()` method is called. The DoipProcessor will be initialized using `DoipServerConfig.processorConfig` and will be shut down along with the server when the server's `shutdown()` method is called.
    Parameters:
      `config` - the server configuration object

  - ### DoipServer

    public DoipServer(DoipServerConfig config, DoipProcessor doipProcessor)
    Constructs a DoipServer with a previously instantiated `DoipProcessor`. The `DoipServerConfig` is used only to determine the properties of the listener. The DoipServer does not call the `DoipProcessor.init(JsonObject)` or `DoipProcessor.shutdown()` methods.
    Parameters:
      `config` - the server configuration object (used for listener properties only)
      `doipProcessor` - a DoipProcessor instance used to handle requests

- ## Method Details

  - ### init

    public void init() throws Exception
    Initializes the server listener and thread pool and begins serving requests. If the `DoipProcessor` was not provided at construction, it will be instantiated and initialized.
    Throws:
      `Exception` - if a new instance of a processor specified by this DoipServer's configuration cannot be constructed, or if a server socket cannot be initialized

  - ### getPort

    public int getPort()

  - ### logAccess

    public void logAccess(String remoteHost, String clientId, String requestId, String operationId, String targetId, String status, Long responseTime)

  - ### shutdown

    public void shutdown()
    Shuts down the server listener and thread pool. If the `DoipProcessor` was not provided at construction but was instead instantiated by `init()`, it will be shut down here.