public final class TcpIpConnection extends Object implements SocketConnection, MetricsProvider, DiscardableMetricsProvider
Connection.
A TcpIpConnection is not responsible for reading or writing data to a socket, this is done through:
SocketReader: which care of reading from the socket and feeding it into the system/li>
SocketWriter: which care of writing data to the socket.IOThreadingModel| Constructor and Description |
|---|
TcpIpConnection(TcpIpConnectionManager connectionManager,
int connectionId,
SocketChannelWrapper socketChannel,
IOThreadingModel ioThreadingModel) |
| Modifier and Type | Method and Description |
|---|---|
void |
close(String reason,
Throwable cause)
Closes this connection.
|
void |
discardMetrics(MetricsRegistry registry) |
boolean |
equals(Object o) |
Throwable |
getCloseCause()
Gets the cause this Connection was closed.
|
String |
getCloseReason()
Gets the reason this Connection was closed.
|
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.
|
InetSocketAddress |
getRemoteSocketAddress()
Returns the address of the endpoint this Connection is connected to, or
null if it is unconnected. |
SocketChannelWrapper |
getSocketChannel() |
SocketReader |
getSocketReader() |
SocketWriter |
getSocketWriter() |
ConnectionType |
getType()
Returns the
ConnectionType of this Connection. |
int |
hashCode() |
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 |
provideMetrics(MetricsRegistry registry) |
void |
setEndPoint(Address endPoint) |
void |
setMonitor(TcpIpConnectionMonitor monitor) |
void |
setReceiveBufferSize(int size) |
void |
setSendBufferSize(int size) |
void |
setType(ConnectionType type)
Sets the type of the connection
|
void |
start()
Starts this connection.
|
String |
toString() |
boolean |
write(OutboundFrame frame)
Writes a outbound frame so it can be received by the other side of the connection.
|
public TcpIpConnection(TcpIpConnectionManager connectionManager, int connectionId, SocketChannelWrapper socketChannel, IOThreadingModel ioThreadingModel)
public void provideMetrics(MetricsRegistry registry)
provideMetrics in interface MetricsProviderpublic void discardMetrics(MetricsRegistry registry)
discardMetrics in interface DiscardableMetricsProviderpublic SocketReader getSocketReader()
getSocketReader in interface SocketConnectionpublic SocketWriter getSocketWriter()
getSocketWriter in interface SocketConnectionpublic SocketChannelWrapper getSocketChannel()
getSocketChannel in interface SocketConnectionpublic ConnectionType getType()
ConnectionConnectionType of this Connection.getType in interface Connectionnull is returned.public void setType(ConnectionType type)
ConnectionsetType in interface Connectiontype - to be setpublic TcpIpConnectionManager getConnectionManager()
public InetAddress getInetAddress()
ConnectiongetInetAddress in interface Connectionnull if the connection is not alive.public int getPort()
Connectiontodo: 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
getPort in interface Connectionpublic InetSocketAddress getRemoteSocketAddress()
Connectionnull if it is unconnected.getRemoteSocketAddress in interface Connectiontodo: do we really need this method because we have getInetAddress, InetSocketAddress and getEndPoint.
public boolean isAlive()
ConnectionisAlive in interface Connectionpublic long lastWriteTimeMillis()
ConnectionlastWriteTimeMillis in interface Connectionpublic long lastReadTimeMillis()
ConnectionlastReadTimeMillis in interface Connectionpublic Address getEndPoint()
ConnectionAddress of the other side of this Connection.
todo: rename to get remoteAddress?
getEndPoint in interface Connectionpublic void setEndPoint(Address endPoint)
public void setMonitor(TcpIpConnectionMonitor monitor)
public TcpIpConnectionMonitor getMonitor()
public int getConnectionId()
public void setSendBufferSize(int size)
throws SocketException
SocketExceptionpublic void setReceiveBufferSize(int size)
throws SocketException
SocketExceptionpublic boolean isClient()
ConnectionisClient in interface Connectionpublic void start()
Starting means that the connection is going to register itself to listen to incoming traffic.
public boolean write(OutboundFrame frame)
ConnectionThe frame could be stored in an internal queue before it actually is written, so this call does not need to be a synchronous call.
write in interface Connectionframe - the frame to write.public void close(String reason, Throwable cause)
ConnectionPending packets on this connection are discarded
If the Connection is already closed, the call is ignored. So it can safely be called multiple times.
close in interface Connectionreason - 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.public Throwable getCloseCause()
ConnectiongetCloseCause in interface Connection(),
Connection.close(String, Throwable)public String getCloseReason()
ConnectiongetCloseReason in interface ConnectionConnection.getCloseCause(),
Connection.close(String, Throwable)Copyright © 2017 Hazelcast, Inc.. All Rights Reserved.