use of com.hazelcast.nio.ConnectionListener in project hazelcast by hazelcast.
the class TcpIpConnectionManager_ConnectionListenerTest method whenConnectionAdded.
@Test
public void whenConnectionAdded() throws Exception {
startAllConnectionManagers();
final ConnectionListener listener = mock(ConnectionListener.class);
connManagerA.addConnectionListener(listener);
final Connection c = connect(connManagerA, addressB);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
listener.connectionAdded(c);
}
});
}
use of com.hazelcast.nio.ConnectionListener in project hazelcast by hazelcast.
the class TcpIpConnectionManager_ConnectionListenerTest method whenConnectionManagerShutdown_thenListenersRemoved.
@Test
public void whenConnectionManagerShutdown_thenListenersRemoved() {
startAllConnectionManagers();
ConnectionListener listener = mock(ConnectionListener.class);
connManagerA.addConnectionListener(listener);
connManagerA.shutdown();
assertEquals(0, connManagerA.connectionListeners.size());
}
use of com.hazelcast.nio.ConnectionListener in project hazelcast by hazelcast.
the class MockConnectionManager method onClose.
public void onClose(final Connection connection) {
final Address endPoint = connection.getEndPoint();
if (mapConnections.remove(endPoint, connection)) {
logger.info("Removed connection to endpoint: " + endPoint + ", connection: " + connection);
ioService.getEventService().executeEventCallback(new StripedRunnable() {
@Override
public void run() {
for (ConnectionListener listener : connectionListeners) {
listener.connectionRemoved(connection);
}
}
@Override
public int getKey() {
return endPoint.hashCode();
}
});
}
}
use of com.hazelcast.nio.ConnectionListener in project hazelcast by hazelcast.
the class TcpIpConnectionManager method registerConnection.
@Override
public synchronized boolean registerConnection(final Address remoteEndPoint, final Connection connection) {
try {
if (remoteEndPoint.equals(ioService.getThisAddress())) {
return false;
}
if (!connection.isAlive()) {
if (logger.isFinestEnabled()) {
logger.finest(connection + " to " + remoteEndPoint + " is not registered since connection is not active.");
}
return false;
}
if (connection instanceof TcpIpConnection) {
TcpIpConnection tcpConnection = (TcpIpConnection) connection;
Address currentEndPoint = tcpConnection.getEndPoint();
if (currentEndPoint != null && !currentEndPoint.equals(remoteEndPoint)) {
throw new IllegalArgumentException(connection + " has already a different endpoint than: " + remoteEndPoint);
}
tcpConnection.setEndPoint(remoteEndPoint);
if (!connection.isClient()) {
TcpIpConnectionMonitor connectionMonitor = getConnectionMonitor(remoteEndPoint, true);
tcpConnection.setMonitor(connectionMonitor);
}
}
connectionsMap.put(remoteEndPoint, connection);
ioService.getEventService().executeEventCallback(new StripedRunnable() {
@Override
public void run() {
for (ConnectionListener listener : connectionListeners) {
listener.connectionAdded(connection);
}
}
@Override
public int getKey() {
return remoteEndPoint.hashCode();
}
});
return true;
} finally {
connectionsInProgress.remove(remoteEndPoint);
}
}
use of com.hazelcast.nio.ConnectionListener in project hazelcast by hazelcast.
the class TcpIpConnectionManager_ConnectionListenerTest method whenConnectionDestroyed.
@Test
public void whenConnectionDestroyed() throws Exception {
startAllConnectionManagers();
final ConnectionListener listener = mock(ConnectionListener.class);
connManagerA.addConnectionListener(listener);
final Connection c = connect(connManagerA, addressB);
c.close(null, null);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
listener.connectionRemoved(c);
}
});
}
Aggregations