use of com.hazelcast.nio.Connection 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);
}
});
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class TcpIpConnectionManager_TransmitTest method withConnection_whenConnectionWriteSucceeds.
@Test
public void withConnection_whenConnectionWriteSucceeds() {
Connection connection = mock(Connection.class);
Packet packet = new Packet(serializationService.toBytes("foo"));
when(connection.write(packet)).thenReturn(true);
boolean result = connManagerA.transmit(packet, connection);
assertTrue(result);
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class FirewallingTcpIpConnectionManager method unblock.
public synchronized void unblock(Address address) {
blockedAddresses.remove(address);
Connection connection = getConnection(address);
if (connection instanceof DroppingConnection) {
connection.close(null, null);
onClose(connection);
}
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class FirewallingTcpIpConnectionManager method block.
public synchronized void block(Address address) {
blockedAddresses.add(address);
Connection connection = getConnection(address);
if (connection != null && connection instanceof TcpIpConnection) {
connection.close("Blocked by connection manager", null);
}
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class MockConnectionManager method stop.
@Override
public void stop() {
logger.fine("Stopping connection manager");
live = false;
final Member localMember = node.getLocalMember();
final Address thisAddress = localMember.getAddress();
for (Address address : registry.getAddresses()) {
if (address.equals(thisAddress)) {
continue;
}
Node otherNode = registry.getNode(address);
if (otherNode != null && otherNode.getState() != NodeState.SHUT_DOWN) {
logger.fine(otherNode.getThisAddress() + " is instructed to remove us.");
ILogger otherLogger = otherNode.getLogger(MockConnectionManager.class);
otherLogger.fine(localMember + " will be removed from the cluster if present, " + "because it has requested to leave.");
try {
ClusterServiceImpl clusterService = otherNode.getClusterService();
clusterService.removeAddress(localMember.getAddress(), localMember.getUuid(), "Connection manager is stopped on " + localMember);
} catch (Throwable e) {
otherLogger.warning("While removing " + thisAddress, e);
}
}
}
for (Connection connection : mapConnections.values()) {
connection.close(null, null);
}
}
Aggregations