Search in sources :

Example 16 with Connection

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

the class TcpIpConnectionManager method send.

private boolean send(Packet packet, Address target, SendTask sendTask) {
    Connection connection = getConnection(target);
    if (connection != null) {
        return connection.write(packet);
    }
    if (sendTask == null) {
        sendTask = new SendTask(packet, target);
    }
    int retries = sendTask.retries;
    if (retries < RETRY_NUMBER && ioService.isActive()) {
        getOrConnect(target, true);
        // TODO: Caution: may break the order guarantee of the packets sent from the same thread!
        scheduler.schedule(sendTask, (retries + 1) * DELAY_FACTOR, TimeUnit.MILLISECONDS);
        return true;
    }
    return false;
}
Also used : Connection(com.hazelcast.nio.Connection)

Example 17 with Connection

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

the class Invocation method toString.

@Override
public String toString() {
    String connectionStr = null;
    Address invTarget = this.invTarget;
    if (invTarget != null) {
        ConnectionManager connectionManager = context.connectionManager;
        Connection connection = connectionManager.getConnection(invTarget);
        connectionStr = connection == null ? null : connection.toString();
    }
    return "Invocation{" + "op=" + op + ", tryCount=" + tryCount + ", tryPauseMillis=" + tryPauseMillis + ", invokeCount=" + invokeCount + ", callTimeoutMillis=" + callTimeoutMillis + ", firstInvocationTimeMs=" + firstInvocationTimeMillis + ", firstInvocationTime='" + timeToString(firstInvocationTimeMillis) + '\'' + ", lastHeartbeatMillis=" + lastHeartbeatMillis + ", lastHeartbeatTime='" + timeToString(lastHeartbeatMillis) + '\'' + ", target=" + invTarget + ", pendingResponse={" + pendingResponse + '}' + ", backupsAcksExpected=" + backupsAcksExpected + ", backupsAcksReceived=" + backupsAcksReceived + ", connection=" + connectionStr + '}';
}
Also used : ConnectionManager(com.hazelcast.nio.ConnectionManager) Address(com.hazelcast.nio.Address) OperationAccessor.setCallerAddress(com.hazelcast.spi.OperationAccessor.setCallerAddress) Connection(com.hazelcast.nio.Connection) StringUtil.timeToString(com.hazelcast.util.StringUtil.timeToString)

Example 18 with Connection

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

the class OutboundResponseHandler method send.

public boolean send(Response response, Address target) {
    checkNotNull(target, "Target is required!");
    if (thisAddress.equals(target)) {
        throw new IllegalArgumentException("Target is this node! -> " + target + ", response: " + response);
    }
    byte[] bytes = serializationService.toBytes(response);
    Packet packet = new Packet(bytes, -1).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE);
    if (response.isUrgent()) {
        packet.raiseFlags(FLAG_URGENT);
    }
    ConnectionManager connectionManager = node.getConnectionManager();
    Connection connection = connectionManager.getOrConnect(target);
    return connectionManager.transmit(packet, connection);
}
Also used : Packet(com.hazelcast.nio.Packet) ConnectionManager(com.hazelcast.nio.ConnectionManager) Connection(com.hazelcast.nio.Connection)

Example 19 with Connection

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

the class TcpIpJoiner method joinViaTargetMember.

private void joinViaTargetMember(Address targetAddress, long maxJoinMillis) {
    try {
        if (targetAddress == null) {
            throw new IllegalArgumentException("Invalid target address -> NULL");
        }
        if (logger.isFineEnabled()) {
            logger.fine("Joining over target member " + targetAddress);
        }
        if (targetAddress.equals(node.getThisAddress()) || isLocalAddress(targetAddress)) {
            clusterJoinManager.setAsMaster();
            return;
        }
        long joinStartTime = Clock.currentTimeMillis();
        Connection connection;
        while (shouldRetry() && (Clock.currentTimeMillis() - joinStartTime < maxJoinMillis)) {
            connection = node.connectionManager.getOrConnect(targetAddress);
            if (connection == null) {
                //noinspection BusyWait
                Thread.sleep(JOIN_RETRY_WAIT_TIME);
                continue;
            }
            if (logger.isFineEnabled()) {
                logger.fine("Sending joinRequest " + targetAddress);
            }
            clusterJoinManager.sendJoinRequest(targetAddress, true);
            //noinspection BusyWait
            Thread.sleep(JOIN_RETRY_WAIT_TIME);
        }
    } catch (final Exception e) {
        logger.warning(e);
    }
}
Also used : Connection(com.hazelcast.nio.Connection) InvalidAddressException(com.hazelcast.util.AddressUtil.InvalidAddressException) UnknownHostException(java.net.UnknownHostException)

Example 20 with Connection

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

the class AbstractClientInternalCacheProxy method getConnectedServerVersion.

private int getConnectedServerVersion() {
    ClientContext clientContext = getContext();
    ClientClusterService clusterService = clientContext.getClusterService();
    Address ownerConnectionAddress = clusterService.getOwnerConnectionAddress();
    HazelcastClientInstanceImpl client = getClient();
    ClientConnectionManager connectionManager = client.getConnectionManager();
    Connection connection = connectionManager.getConnection(ownerConnectionAddress);
    if (connection == null) {
        logger.warning(format("No owner connection is available, " + "near cached cache %s will be started in legacy mode", name));
        return UNKNOWN_HAZELCAST_VERSION;
    }
    return ((ClientConnection) connection).getConnectedServerVersion();
}
Also used : Address(com.hazelcast.nio.Address) ClientContext(com.hazelcast.client.spi.ClientContext) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) Connection(com.hazelcast.nio.Connection) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager) ClientClusterService(com.hazelcast.client.spi.ClientClusterService)

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