Search in sources :

Example 11 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class JavaThinClient method transactionConfiguration.

@Test
void transactionConfiguration() {
    // tag::transaction-config[]
    ClientConfiguration cfg = new ClientConfiguration();
    cfg.setAddresses("localhost:10800");
    cfg.setTransactionConfiguration(new ClientTransactionConfiguration().setDefaultTxTimeout(10000).setDefaultTxConcurrency(TransactionConcurrency.OPTIMISTIC).setDefaultTxIsolation(TransactionIsolation.REPEATABLE_READ));
    IgniteClient client = Ignition.startClient(cfg);
    // end::transaction-config[]
    ClientCache cache = client.createCache(new ClientCacheConfiguration().setName("test").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
    // tag::tx-custom-properties[]
    ClientTransactions tx = client.transactions();
    try (ClientTransaction t = tx.txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.REPEATABLE_READ)) {
        cache.put(1, "new value");
        t.commit();
    }
// end::tx-custom-properties[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientTransaction(org.apache.ignite.client.ClientTransaction) ClientTransactionConfiguration(org.apache.ignite.configuration.ClientTransactionConfiguration) ClientCache(org.apache.ignite.client.ClientCache) ClientTransactions(org.apache.ignite.client.ClientTransactions) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration) Test(org.junit.jupiter.api.Test)

Example 12 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class BinaryMetadataRegisterClassTest method afterTest.

/**
 * {@inheritDoc}
 */
@Override
protected void afterTest() throws Exception {
    stopAllGrids();
    for (IgniteClient thinClient : thinClients) thinClient.close();
    super.afterTest();
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient)

Example 13 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class K8s method connectThinClientWithConfiguration.

public static void connectThinClientWithConfiguration() throws Exception {
    // tag::connectThinClientWithKubernetesConfiguration[]
    KubernetesConnectionConfiguration kcfg = new KubernetesConnectionConfiguration();
    kcfg.setNamespace("ignite");
    kcfg.setServiceName("ignite-service");
    ClientConfiguration ccfg = new ClientConfiguration();
    ccfg.setAddressesFinder(new ThinClientKubernetesAddressFinder(kcfg));
    IgniteClient client = Ignition.startClient(cfg);
    ClientCache<Integer, String> cache = client.getOrCreateCache("test_cache");
    cache.put(1, "first test value");
    System.out.println(cache.get(1));
    client.close();
// end::connectThinClientWithKubernetesConfiguration[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

Example 14 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class K8s method connectThinClient.

public static void connectThinClient() throws Exception {
    // tag::connectThinClient[]
    ClientConfiguration cfg = new ClientConfiguration().setAddresses("13.86.186.145:10800");
    IgniteClient client = Ignition.startClient(cfg);
    ClientCache<Integer, String> cache = client.getOrCreateCache("test_cache");
    cache.put(1, "first test value");
    System.out.println(cache.get(1));
    client.close();
// end::connectThinClient[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

Example 15 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class ClientPutGetExample method main.

/**
 * Entry point.
 *
 * @param args Command line arguments.
 */
public static void main(String[] args) {
    ClientConfiguration cfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
    try (IgniteClient igniteClient = Ignition.startClient(cfg)) {
        System.out.println();
        System.out.println(">>> Thin client put-get example started.");
        final String CACHE_NAME = "put-get-example";
        ClientCache<Integer, Address> cache = igniteClient.getOrCreateCache(CACHE_NAME);
        System.out.format(">>> Created cache [%s].\n", CACHE_NAME);
        Integer key = 1;
        Address val = new Address("1545 Jackson Street", 94612);
        cache.put(key, val);
        System.out.format(">>> Saved [%s] in the cache.\n", val);
        Address cachedVal = cache.get(key);
        System.out.format(">>> Loaded [%s] from the cache.\n", cachedVal);
    } catch (ClientException e) {
        System.err.println(e.getMessage());
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Address(org.apache.ignite.examples.model.Address) ClientException(org.apache.ignite.client.ClientException) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

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