Search in sources :

Example 61 with Connection

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);
        }
    });
}
Also used : Connection(com.hazelcast.nio.Connection) AssertTask(com.hazelcast.test.AssertTask) ConnectionListener(com.hazelcast.nio.ConnectionListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 62 with Connection

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);
}
Also used : Packet(com.hazelcast.nio.Packet) Connection(com.hazelcast.nio.Connection) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 63 with Connection

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);
    }
}
Also used : Connection(com.hazelcast.nio.Connection)

Example 64 with 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);
    }
}
Also used : Connection(com.hazelcast.nio.Connection)

Example 65 with Connection

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);
    }
}
Also used : Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Connection(com.hazelcast.nio.Connection) ILogger(com.hazelcast.logging.ILogger) Member(com.hazelcast.core.Member)

Aggregations

Connection (com.hazelcast.nio.Connection)67 Address (com.hazelcast.nio.Address)18 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)10 Test (org.junit.Test)10 QuickTest (com.hazelcast.test.annotation.QuickTest)8 IOException (java.io.IOException)7 ClientConnectionManager (com.hazelcast.client.connection.ClientConnectionManager)6 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)6 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)6 AssertTask (com.hazelcast.test.AssertTask)6 ClientClusterService (com.hazelcast.client.spi.ClientClusterService)4 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)4 Node (com.hazelcast.instance.Node)4 Packet (com.hazelcast.nio.Packet)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 EventHandler (com.hazelcast.client.spi.EventHandler)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 Member (com.hazelcast.core.Member)3 ILogger (com.hazelcast.logging.ILogger)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3