Search in sources :

Example 6 with Connection

use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.

the class FirewallingMockConnectionManager method unblock.

public synchronized void unblock(Address address) {
    blockedAddresses.remove(address);
    Connection connection = getConnection(address);
    if (connection instanceof DroppingConnection) {
        connection.close(null, null);
    }
}
Also used : Connection(com.hazelcast.nio.Connection)

Example 7 with Connection

use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.

the class FirewallingTcpIpConnectionManager method getOrConnect.

@Override
public synchronized Connection getOrConnect(Address address, boolean silent) {
    Connection connection = getConnection(address);
    if (connection != null) {
        return connection;
    }
    if (blockedAddresses.contains(address)) {
        connection = new DroppingConnection(address, this);
        registerConnection(address, connection);
        return connection;
    }
    return super.getOrConnect(address, silent);
}
Also used : Connection(com.hazelcast.nio.Connection)

Example 8 with Connection

use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.

the class TcpIpConnectionManager_ConnectMemberBaseTest method getOrConnect_whenAlreadyConnectedSameConnectionReturned.

@Test
public void getOrConnect_whenAlreadyConnectedSameConnectionReturned() throws UnknownHostException {
    startAllConnectionManagers();
    Connection c1 = connect(connManagerA, addressB);
    Connection c2 = connManagerA.getOrConnect(addressB);
    assertSame(c1, c2);
}
Also used : Connection(com.hazelcast.nio.Connection) Test(org.junit.Test)

Example 9 with Connection

use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.

the class TcpIpConnectionManager_ConnectMemberBaseTest method getOrConnect_whenNotConnected_thenEventuallyConnectionAvailable.

// ================== getOrConnect ======================================================
@Test
public void getOrConnect_whenNotConnected_thenEventuallyConnectionAvailable() throws UnknownHostException {
    startAllConnectionManagers();
    Connection c = connManagerA.getOrConnect(addressB);
    assertNull(c);
    connect(connManagerA, addressB);
    assertEquals(1, connManagerA.getActiveConnectionCount());
    assertEquals(1, connManagerB.getActiveConnectionCount());
}
Also used : Connection(com.hazelcast.nio.Connection) Test(org.junit.Test)

Example 10 with Connection

use of com.hazelcast.nio.Connection 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);
        }
    });
}
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)

Aggregations

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