Search in sources :

Example 6 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class SqlClientService method mappingDdl.

/**
 * Gets a SQL Mapping suggestion for the given IMap name.
 *
 * Used by Management Center.
 */
@Nonnull
public CompletableFuture<String> mappingDdl(Member member, String mapName) {
    checkNotNull(mapName);
    ClientInvocation invocation = new ClientInvocation(client, SqlMappingDdlCodec.encodeRequest(mapName), null, member.getUuid());
    return new ClientDelegatingFuture<>(invocation.invoke(), client.getSerializationService(), SqlMappingDdlCodec::decodeResponse);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) SqlMappingDdlCodec(com.hazelcast.client.impl.protocol.codec.SqlMappingDdlCodec) Nonnull(javax.annotation.Nonnull)

Example 7 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class ClientProtocolTest method testUnsupportedClientMessage.

@Test(expected = UnsupportedOperationException.class)
public void testUnsupportedClientMessage() {
    hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    ClientMessage s = MapSizeCodec.encodeRequest("mapName");
    int undefinedMessageType = -1;
    s.setMessageType(undefinedMessageType);
    ClientInvocation invocation = new ClientInvocation(clientImpl, s, "mapName");
    try {
        invocation.invoke().get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class TcpClientConnectionManager method authenticateOnCluster.

private ClientAuthenticationCodec.ResponseParameters authenticateOnCluster(TcpClientConnection connection) {
    Address memberAddress = connection.getInitAddress();
    ClientMessage request = encodeAuthenticationRequest(memberAddress);
    ClientInvocationFuture future = new ClientInvocation(client, request, null, connection).invokeUrgent();
    try {
        return ClientAuthenticationCodec.decodeResponse(future.get(authenticationTimeout, MILLISECONDS));
    } catch (Exception e) {
        connection.close("Failed to authenticate connection", e);
        throw rethrow(e);
    }
}
Also used : Address(com.hazelcast.cluster.Address) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HazelcastException(com.hazelcast.core.HazelcastException) HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException) IOException(java.io.IOException) AuthenticationException(com.hazelcast.client.AuthenticationException) HazelcastClientOfflineException(com.hazelcast.client.HazelcastClientOfflineException) EOFException(java.io.EOFException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClientNotAllowedInClusterException(com.hazelcast.client.ClientNotAllowedInClusterException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 9 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class HeartbeatManager method start.

public static void start(HazelcastClientInstanceImpl client, TaskScheduler taskScheduler, ILogger logger, long heartbeatIntervalMillis, long heartbeatTimeoutMillis, Collection<Connection> unmodifiableActiveConnections) {
    taskScheduler.scheduleWithRepetition(() -> {
        long now = Clock.currentTimeMillis();
        for (Connection connection : unmodifiableActiveConnections) {
            if (!connection.isAlive()) {
                return;
            }
            if (now - connection.lastReadTimeMillis() > heartbeatTimeoutMillis) {
                logger.warning("Heartbeat failed over the connection: " + connection);
                connection.close("Heartbeat timed out", new TargetDisconnectedException("Heartbeat timed out to connection " + connection));
                return;
            }
            if (now - connection.lastWriteTimeMillis() > heartbeatIntervalMillis) {
                ClientMessage request = ClientPingCodec.encodeRequest();
                ClientInvocation invocation = new ClientInvocation(client, request, null, connection);
                invocation.invokeUrgent();
            }
        }
    }, heartbeatIntervalMillis, heartbeatIntervalMillis, MILLISECONDS);
}
Also used : Connection(com.hazelcast.internal.nio.Connection) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 10 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class ClientSchemaService method get.

@Override
public Schema get(long schemaId) {
    Schema schema = schemas.get(schemaId);
    if (schema != null) {
        return schema;
    }
    if (logger.isFinestEnabled()) {
        logger.finest("Could not find schema id  " + schemaId + " locally, will search on the cluster" + schemaId);
    }
    ClientInvocation invocation = new ClientInvocation(client, ClientFetchSchemaCodec.encodeRequest(schemaId), SERVICE_NAME);
    ClientMessage message = invocation.invoke().joinInternal();
    schema = ClientFetchSchemaCodec.decodeResponse(message);
    if (schema != null) {
        schemas.put(schemaId, schema);
    }
    return schema;
}
Also used : Schema(com.hazelcast.internal.serialization.impl.compact.Schema) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Aggregations

ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)129 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)97 ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)54 ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)51 Test (org.junit.Test)23 Data (com.hazelcast.internal.serialization.Data)22 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 QuickTest (com.hazelcast.test.annotation.QuickTest)19 UUID (java.util.UUID)18 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)16 Future (java.util.concurrent.Future)13 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)9 ArrayList (java.util.ArrayList)9 Nonnull (javax.annotation.Nonnull)9 ExecutionException (java.util.concurrent.ExecutionException)8 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)7 Collection (java.util.Collection)6 List (java.util.List)6 Map (java.util.Map)6 TimeUnit (java.util.concurrent.TimeUnit)6