use of org.apache.ignite.client.ClientException in project ignite by apache.
the class JavaThinClient method clientAddressFinder.
void clientAddressFinder() throws Exception {
// tag::client-address-finder[]
ClientAddressFinder finder = () -> {
String[] dynamicServerAddresses = fetchServerAddresses();
return dynamicServerAddresses;
};
ClientConfiguration cfg = new ClientConfiguration().setAddressesFinder(finder).setPartitionAwarenessEnabled(true);
try (IgniteClient client = Ignition.startClient(cfg)) {
ClientCache<Integer, String> cache = client.cache("myCache");
// Put, get, or remove data from the cache...
} catch (ClientException e) {
System.err.println(e.getMessage());
}
// end::client-address-finder[]
}
use of org.apache.ignite.client.ClientException in project ignite by apache.
the class JavaThinClient method veiwsystemview.
void veiwsystemview() {
// tag::system-views[]
ClientConfiguration cfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
try (IgniteClient igniteClient = Ignition.startClient(cfg)) {
// getting the id of the first node
UUID nodeId = (UUID) igniteClient.query(new SqlFieldsQuery("SELECT * from NODES").setSchema("IGNITE")).getAll().iterator().next().get(0);
double cpu_load = (Double) igniteClient.query(new SqlFieldsQuery("select CUR_CPU_LOAD * 100 from NODE_METRICS where NODE_ID = ? ").setSchema("IGNITE").setArgs(nodeId.toString())).getAll().iterator().next().get(0);
System.out.println("node's cpu load = " + cpu_load);
} catch (ClientException e) {
System.err.println(e.getMessage());
} catch (Exception e) {
System.err.format("Unexpected failure: %s\n", e);
}
// end::system-views[]
}
use of org.apache.ignite.client.ClientException in project ignite by apache.
the class ClientCacheEntryListenerHandler method startListen.
/**
* Send request to the server and start
*/
public synchronized void startListen(CacheEntryUpdatedListener<K, V> locLsnr, ClientDisconnectListener disconnectLsnr, Factory<? extends CacheEntryEventFilter<? super K, ? super V>> rmtFilterFactory, int pageSize, long timeInterval, boolean includeExpired) {
assert locLsnr != null;
if (clientCh != null)
throw new IllegalStateException("Listener was already started");
this.locLsnr = locLsnr;
this.disconnectLsnr = disconnectLsnr;
Consumer<PayloadOutputChannel> qryWriter = payloadCh -> {
BinaryOutputStream out = payloadCh.out();
out.writeInt(ClientUtils.cacheId(jCacheAdapter.getName()));
out.writeByte(keepBinary ? KEEP_BINARY_FLAG_MASK : 0);
out.writeInt(pageSize);
out.writeLong(timeInterval);
out.writeBoolean(includeExpired);
if (rmtFilterFactory == null)
out.writeByte(GridBinaryMarshaller.NULL);
else {
utils.writeObject(out, rmtFilterFactory);
out.writeByte(JAVA_PLATFORM);
}
};
Function<PayloadInputChannel, T2<ClientChannel, Long>> qryReader = payloadCh -> {
ClientChannel ch = payloadCh.clientChannel();
Long rsrcId = payloadCh.in().readLong();
ch.addNotificationListener(CONTINUOUS_QUERY_EVENT, rsrcId, this);
return new T2<>(ch, rsrcId);
};
try {
T2<ClientChannel, Long> params = ch.service(ClientOperation.QUERY_CONTINUOUS, qryWriter, qryReader);
clientCh = params.get1();
rsrcId = params.get2();
} catch (ClientError e) {
throw new ClientException(e);
}
}
use of org.apache.ignite.client.ClientException in project ignite by apache.
the class ClientCacheEntryListenerHandler method acceptNotification.
/**
* {@inheritDoc}
*/
@Override
public void acceptNotification(ByteBuffer payload, Exception err) {
if (err == null && payload != null) {
BinaryInputStream in = BinaryByteBufferInputStream.create(payload);
int cnt = in.readInt();
List<CacheEntryEvent<? extends K, ? extends V>> evts = new ArrayList<>(cnt);
for (int i = 0; i < cnt; i++) {
K key = utils.readObject(in, keepBinary);
V oldVal = utils.readObject(in, keepBinary);
V val = utils.readObject(in, keepBinary);
byte evtTypeByte = in.readByte();
EventType evtType = eventType(evtTypeByte);
if (evtType == null)
onChannelClosed(new ClientException("Unknown event type: " + evtTypeByte));
evts.add(new CacheEntryEventImpl<>(jCacheAdapter, evtType, key, oldVal, val));
}
locLsnr.onUpdated(evts);
}
}
use of org.apache.ignite.client.ClientException in project ignite by apache.
the class ClientComputeImpl method executeAsync0.
/**
* @param taskName Task name.
* @param arg Argument.
* @param clusterGrp Cluster group.
* @param flags Flags.
* @param timeout Timeout.
*/
private <T, R> IgniteClientFuture<R> executeAsync0(String taskName, @Nullable T arg, ClientClusterGroupImpl clusterGrp, byte flags, long timeout) throws ClientException {
Collection<UUID> nodeIds = clusterGrp.nodeIds();
if (F.isEmpty(taskName))
throw new ClientException("Task name can't be null or empty.");
if (nodeIds != null && nodeIds.isEmpty())
throw new ClientException("Cluster group is empty.");
Consumer<PayloadOutputChannel> payloadWriter = ch -> writeExecuteTaskRequest(ch, taskName, arg, nodeIds, flags, timeout);
Function<PayloadInputChannel, ClientComputeTask<R>> payloadReader = ch -> {
Long taskId = ch.in().readLong();
ClientComputeTask<R> task = new ClientComputeTask<>(utils, ch.clientChannel(), taskId);
ch.clientChannel().addNotificationListener(COMPUTE_TASK_FINISHED, taskId, task);
return task;
};
IgniteClientFuture<ClientComputeTask<R>> initFut = ch.serviceAsync(COMPUTE_TASK_EXECUTE, payloadWriter, payloadReader);
CompletableFuture<R> resFut = new CompletableFuture<>();
AtomicReference<Object> cancellationToken = new AtomicReference<>();
initFut.handle((task, err) -> handleExecuteInitFuture(resFut, cancellationToken, task, err));
return new IgniteClientFutureImpl<>(resFut, mayInterruptIfRunning -> {
// 2. initFut has completed - cancel compute future.
if (!cancellationToken.compareAndSet(null, mayInterruptIfRunning)) {
GridFutureAdapter<?> fut = (GridFutureAdapter<?>) cancellationToken.get();
if (!cancelGridFuture(fut, mayInterruptIfRunning))
return false;
}
resFut.cancel(mayInterruptIfRunning);
return true;
});
}
Aggregations