use of org.apache.ignite.client.ClientException in project ignite by apache.
the class MultipleSSLContextsTest method testThinClients.
/**
* Checks that thin clients with SSL enabled can join the cluster and perform some work on it.
*
* @throws Exception If failed.
*/
@Test
public void testThinClients() throws Exception {
int clientsNum = 3;
int keysNum = 1000;
String cacheName = "thinClientCache";
List<IgniteClient> clients = new ArrayList<>(clientsNum);
try {
for (int i = 0; i < clientsNum; i++) {
IgniteClient client = Ignition.startClient(clientConfiguration("127.0.0.1:1080" + i));
clients.add(client);
}
Map<Integer, Integer> expMap = new HashMap<>();
for (int i = 0; i < keysNum; i++) {
int clientId = keysNum % clientsNum;
ClientCache<Integer, Integer> cache = clients.get(clientId).getOrCreateCache(cacheName);
cache.put(i, i);
expMap.put(i, i);
}
IgniteCache<Integer, Integer> cache = grid(0).cache(cacheName);
assertCacheContent(expMap, cache);
} catch (ClientException ex) {
ex.printStackTrace();
fail("Failed to start thin Java clients: " + ex.getMessage());
} finally {
for (IgniteClient client : clients) client.close();
IgniteCache cache = grid(0).cache(cacheName);
if (cache != null)
cache.destroy();
}
}
use of org.apache.ignite.client.ClientException in project ignite by apache.
the class ReliableChannel method getRetryLimit.
/**
* Get retry limit.
*/
private int getRetryLimit() {
List<ClientChannelHolder> holders = channels;
if (holders == null)
throw new ClientException("Connections to nodes aren't initialized.");
int size = holders.size();
return clientCfg.getRetryLimit() > 0 ? Math.min(clientCfg.getRetryLimit(), size) : size;
}
use of org.apache.ignite.client.ClientException 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.ClientException in project ignite by apache.
the class TcpClientCache method writeCacheInfo.
/**
* Write cache ID and flags.
*/
private void writeCacheInfo(PayloadOutputChannel payloadCh) {
BinaryOutputStream out = payloadCh.out();
out.writeInt(cacheId);
byte flags = keepBinary ? KEEP_BINARY_FLAG_MASK : 0;
TcpClientTransaction tx = transactions.tx();
if (expiryPlc != null) {
ProtocolContext protocolCtx = payloadCh.clientChannel().protocolCtx();
if (!protocolCtx.isFeatureSupported(EXPIRY_POLICY)) {
throw new ClientProtocolError(String.format("Expire policies are not supported by the server " + "version %s, required version %s", protocolCtx.version(), EXPIRY_POLICY.verIntroduced()));
}
flags |= WITH_EXPIRY_POLICY_FLAG_MASK;
}
if (tx != null) {
if (tx.clientChannel() != payloadCh.clientChannel()) {
throw new ClientException("Transaction context has been lost due to connection errors. " + "Cache operations are prohibited until current transaction closed.");
}
flags |= TRANSACTIONAL_FLAG_MASK;
}
out.writeByte(flags);
if ((flags & WITH_EXPIRY_POLICY_FLAG_MASK) != 0) {
out.writeLong(convertDuration(expiryPlc.getExpiryForCreation()));
out.writeLong(convertDuration(expiryPlc.getExpiryForUpdate()));
out.writeLong(convertDuration(expiryPlc.getExpiryForAccess()));
}
if ((flags & TRANSACTIONAL_FLAG_MASK) != 0)
out.writeInt(tx.txId());
}
use of org.apache.ignite.client.ClientException in project ignite by apache.
the class TcpClientTransactions method txStart0.
/**
* @param concurrency Concurrency.
* @param isolation Isolation.
* @param timeout Timeout.
*/
private ClientTransaction txStart0(TransactionConcurrency concurrency, TransactionIsolation isolation, Long timeout, String lb) {
TcpClientTransaction tx0 = tx();
if (tx0 != null)
throw new ClientException("A transaction has already been started by the current thread.");
tx0 = ch.service(ClientOperation.TX_START, req -> {
ProtocolContext protocolCtx = req.clientChannel().protocolCtx();
if (!protocolCtx.isFeatureSupported(TRANSACTIONS)) {
throw new ClientProtocolError(String.format("Transactions are not supported by the server's " + "protocol version %s, required version %s", protocolCtx.version(), TRANSACTIONS.verIntroduced()));
}
try (BinaryRawWriterEx writer = new BinaryWriterExImpl(marsh.context(), req.out(), null, null)) {
writer.writeByte((byte) (concurrency == null ? txCfg.getDefaultTxConcurrency() : concurrency).ordinal());
writer.writeByte((byte) (isolation == null ? txCfg.getDefaultTxIsolation() : isolation).ordinal());
writer.writeLong(timeout == null ? txCfg.getDefaultTxTimeout() : timeout);
writer.writeString(lb);
}
}, res -> new TcpClientTransaction(res.in().readInt(), res.clientChannel()));
threadLocTxUid.set(tx0.txUid);
txMap.put(tx0.txUid, tx0);
return tx0;
}
Aggregations