public class TcpIpConnectionManager extends Object implements ConnectionManager, PacketHandler
Constructor and Description |
---|
TcpIpConnectionManager(IOService ioService,
ServerSocketChannel serverSocketChannel,
LoggingService loggingService,
MetricsRegistry metricsRegistry,
EventLoopGroup eventLoopGroup) |
TcpIpConnectionManager(IOService ioService,
ServerSocketChannel serverSocketChannel,
LoggingService loggingService,
MetricsRegistry metricsRegistry,
EventLoopGroup eventLoopGroup,
HazelcastProperties properties) |
Modifier and Type | Method and Description |
---|---|
void |
addConnectionListener(ConnectionListener listener)
Registers a ConnectionListener.
|
int |
getActiveConnectionCount()
Gets the number of active connections.
|
Set<TcpIpConnection> |
getActiveConnections() |
int |
getAllTextConnections()
Gets the number of text connections (rest/memcache)
|
Connection |
getConnection(Address address)
Gets the connection for a given address.
|
int |
getConnectionCount()
Gets the total number of connections.
|
int |
getCurrentClientConnections()
Gets the number of client connections.
|
EventLoopGroup |
getEventLoopGroup() |
IOService |
getIoService() |
Connection |
getOrConnect(Address address)
Gets the existing connection for a given address or connects.
|
Connection |
getOrConnect(Address address,
boolean silent)
Gets the existing connection for a given address.
|
void |
handle(Packet packet)
Signals the PacketHandler that there is a packet to be handled.
|
void |
incrementTextConnections() |
boolean |
isLive() |
void |
onConnectionClose(Connection connection)
Deals with cleaning up a closed connection.
|
boolean |
registerConnection(Address remoteEndPoint,
Connection connection) |
void |
shutdown()
Shutdowns ConnectionManager completely.
|
void |
start()
Starts ConnectionManager, initializes its resources, starts threads, etc.
|
void |
stop()
Stops ConnectionManager, releases its resources, stops threads, etc.
|
String |
toString() |
boolean |
transmit(Packet packet,
Address target)
Retries sending packet maximum 5 times until connection to target becomes available.
|
boolean |
transmit(Packet packet,
Connection connection)
Transmits a packet to a certain connection.
|
public TcpIpConnectionManager(IOService ioService, ServerSocketChannel serverSocketChannel, LoggingService loggingService, MetricsRegistry metricsRegistry, EventLoopGroup eventLoopGroup)
public TcpIpConnectionManager(IOService ioService, ServerSocketChannel serverSocketChannel, LoggingService loggingService, MetricsRegistry metricsRegistry, EventLoopGroup eventLoopGroup, HazelcastProperties properties)
public IOService getIoService()
public EventLoopGroup getEventLoopGroup()
public Set<TcpIpConnection> getActiveConnections()
public int getActiveConnectionCount()
ConnectionManager
getActiveConnectionCount
in interface ConnectionManager
public int getAllTextConnections()
ConnectionManager
getAllTextConnections
in interface ConnectionManager
public int getConnectionCount()
ConnectionManager
getConnectionCount
in interface ConnectionManager
public void incrementTextConnections()
public void addConnectionListener(ConnectionListener listener)
ConnectionListenable
addConnectionListener
in interface ConnectionListenable
listener
- the ConnectionListener to add.public void handle(Packet packet) throws Exception
PacketHandler
handle
in interface PacketHandler
packet
- the response packet to handleException
public boolean registerConnection(Address remoteEndPoint, Connection connection)
registerConnection
in interface ConnectionManager
public Connection getConnection(Address address)
ConnectionManager
getConnection
in interface ConnectionManager
address
- the remote side of the connectionpublic Connection getOrConnect(Address address)
ConnectionManager
getOrConnect
in interface ConnectionManager
address
- the address to connect tonull
if no connection existsConnectionManager.getOrConnect(Address, boolean)
public Connection getOrConnect(Address address, boolean silent)
ConnectionManager
null
.
When the connection is established at some point in time, it can be retrieved using the
ConnectionManager.getConnection(Address)
.
getOrConnect
in interface ConnectionManager
address
- the address to connect tosilent
- if logging should be done on debug level (silent=true
) or on info level (silent=false
)public void onConnectionClose(Connection connection)
TcpIpConnection.close(String, Throwable)
method where it is protected against multiple closes.onConnectionClose
in interface ConnectionManager
public void start()
ConnectionManager
If it is already started, then this method has no effect.
start
in interface ConnectionManager
public void stop()
ConnectionManager
ConnectionManager.start()
.
This method has no effect if it is already stopped or shutdown.
Currently stop
is called during the merge process to detach node from the current cluster. After
node becomes ready to join to the new cluster, start
is called to re-initialize the ConnectionManager.
stop
in interface ConnectionManager
public void shutdown()
ConnectionManager
This method has no effect if it is already shutdown.
shutdown
in interface ConnectionManager
public int getCurrentClientConnections()
ConnectionManager
getCurrentClientConnections
in interface ConnectionManager
public boolean isLive()
public boolean transmit(Packet packet, Connection connection)
ConnectionManager
If this method is called with a null
connection, the call returns false
.
transmit
in interface ConnectionManager
packet
- the packet to transmitconnection
- he connection to where the Packet should be transmittedtrue
if the transmit was a success, false
if a failure (there is no guarantee that the packet is
actually going to be received since the packet perhaps is stuck in some buffer; it just means that it's buffered somewhere)public boolean transmit(Packet packet, Address target)
transmit
in interface ConnectionManager
packet
- The Packet to transmit.target
- The address of the target machine where the Packet should be transmitted.ConnectionManager.transmit(com.hazelcast.nio.Packet, com.hazelcast.nio.Connection)
Copyright © 2018 Hazelcast, Inc.. All Rights Reserved.