Search in sources :

Example 51 with Connection

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

the class ClientSmartInvocationServiceImpl method invokeOnPartitionOwner.

@Override
public void invokeOnPartitionOwner(ClientInvocation invocation, int partitionId) throws IOException {
    final Address owner = partitionService.getPartitionOwner(partitionId);
    if (owner == null) {
        throw new IOException("Partition does not have owner. partitionId : " + partitionId);
    }
    invocation.getClientMessage().setPartitionId(partitionId);
    Connection connection = getOrTriggerConnect(owner);
    send(invocation, (ClientConnection) connection);
}
Also used : Address(com.hazelcast.nio.Address) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) Connection(com.hazelcast.nio.Connection) IOException(java.io.IOException)

Example 52 with Connection

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

the class TcpIpConnectionManager method getOrConnect.

@Override
public Connection getOrConnect(final Address address, final boolean silent) {
    Connection connection = connectionsMap.get(address);
    if (connection == null && live) {
        if (connectionsInProgress.add(address)) {
            ioService.shouldConnectTo(address);
            ioService.executeAsync(new InitConnectionTask(this, address, silent));
        }
    }
    return connection;
}
Also used : Connection(com.hazelcast.nio.Connection)

Example 53 with Connection

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

the class ClientEngineImpl method shutdown.

@Override
public void shutdown(boolean terminate) {
    for (ClientEndpoint ce : endpointManager.getEndpoints()) {
        ClientEndpointImpl endpoint = (ClientEndpointImpl) ce;
        try {
            endpoint.destroy();
        } catch (LoginException e) {
            logger.finest(e.getMessage());
        }
        try {
            final Connection conn = endpoint.getConnection();
            if (conn.isAlive()) {
                conn.close("Shutdown of ClientEngine", null);
            }
        } catch (Exception e) {
            logger.finest(e);
        }
    }
    endpointManager.clear();
    ownershipMappings.clear();
}
Also used : Connection(com.hazelcast.nio.Connection) TcpIpConnection(com.hazelcast.nio.tcp.TcpIpConnection) LoginException(javax.security.auth.login.LoginException) ClientEndpoint(com.hazelcast.client.ClientEndpoint) LoginException(javax.security.auth.login.LoginException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 54 with Connection

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

the class ClusterServiceImpl method doRemoveAddress.

void doRemoveAddress(Address deadAddress, String reason, boolean destroyConnection) {
    if (!ensureMemberIsRemovable(deadAddress)) {
        return;
    }
    lock.lock();
    try {
        if (deadAddress.equals(node.getMasterAddress())) {
            assignNewMaster();
        }
        if (node.isMaster()) {
            clusterJoinManager.removeJoin(deadAddress);
        }
        Connection conn = node.connectionManager.getConnection(deadAddress);
        if (destroyConnection && conn != null) {
            conn.close(reason, null);
        }
        MemberImpl deadMember = getMember(deadAddress);
        if (deadMember != null) {
            removeMember(deadMember);
            logger.info(membersString());
        }
    } finally {
        lock.unlock();
    }
}
Also used : MemberImpl(com.hazelcast.instance.MemberImpl) Connection(com.hazelcast.nio.Connection)

Example 55 with Connection

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

the class SystemLogPlugin method render.

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private void render(DiagnosticsLogWriter writer, ConnectionEvent event) {
    if (event.added) {
        writer.startSection("ConnectionAdded");
    } else {
        writer.startSection("ConnectionRemoved");
    }
    Connection connection = event.connection;
    writer.writeEntry(connection.toString());
    writer.writeKeyValueEntry("type", connection.getType().name());
    writer.writeKeyValueEntry("isAlive", connection.isAlive());
    if (!event.added) {
        String closeReason = connection.getCloseReason();
        Throwable closeCause = connection.getCloseCause();
        if (closeReason == null && closeCause != null) {
            closeReason = closeCause.getMessage();
        }
        writer.writeKeyValueEntry("closeReason", closeReason == null ? "Unknown" : closeReason);
        if (closeCause != null) {
            writer.startSection("CloseCause");
            String s = closeCause.getClass().getName();
            String message = closeCause.getMessage();
            writer.writeEntry((message != null) ? (s + ": " + message) : s);
            for (StackTraceElement element : closeCause.getStackTrace()) {
                writer.writeEntry(element.toString());
            }
            writer.endSection();
        }
    }
    writer.endSection();
}
Also used : Connection(com.hazelcast.nio.Connection)

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