Package de.gebit.integrity.remoting.transport

## Class Endpoint

- java.lang.Object
- - de.gebit.integrity.remoting.transport.Endpoint

-     public class Endpoint
      extends Object

  An endpoint is a client- or serverside termination point of a message channel. The endpoint uses a TCP connection to transmit messages bidirectionally, with processors waiting for new messages to arrive.
  Author:
    Rene Schneider - initial API and implementation

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Endpoint​(String aHost, int aPort, Map<Class<? extends AbstractMessage>,​MessageProcessor<?>> aProcessorMap, EndpointListener aListener, ClassLoader aClassLoader)` | Creates a new endpoint and connects to a remote host, on which a `ServerEndpoint` is expected to run.
    `Endpoint​(Socket aSocket, Map<Class<? extends AbstractMessage>,​MessageProcessor<?>> aProcessorMap, EndpointListener aListener, ClassLoader aClassLoader)` | Creates a new endpoint from a specific, already-connected socket.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `close​(boolean anEmptyOutputQueueFlag)` | Close the connection.
    `protected com.esotericsoftware.kryo.Kryo` | `instantiateKryo()` | Instantiates the Kryo serialization framework.
    `boolean` | `isActive()` |
    `boolean` | `isDisconnectRequested()` |
    `void` | `sendMessage​(AbstractMessage aMessage)` | Sends a message.

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

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

- - ### Constructor Detail

    - #### Endpoint

          public Endpoint​(Socket aSocket,
                          Map<Class<? extends AbstractMessage>,​MessageProcessor<?>> aProcessorMap,
                          EndpointListener aListener,
                          ClassLoader aClassLoader)

      Creates a new endpoint from a specific, already-connected socket.
      Parameters:
        `aSocket` - the connected socket
        `aProcessorMap` - the processors
        `aListener` - the listener
        `aClassLoader` - the classloader to use when deserializing objects

    - #### Endpoint

          public Endpoint​(String aHost,
                          int aPort,
                          Map<Class<? extends AbstractMessage>,​MessageProcessor<?>> aProcessorMap,
                          EndpointListener aListener,
                          ClassLoader aClassLoader)
                   throws UnknownHostException,
                          IOException

      Creates a new endpoint and connects to a remote host, on which a `ServerEndpoint` is expected to run.
      Parameters:
        `aHost` - the host name or IP
        `aPort` - the port to connect to
        `aProcessorMap` - the map of processors
        `aListener` - the listener
        `aClassLoader` - the classloader to use when deserializing objects
      Throws:
        `UnknownHostException`
        `IOException`

  - ### Method Detail

    - #### sendMessage

          public void sendMessage​(AbstractMessage aMessage)

      Sends a message. This queues the message into the outqueue, which is then emptied asynchronously by the `outputProcessor`.
      Parameters:
        `aMessage` - the message to send

    - #### isActive

          public boolean isActive()

    - #### isDisconnectRequested

          public boolean isDisconnectRequested()

    - #### close

          public void close​(boolean anEmptyOutputQueueFlag)

      Close the connection.
      Parameters:
        `anEmptyOutputQueueFlag` - whether the output queue shall be sent to the other endpoint before closing

    - #### instantiateKryo

          protected com.esotericsoftware.kryo.Kryo instantiateKryo()

      Instantiates the Kryo serialization framework.
      Returns:
        an instantiated and fully configured `Kryo` instance