use of org.apache.ignite.configuration.ClientConfiguration 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.configuration.ClientConfiguration 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.configuration.ClientConfiguration in project ignite by apache.
the class JavaThinClient method main.
public static void main(String[] args) throws ClientException, Exception {
JavaThinClient test = new JavaThinClient();
ClientConfiguration cfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
try (IgniteClient client = Ignition.startClient(cfg)) {
test.scanQuery(client);
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class JavaThinClient method configureSSL.
@Test
void configureSSL() throws ClientException, Exception {
// tag::ssl-configuration[]
ClientConfiguration clientCfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
clientCfg.setSslMode(SslMode.REQUIRED).setSslClientCertificateKeyStorePath(KEYSTORE).setSslClientCertificateKeyStoreType("JKS").setSslClientCertificateKeyStorePassword("123456").setSslTrustCertificateKeyStorePath(TRUSTSTORE).setSslTrustCertificateKeyStorePassword("123456").setSslTrustCertificateKeyStoreType("JKS").setSslKeyAlgorithm("SunX509").setSslTrustAll(false).setSslProtocol(SslProtocol.TLS);
try (IgniteClient client = Ignition.startClient(clientCfg)) {
// ...
}
// end::ssl-configuration[]
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class CacheCreateDestroyEventSecurityContextTest method testIgniteClient.
/**
* Tests cache create/destroy event security context in case operation is initiated from the {@link IgniteClient}.
*/
@Test
public void testIgniteClient() throws Exception {
operationInitiatorLogin = "thin_client";
ClientConfiguration cfg = new ClientConfiguration().setAddresses(Config.SERVER).setUserName(operationInitiatorLogin).setUserPassword("");
ClientCacheConfiguration ccfg = clientCacheConfiguration();
try (IgniteClient cli = Ignition.startClient(cfg)) {
checkCacheEvents(() -> cli.createCache(ccfg), EVT_CACHE_STARTED);
checkCacheEvents(() -> cli.destroyCache(ccfg.getName()), EVT_CACHE_STOPPED);
checkCacheEvents(() -> cli.createCacheAsync(ccfg).get(), EVT_CACHE_STARTED);
checkCacheEvents(() -> cli.destroyCacheAsync(ccfg.getName()).get(), EVT_CACHE_STOPPED);
checkCacheEvents(() -> cli.getOrCreateCache(clientCacheConfiguration()), EVT_CACHE_STARTED);
checkCacheEvents(() -> cli.getOrCreateCacheAsync(clientCacheConfiguration()).get(), EVT_CACHE_STARTED);
checkCacheEvents(() -> cli.cluster().state(INACTIVE), EVT_CACHE_STOPPED);
checkCacheEvents(() -> cli.cluster().state(ACTIVE), EVT_CACHE_STARTED);
}
}
Aggregations