use of org.apache.ignite.client.ClientException in project ignite by apache.
the class ClientClusterImpl method state.
/**
* {@inheritDoc}
*/
@Override
public void state(ClusterState newState) throws ClientException {
try {
ch.service(ClientOperation.CLUSTER_CHANGE_STATE, req -> {
ProtocolContext protocolCtx = req.clientChannel().protocolCtx();
checkClusterApiSupported(protocolCtx);
if (newState.ordinal() > 1 && !protocolCtx.isFeatureSupported(ProtocolBitmaskFeature.CLUSTER_STATES)) {
throw new ClientFeatureNotSupportedByServerException("State " + newState.name() + " is not " + "supported by the server");
}
req.out().writeByte((byte) newState.ordinal());
}, null);
} catch (ClientError e) {
throw new ClientException(e);
}
}
use of org.apache.ignite.client.ClientException in project ignite by apache.
the class ClientClusterGroupImpl method requestNodeIds.
/**
* Requests node IDs from the server.
*/
private synchronized Collection<UUID> requestNodeIds() {
try {
return ch.service(ClientOperation.CLUSTER_GROUP_GET_NODE_IDS, req -> {
if (!req.clientChannel().protocolCtx().isFeatureSupported(ProtocolBitmaskFeature.CLUSTER_GROUPS))
throw new ClientFeatureNotSupportedByServerException(ProtocolBitmaskFeature.CLUSTER_GROUPS);
try (BinaryRawWriterEx writer = utils.createBinaryWriter(req.out())) {
writer.writeLong(cachedTopVer);
projectionFilters.write(writer);
}
}, res -> {
if (!res.in().readBoolean())
// There were no changes since last request.
return new ArrayList<>(cachedNodeIds);
// Topology version.
long topVer = res.in().readLong();
int nodesCnt = res.in().readInt();
Collection<UUID> nodeIds = new ArrayList<>(nodesCnt);
for (int i = 0; i < nodesCnt; i++) nodeIds.add(new UUID(res.in().readLong(), res.in().readLong()));
cachedNodes.keySet().retainAll(nodeIds);
cachedTopVer = topVer;
cachedNodeIds = nodeIds;
return new ArrayList<>(nodeIds);
});
} catch (ClientError e) {
throw new ClientException(e);
}
}
use of org.apache.ignite.client.ClientException in project ignite by apache.
the class ClientClusterGroupImpl method requestNodesByIds.
/**
* Requests nodes from the server.
*
* @param nodeIds Node ids.
*/
private Collection<ClusterNode> requestNodesByIds(Collection<UUID> nodeIds) {
try {
return ch.service(ClientOperation.CLUSTER_GROUP_GET_NODE_INFO, req -> {
if (!req.clientChannel().protocolCtx().isFeatureSupported(ProtocolBitmaskFeature.CLUSTER_GROUPS))
throw new ClientFeatureNotSupportedByServerException(ProtocolBitmaskFeature.CLUSTER_GROUPS);
req.out().writeInt(nodeIds.size());
for (UUID nodeId : nodeIds) {
req.out().writeLong(nodeId.getMostSignificantBits());
req.out().writeLong(nodeId.getLeastSignificantBits());
}
}, res -> {
try (BinaryReaderExImpl reader = utils.createBinaryReader(res.in())) {
int nodesCnt = reader.readInt();
Collection<ClusterNode> nodes = new ArrayList<>();
for (int i = 0; i < nodesCnt; i++) {
ClusterNode node = readClusterNode(reader);
cachedNodes.put(node.id(), node);
if (projectionFilters.testClientSidePredicates(node))
nodes.add(node);
}
return nodes;
} catch (IOException e) {
throw new ClientError(e);
}
});
} catch (ClientError e) {
throw new ClientException(e);
}
}
use of org.apache.ignite.client.ClientException 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.ClientException in project ignite by apache.
the class OptimizedMarshallerClassesCachedTest method testLocalDateTimeMetaCached.
/**
* Test check that meta for classes serialized by {@link OptimizedMarshaller} are cached on client.
*/
@Test
public void testLocalDateTimeMetaCached() throws Exception {
try (Ignite srv = startGrid(0)) {
srv.getOrCreateCache(Config.DEFAULT_CACHE_NAME).put(1, LocalDateTime.now());
IgniteClient cli = new TcpIgniteClient((cfg0, hnd) -> new TcpClientChannel(cfg0, hnd) {
@Override
public <T> T service(ClientOperation op, Consumer<PayloadOutputChannel> payloadWriter, Function<PayloadInputChannel, T> payloadReader) throws ClientException {
if (op == ClientOperation.GET_BINARY_TYPE_NAME)
cnt.incrementAndGet();
return super.service(op, payloadWriter, payloadReader);
}
@Override
public <T> CompletableFuture<T> serviceAsync(ClientOperation op, Consumer<PayloadOutputChannel> payloadWriter, Function<PayloadInputChannel, T> payloadReader) {
if (op == ClientOperation.GET_BINARY_TYPE_NAME)
cnt.incrementAndGet();
return super.serviceAsync(op, payloadWriter, payloadReader);
}
}, new ClientConfiguration().setAddresses(Config.SERVER));
try {
cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
} finally {
cli.close();
}
assertEquals(1, cnt.get());
}
}
Aggregations