com.hazelcast.nio
Interface Connection

All Known Implementing Classes:
ClientConnection, TcpIpConnection

public interface Connection

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


Method Summary
 void close()
          Closes this connection.
 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 still alive.
 boolean isClient()
          Checks if it is a client connection.
 long lastReadTime()
          Returns the clock time of the most recent read using this connection.
 long lastWriteTime()
          Returns the clock time of the most recent write using this connection.
 boolean write(SocketWritable packet)
          Writes a SocketWritable packet to the other side.
 

Method Detail

write

boolean write(SocketWritable packet)
Writes a SocketWritable packet to the other side.

The packet could be stored in an internal queue before it actually is written, so this call doesn't need to be a synchronous call.

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

isAlive

boolean isAlive()
Checks if the Connection is still alive.

Returns:
true if alive, false otherwise.

lastReadTime

long lastReadTime()
Returns the clock time of the most recent read using this connection.

Returns:
the clock time of the most recent read

lastWriteTime

long lastWriteTime()
Returns the clock time of the most recent write using this connection.

Returns:
the clock time of the most recent write.

close

void close()
Closes this connection.

todo: what happens with all pending SocketWritables? Are they flushed, discarded or undefined behavior?

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


getType

ConnectionType getType()
Returns the ConnectionType of this Connection.

Returns:
the ConnectionType. It could be that null is returned.

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.


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.