use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class JavaThinClient method cientCluster.
@Test
void cientCluster() throws Exception {
ClientConfiguration clientCfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
// tag::client-cluster[]
try (IgniteClient client = Ignition.startClient(clientCfg)) {
ClientCluster clientCluster = client.cluster();
clientCluster.state(ClusterState.ACTIVE);
}
// end::client-cluster[]
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class JavaThinClient method clientCompute.
void clientCompute() throws Exception {
// tag::client-compute-setup[]
ThinClientConfiguration thinClientCfg = new ThinClientConfiguration().setMaxActiveComputeTasksPerConnection(100);
ClientConnectorConfiguration clientConnectorCfg = new ClientConnectorConfiguration().setThinClientConfiguration(thinClientCfg);
IgniteConfiguration igniteCfg = new IgniteConfiguration().setClientConnectorConfiguration(clientConnectorCfg);
Ignite ignite = Ignition.start(igniteCfg);
// end::client-compute-setup[]
ClientConfiguration clientCfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
// tag::client-compute-task[]
try (IgniteClient client = Ignition.startClient(clientCfg)) {
// Suppose that the MyTask class is already deployed in the cluster
client.compute().execute(MyTask.class.getName(), "argument");
}
// end::client-compute-task[]
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class JavaThinClient method continuousQueries.
void continuousQueries() throws Exception {
ClientConfiguration clientCfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
try (IgniteClient client = Ignition.startClient(clientCfg)) {
// tag::continuous-queries[]
ClientCache<Integer, String> cache = client.getOrCreateCache("myCache");
ContinuousQuery<Integer, String> query = new ContinuousQuery<>();
query.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events) throws CacheEntryListenerException {
// react to the update events here
}
});
ClientDisconnectListener disconnectListener = new ClientDisconnectListener() {
@Override
public void onDisconnected(Exception reason) {
// react to the disconnect event here
}
};
cache.query(query, disconnectListener);
// end::continuous-queries[]
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class JavaThinClient method asyncApi.
void asyncApi() throws Exception {
ClientConfiguration clientCfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
// tag::async-api[]
IgniteClient client = Ignition.startClient(clientCfg);
ClientCache<Integer, String> cache = client.getOrCreateCache("cache");
IgniteClientFuture<Void> putFut = cache.putAsync(1, "hello");
// Blocking wait.
putFut.get();
IgniteClientFuture<String> getFut = cache.getAsync(1);
// Non-blocking continuation.
getFut.thenAccept(val -> System.out.println(val));
// end::async-api[]
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class JavaThinClient method clientClusterGroups.
void clientClusterGroups() throws Exception {
ClientConfiguration clientCfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
// tag::client-cluster-groups[]
try (IgniteClient client = Ignition.startClient(clientCfg)) {
ClientClusterGroup serversInDc1 = client.cluster().forServers().forAttribute("dc", "dc1");
serversInDc1.nodes().forEach(n -> System.out.println("Node ID: " + n.id()));
}
// end::client-cluster-groups[]
}
Aggregations