com.hazelcast.nio.tcp
Class TcpIpConnection

java.lang.Object
  extended by com.hazelcast.nio.tcp.TcpIpConnection
All Implemented Interfaces:
Connection

public final class TcpIpConnection
extends Object
implements Connection

The Tcp/Ip implementation of the Connection. A Connection has 2 sides:

  1. the side where it receives data from the remote machine
  2. the side where it sends data to the remote machine
The reading side is the ReadHandler and the writing side of this connection is the WriteHandler.


Constructor Summary
TcpIpConnection(TcpIpConnectionManager connectionManager, IOSelector in, IOSelector out, int connectionId, SocketChannelWrapper socketChannel)
           
 
Method Summary
 void close()
          Closes this connection.
 void close(Throwable t)
           
 boolean equals(Object o)
           
 int getConnectionId()
           
 TcpIpConnectionManager getConnectionManager()
           
 Address getEndPoint()
          Gets the Address of the other side of this Connection.
 InetAddress getInetAddress()
          Returns remote address of this Connection.
 TcpIpConnectionMonitor getMonitor()
           
 int getPort()
          The remote port.
 com.hazelcast.nio.tcp.ReadHandler getReadHandler()
           
 InetSocketAddress getRemoteSocketAddress()
          Returns the address of the endpoint this Connection is connected to, or null if it is unconnected.
 SocketChannelWrapper getSocketChannelWrapper()
           
 ConnectionType getType()
          Returns the ConnectionType of this Connection.
 WriteHandler getWriteHandler()
           
 int hashCode()
           
 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.
 void setEndPoint(Address endPoint)
           
 void setMonitor(TcpIpConnectionMonitor monitor)
           
 void setType(ConnectionType type)
           
 String toString()
           
 boolean write(SocketWritable packet)
          Writes a SocketWritable packet to the other side.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TcpIpConnection

public TcpIpConnection(TcpIpConnectionManager connectionManager,
                       IOSelector in,
                       IOSelector out,
                       int connectionId,
                       SocketChannelWrapper socketChannel)
Method Detail

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.

getConnectionManager

public TcpIpConnectionManager getConnectionManager()

write

public boolean write(SocketWritable packet)
Description copied from interface: Connection
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.

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

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.

setType

public void setType(ConnectionType type)

getSocketChannelWrapper

public SocketChannelWrapper getSocketChannelWrapper()

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.

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.

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.


getReadHandler

public com.hazelcast.nio.tcp.ReadHandler getReadHandler()

getWriteHandler

public WriteHandler getWriteHandler()

isAlive

public boolean isAlive()
Description copied from interface: Connection
Checks if the Connection is still alive.

Specified by:
isAlive in interface Connection
Returns:
true if alive, false otherwise.

lastWriteTime

public long lastWriteTime()
Description copied from interface: Connection
Returns the clock time of the most recent write using this connection.

Specified by:
lastWriteTime in interface Connection
Returns:
the clock time of the most recent write.

lastReadTime

public long lastReadTime()
Description copied from interface: Connection
Returns the clock time of the most recent read using this connection.

Specified by:
lastReadTime in interface Connection
Returns:
the clock time of the most recent read

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.

setEndPoint

public void setEndPoint(Address endPoint)

setMonitor

public void setMonitor(TcpIpConnectionMonitor monitor)

getMonitor

public TcpIpConnectionMonitor getMonitor()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

close

public void close()
Description copied from interface: Connection
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.

Specified by:
close in interface Connection

close

public void close(Throwable t)

getConnectionId

public int getConnectionId()

toString

public String toString()
Overrides:
toString in class Object


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