Search in sources :

Example 11 with Connection

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

the class TcpIpConnectionManager_TransmitTest method withConnection_whenConnectionWriteFails.

@Test
public void withConnection_whenConnectionWriteFails() {
    Connection connection = mock(Connection.class);
    Packet packet = new Packet(serializationService.toBytes("foo"));
    when(connection.write(packet)).thenReturn(false);
    boolean result = connManagerA.transmit(packet, connection);
    assertFalse(result);
}
Also used : Packet(com.hazelcast.nio.Packet) Connection(com.hazelcast.nio.Connection) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with Connection

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

the class TcpIpConnection_AbstractTest method connect.

protected TcpIpConnection connect(final TcpIpConnectionManager connectionManager, final Address address) {
    connectionManager.getOrConnect(address);
    final AtomicReference<TcpIpConnection> ref = new AtomicReference<TcpIpConnection>();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Connection c = connectionManager.getConnection(address);
            assertNotNull(c);
            ref.set((TcpIpConnection) c);
        }
    });
    return ref.get();
}
Also used : Connection(com.hazelcast.nio.Connection) AssertTask(com.hazelcast.test.AssertTask) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 13 with Connection

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

the class ClientConnectionManagerImpl method getOrTriggerConnect.

@Override
public Connection getOrTriggerConnect(Address target, boolean asOwner) {
    Connection connection = getConnection(target, asOwner);
    if (connection != null) {
        return connection;
    }
    triggerConnect(target, asOwner);
    return null;
}
Also used : Connection(com.hazelcast.nio.Connection)

Example 14 with Connection

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

the class TcpIpConnectionManager method stop.

@Override
public synchronized void stop() {
    if (!live) {
        return;
    }
    live = false;
    logger.finest("Stopping ConnectionManager");
    shutdownAcceptorThread();
    for (SocketChannelWrapper socketChannel : acceptedSockets) {
        closeResource(socketChannel);
    }
    for (Connection conn : connectionsMap.values()) {
        destroySilently(conn, "TcpIpConnectionManager is stopping");
    }
    for (TcpIpConnection conn : activeConnections) {
        destroySilently(conn, "TcpIpConnectionManager is stopping");
    }
    ioThreadingModel.shutdown();
    acceptedSockets.clear();
    connectionsInProgress.clear();
    connectionsMap.clear();
    monitors.clear();
    activeConnections.clear();
}
Also used : SocketChannelWrapper(com.hazelcast.internal.networking.SocketChannelWrapper) Connection(com.hazelcast.nio.Connection)

Example 15 with Connection

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

the class TcpIpConnectionManager method toString.

@Override
public String toString() {
    final StringBuilder sb = new StringBuilder("Connections {");
    for (Connection conn : connectionsMap.values()) {
        sb.append("\n");
        sb.append(conn);
    }
    sb.append("\nlive=");
    sb.append(live);
    sb.append("\n}");
    return sb.toString();
}
Also used : Connection(com.hazelcast.nio.Connection)

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