Search in sources :

Example 6 with ClientConnectionException

use of org.apache.ignite.client.ClientConnectionException in project ignite by apache.

the class ReliableChannel method applyOnDefaultChannel.

/**
 * Apply specified {@code function} on any of available channel.
 */
private <T> T applyOnDefaultChannel(Function<ClientChannel, T> function, ClientOperation op, int attemptsLimit, Consumer<Integer> attemptsCallback) {
    ClientConnectionException failure = null;
    for (int attempt = 0; attempt < attemptsLimit; attempt++) {
        ClientChannelHolder hld = null;
        ClientChannel c = null;
        try {
            if (closed)
                throw new ClientException("Channel is closed");
            curChannelsGuard.readLock().lock();
            try {
                hld = channels.get(curChIdx);
            } finally {
                curChannelsGuard.readLock().unlock();
            }
            c = hld.getOrCreateChannel();
            if (c != null) {
                attemptsCallback.accept(attempt + 1);
                return function.apply(c);
            }
        } catch (ClientConnectionException e) {
            if (failure == null)
                failure = e;
            else
                failure.addSuppressed(e);
            onChannelFailure(hld, c);
            if (op != null && !shouldRetry(op, attempt, e))
                break;
        }
    }
    throw failure;
}
Also used : ClientConnectionException(org.apache.ignite.client.ClientConnectionException) ClientException(org.apache.ignite.client.ClientException)

Example 7 with ClientConnectionException

use of org.apache.ignite.client.ClientConnectionException in project ignite by apache.

the class ReliableChannel method affinityServiceAsync.

/**
 * Send request to affinity node and handle response.
 */
public <T> IgniteClientFuture<T> affinityServiceAsync(int cacheId, Object key, ClientOperation op, Consumer<PayloadOutputChannel> payloadWriter, Function<PayloadInputChannel, T> payloadReader) throws ClientException, ClientError {
    if (partitionAwarenessEnabled && affinityInfoIsUpToDate(cacheId)) {
        UUID affNodeId = affinityCtx.affinityNode(cacheId, key);
        if (affNodeId != null) {
            CompletableFuture<T> fut = new CompletableFuture<>();
            Object result = applyOnNodeChannel(affNodeId, channel -> channel.serviceAsync(op, payloadWriter, payloadReader).handle((res, err) -> {
                if (err == null) {
                    fut.complete(res);
                    return null;
                }
                try {
                    // Will try to reinit channels if topology changed.
                    onChannelFailure(channel);
                } catch (Throwable ex) {
                    fut.completeExceptionally(ex);
                    return null;
                }
                if (err instanceof ClientConnectionException) {
                    ClientConnectionException failure = (ClientConnectionException) err;
                    int attemptsLimit = getRetryLimit() - 1;
                    if (attemptsLimit == 0 || !shouldRetry(op, 0, failure)) {
                        fut.completeExceptionally(err);
                        return null;
                    }
                    handleServiceAsync(fut, op, payloadWriter, payloadReader, attemptsLimit, failure);
                    return null;
                }
                fut.completeExceptionally(err);
                return null;
            }));
            if (result != null)
                return new IgniteClientFutureImpl<>(fut);
        }
    }
    return serviceAsync(op, payloadWriter, payloadReader);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClientRetryPolicy(org.apache.ignite.client.ClientRetryPolicy) ClientException(org.apache.ignite.client.ClientException) Map(java.util.Map) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) IgniteBinary(org.apache.ignite.IgniteBinary) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ClientAuthorizationException(org.apache.ignite.client.ClientAuthorizationException) ClientAuthenticationException(org.apache.ignite.client.ClientAuthenticationException) GridNioClientConnectionMultiplexer(org.apache.ignite.internal.client.thin.io.gridnioserver.GridNioClientConnectionMultiplexer) F(org.apache.ignite.internal.util.typedef.F) HostAndPortRange(org.apache.ignite.internal.util.HostAndPortRange) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IgniteClientFuture(org.apache.ignite.client.IgniteClientFuture) Set(java.util.Set) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) ClientConnectionMultiplexer(org.apache.ignite.internal.client.thin.io.ClientConnectionMultiplexer) Consumer(java.util.function.Consumer) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ForkJoinPool(java.util.concurrent.ForkJoinPool) ClientOperationType(org.apache.ignite.client.ClientOperationType) ClientRetryPolicyContext(org.apache.ignite.client.ClientRetryPolicyContext) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) CompletableFuture(java.util.concurrent.CompletableFuture) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) UUID(java.util.UUID)

Example 8 with ClientConnectionException

use of org.apache.ignite.client.ClientConnectionException in project ignite by apache.

the class GridNioClientConnectionMultiplexer method open.

/**
 * {@inheritDoc}
 */
@Override
public ClientConnection open(InetSocketAddress addr, ClientMessageHandler msgHnd, ClientConnectionStateHandler stateHnd) throws ClientConnectionException {
    try {
        SocketChannel ch = SocketChannel.open();
        ch.socket().connect(new InetSocketAddress(addr.getHostName(), addr.getPort()), Integer.MAX_VALUE);
        Map<Integer, Object> meta = new HashMap<>();
        GridNioFuture<?> sslHandshakeFut = null;
        if (sslCtx != null) {
            sslHandshakeFut = new GridNioFutureImpl<>(null);
            meta.put(GridNioSslFilter.HANDSHAKE_FUT_META_KEY, sslHandshakeFut);
        }
        GridNioSession ses = srv.createSession(ch, meta, false, null).get();
        if (sslHandshakeFut != null)
            sslHandshakeFut.get();
        return new GridNioClientConnection(ses, msgHnd, stateHnd);
    } catch (Exception e) {
        throw new ClientConnectionException(e.getMessage(), e);
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

Aggregations

ClientConnectionException (org.apache.ignite.client.ClientConnectionException)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 InetSocketAddress (java.net.InetSocketAddress)5 ClientException (org.apache.ignite.client.ClientException)5 Arrays (java.util.Arrays)4 Collection (java.util.Collection)4 Map (java.util.Map)4 UUID (java.util.UUID)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ForkJoinPool (java.util.concurrent.ForkJoinPool)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)4 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)4 Consumer (java.util.function.Consumer)4 Function (java.util.function.Function)4 ClientAuthenticationException (org.apache.ignite.client.ClientAuthenticationException)4 ClientAuthorizationException (org.apache.ignite.client.ClientAuthorizationException)4 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)4 ClientConnectionMultiplexer (org.apache.ignite.internal.client.thin.io.ClientConnectionMultiplexer)4