Search in sources :

Example 6 with IgniteClient

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[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientCluster(org.apache.ignite.client.ClientCluster) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) Test(org.junit.jupiter.api.Test)

Example 7 with IgniteClient

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[]
}
Also used : ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteClient(org.apache.ignite.client.IgniteClient) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) Ignite(org.apache.ignite.Ignite) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 8 with IgniteClient

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[]
    }
}
Also used : ClientDisconnectListener(org.apache.ignite.client.ClientDisconnectListener) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ClientException(org.apache.ignite.client.ClientException) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) ClientAuthenticationException(org.apache.ignite.client.ClientAuthenticationException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 9 with IgniteClient

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[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 10 with IgniteClient

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[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Aggregations

IgniteClient (org.apache.ignite.client.IgniteClient)106 Test (org.junit.Test)76 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)43 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)26 UUID (java.util.UUID)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Ignite (org.apache.ignite.Ignite)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 HashSet (java.util.HashSet)13 T2 (org.apache.ignite.internal.util.typedef.T2)13 Set (java.util.Set)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 List (java.util.List)10 BinaryObject (org.apache.ignite.binary.BinaryObject)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)10 GridTestUtils.assertThrowsWithCause (org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause)10 Map (java.util.Map)9 Duration (javax.cache.expiry.Duration)9 ClientCacheConfiguration (org.apache.ignite.client.ClientCacheConfiguration)9