com.hazelcast.client.connection.nio

## Class ClientConnection

- java.lang.Object
- - com.hazelcast.client.connection.nio.ClientConnection

- All Implemented Interfaces:
    Connection

      public class ClientConnection
      extends Object
      implements Connection

  Client implementation of `Connection`. ClientConnection is a connection between a Hazelcast Client and a Hazelcast Member.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClientConnection(com.hazelcast.client.impl.HazelcastClientInstanceImpl client, int connectionId)`
    `ClientConnection(com.hazelcast.client.impl.HazelcastClientInstanceImpl client, int connectionId, com.hazelcast.internal.networking.Channel channel)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close(String reason, Throwable cause)` Closes this connection.
    `void` | `decrementPendingPacketCount()`
    `boolean` | `equals(Object o)`
    `Throwable` | `getCloseCause()` Gets the cause this Connection was closed.
    `long` | `getClosedTime()` Closed time is the first time connection.close called.
    `String` | `getCloseReason()` Gets the reason this Connection was closed.
    `int` | `getConnectedServerVersion()`
    `String` | `getConnectedServerVersionString()`
    `ClientConnectionManager` | `getConnectionManager()`
    `Address` | `getEndPoint()` Gets the `Address` of the other side of this Connection.
    `InetAddress` | `getInetAddress()` Returns remote address of this Connection.
    `InetSocketAddress` | `getLocalSocketAddress()`
    `int` | `getPendingPacketCount()`
    `int` | `getPort()` The remote port.
    `InetSocketAddress` | `getRemoteSocketAddress()` Returns the address of the endpoint this Connection is connected to, or `null` if it is unconnected.
    `long` | `getStartTime()`
    `ConnectionType` | `getType()` Returns the `ConnectionType` of this Connection.
    `void` | `handleClientMessage(com.hazelcast.client.impl.protocol.ClientMessage message)`
    `int` | `hashCode()`
    `void` | `incrementPendingPacketCount()`
    `protected void` | `innerClose()`
    `boolean` | `isAlive()` Checks if the Connection is alive.
    `boolean` | `isAuthenticatedAsOwner()`
    `boolean` | `isClient()` Checks if it is a client connection.
    `boolean` | `isHeartBeating()`
    `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` | `setConnectedServerVersion(String connectedServerVersion)`
    `void` | `setIsAuthenticatedAsOwner()`
    `void` | `setRemoteEndpoint(Address remoteEndpoint)`
    `void` | `setType(ConnectionType type)` Sets the type of the connection
    `String` | `toString()`
    `boolean` | `write(com.hazelcast.internal.networking.OutboundFrame frame)` Writes a outbound frame so it can be received by the other side of the connection.

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ClientConnection

          public ClientConnection(com.hazelcast.client.impl.HazelcastClientInstanceImpl client,
                                  int connectionId,
                                  com.hazelcast.internal.networking.Channel channel)

    - #### ClientConnection

          public ClientConnection(com.hazelcast.client.impl.HazelcastClientInstanceImpl client,
                                  int connectionId)

  - ### Method Detail

    - #### incrementPendingPacketCount

          public void incrementPendingPacketCount()

    - #### decrementPendingPacketCount

          public void decrementPendingPacketCount()

    - #### getPendingPacketCount

          public int getPendingPacketCount()

    - #### write

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

      Description copied from interface: `Connection`
      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.

      Specified by:
        `write` in interface `Connection`
      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.

    - #### getEndPoint

          public Address getEndPoint()

      Description copied from interface: `Connection`
      Gets the `Address` of the other side of this Connection.

      todo: rename to get remoteAddress?

      Specified by:
        `getEndPoint` in interface `Connection`
      Returns:
        the Address.

    - #### isAlive

          public boolean isAlive()

      Description copied from interface: `Connection`
      Checks if the Connection is alive.
      Specified by:
        `isAlive` in interface `Connection`
      Returns:
        true if alive, false otherwise.

    - #### lastReadTimeMillis

          public long lastReadTimeMillis()

      Description copied from interface: `Connection`
      Returns the clock time in milliseconds of the most recent read using this connection.
      Specified by:
        `lastReadTimeMillis` in interface `Connection`
      Returns:
        the clock time of the most recent read

    - #### lastWriteTimeMillis

          public long lastWriteTimeMillis()

      Description copied from interface: `Connection`
      Returns the clock time in milliseconds of the most recent write using this connection.
      Specified by:
        `lastWriteTimeMillis` in interface `Connection`
      Returns:
        the clock time of the most recent write.

    - #### setType

          public void setType(ConnectionType type)

      Description copied from interface: `Connection`
      Sets the type of the connection
      Specified by:
        `setType` in interface `Connection`
      Parameters:
        `type` - to be set

    - #### getType

          public ConnectionType getType()

      Description copied from interface: `Connection`
      Returns the `ConnectionType` of this Connection.
      Specified by:
        `getType` in interface `Connection`
      Returns:
        the ConnectionType. It could be that `null` is returned.

    - #### isClient

          public boolean isClient()

      Description copied from interface: `Connection`
      Checks if it is a client connection.
      Specified by:
        `isClient` in interface `Connection`
      Returns:
        true if client connection, false otherwise.

    - #### getInetAddress

          public InetAddress getInetAddress()

      Description copied from interface: `Connection`
      Returns remote address of this Connection.
      Specified by:
        `getInetAddress` in interface `Connection`
      Returns:
        the remote address. The returned value could be `null` if the connection is not alive.

    - #### getRemoteSocketAddress

          public InetSocketAddress getRemoteSocketAddress()

      Description copied from interface: `Connection`
      Returns the address of the endpoint this Connection is connected to, or `null` if it is unconnected.
      Specified by:
        `getRemoteSocketAddress` in interface `Connection`
      Returns:
        address of the endpoint.

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

    - #### getPort

          public int getPort()

      Description copied from interface: `Connection`
      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

      Specified by:
        `getPort` in interface `Connection`
      Returns:
        the remote port number to which this Connection is connected, or 0 if the socket is not connected yet.

    - #### getConnectionManager

          public ClientConnectionManager getConnectionManager()

    - #### setRemoteEndpoint

          public void setRemoteEndpoint(Address remoteEndpoint)

    - #### getLocalSocketAddress

          public InetSocketAddress getLocalSocketAddress()

    - #### close

          public void close(String reason,
                            Throwable cause)

      Description copied from interface: `Connection`
      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.

      Specified by:
        `close` in interface `Connection`
      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.

    - #### innerClose

          protected void innerClose()
                             throws IOException

      Throws:
        `IOException`

    - #### getCloseCause

          public Throwable getCloseCause()

      Description copied from interface: `Connection`
      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.
      Specified by:
        `getCloseCause` in interface `Connection`
      Returns:
        the cause of closing this connection.
      See Also:
        `()`, `Connection.close(String, Throwable)`

    - #### getCloseReason

          public String getCloseReason()

      Description copied from interface: `Connection`
      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.
      Specified by:
        `getCloseReason` in interface `Connection`
      Returns:
        the reason this connection was closed.
      See Also:
        `Connection.getCloseCause()`, `Connection.close(String, Throwable)`

    - #### handleClientMessage

          public void handleClientMessage(com.hazelcast.client.impl.protocol.ClientMessage message)

    - #### isHeartBeating

          public boolean isHeartBeating()

    - #### isAuthenticatedAsOwner

          public boolean isAuthenticatedAsOwner()

    - #### setIsAuthenticatedAsOwner

          public void setIsAuthenticatedAsOwner()

    - #### getStartTime

          public long getStartTime()

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getClosedTime

          public long getClosedTime()

      Closed time is the first time connection.close called.
      Returns:
        the closed time of connection, returns zero if not closed yet

    - #### setConnectedServerVersion

          public void setConnectedServerVersion(String connectedServerVersion)

    - #### getConnectedServerVersion

          public int getConnectedServerVersion()

    - #### getConnectedServerVersionString

          public String getConnectedServerVersionString()

Copyright © 2018. All rights reserved.