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;
}
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);
}
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);
}
}
Aggregations