com.hazelcast.nio

## Interface Connection

- All Known Implementing Classes:
    ClientConnection, TcpIpConnection

      @PrivateApi
      public interface Connection

  Represents a 'connection' between two machines. The most important implementation is the `TcpIpConnection`.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close(String reason, Throwable cause)` Closes this connection.
    `Throwable` | `getCloseCause()` Gets the cause this Connection was closed.
    `String` | `getCloseReason()` Gets the reason this Connection was closed.
    `Address` | `getEndPoint()` Gets the `Address` of the other side of this Connection.
    `InetAddress` | `getInetAddress()` Returns remote address of this Connection.
    `int` | `getPort()` The remote port.
    `InetSocketAddress` | `getRemoteSocketAddress()` Returns the address of the endpoint this Connection is connected to, or `null` if it is unconnected.
    `ConnectionType` | `getType()` Returns the `ConnectionType` of this Connection.
    `boolean` | `isAlive()` Checks if the Connection is alive.
    `boolean` | `isClient()` Checks if it is a client connection.
    `long` | `lastReadTimeMillis()` Returns the clock time in milliseconds of the most recent read using this connection.
    `long` | `lastWriteTimeMillis()` Returns the clock time in milliseconds of the most recent write using this connection.
    `void` | `setType(ConnectionType type)` Sets the type of the connection
    `boolean` | `write(com.hazelcast.internal.networking.OutboundFrame frame)` Writes a outbound frame so it can be received by the other side of the connection.

- - ### Method Detail

    - #### isAlive

          boolean isAlive()

      Checks if the Connection is alive.
      Returns:
        true if alive, false otherwise.

    - #### lastReadTimeMillis

          long lastReadTimeMillis()

      Returns the clock time in milliseconds of the most recent read using this connection.
      Returns:
        the clock time of the most recent read

    - #### lastWriteTimeMillis

          long lastWriteTimeMillis()

      Returns the clock time in milliseconds of the most recent write using this connection.
      Returns:
        the clock time of the most recent write.

    - #### getType

          ConnectionType getType()

      Returns the `ConnectionType` of this Connection.
      Returns:
        the ConnectionType. It could be that `null` is returned.

    - #### setType

          void setType(ConnectionType type)

      Sets the type of the connection
      Parameters:
        `type` - to be set

    - #### isClient

          boolean isClient()

      Checks if it is a client connection.
      Returns:
        true if client connection, false otherwise.

    - #### getInetAddress

          InetAddress getInetAddress()

      Returns remote address of this Connection.
      Returns:
        the remote address. The returned value could be `null` if the connection is not alive.

    - #### getRemoteSocketAddress

          InetSocketAddress getRemoteSocketAddress()

      Returns the address of the endpoint this Connection is connected to, or `null` if it is unconnected.
      Returns:
        address of the endpoint.

        todo: do we really need this method because we have getInetAddress, InetSocketAddress and getEndPoint.

    - #### getEndPoint

          Address getEndPoint()

      Gets the `Address` of the other side of this Connection.

      todo: rename to get remoteAddress?

      Returns:
        the Address.

    - #### getPort

          int getPort()

      The remote port.

      todo: rename to getRemotePort? And do we need it because we already have getEndPoint which returns an address which includes port. It is only used in testing

      Returns:
        the remote port number to which this Connection is connected, or 0 if the socket is not connected yet.

    - #### write

          boolean write(com.hazelcast.internal.networking.OutboundFrame frame)

      Writes a outbound frame so it can be received by the other side of the connection. No guarantees are made that the frame is going to be received on the other side.

      The frame could be stored in an internal queue before it actually is written, so this call does not need to be a synchronous call.

      Parameters:
        `frame` - the frame to write.
      Returns:
        false if the frame was not accepted to be written, e.g. because the Connection was not alive.
      Throws:
        `NullPointerException` - if frame is null.

    - #### close

          void close(String reason,
                     Throwable cause)

      Closes this connection.

      Pending packets on this connection are discarded

      If the Connection is already closed, the call is ignored. So it can safely be called multiple times.

      Parameters:
        `reason` - the reason this connection is going to be closed. Is allowed to be null.
        `cause` - the Throwable responsible for closing this connection. Is allowed to be null.

    - #### getCloseReason

          String getCloseReason()

      Gets the reason this Connection was closed. Can be null if no reason was given or if the connection is still active. It is purely meant for debugging to shed some light on why connections are closed. This method is thread-safe and can be called at any moment. If the connection is closed and no reason is available, it is very likely that the close cause does contain the reason of closing.
      Returns:
        the reason this connection was closed.
      See Also:
        `getCloseCause()`, `close(String, Throwable)`

    - #### getCloseCause

          Throwable getCloseCause()

      Gets the cause this Connection was closed. Can be null if no cause was given or if the connection is still active. It is purely meant for debugging to shed some light on why connections are closed. This method is thread-safe and can be called at any moment.
      Returns:
        the cause of closing this connection.
      See Also:
        `()`, `close(String, Throwable)`

Copyright © 2018. All rights reserved.