Search in sources :

Example 21 with CacheConfiguration

use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.

the class AlgorithmSpecificDatasetExample method createCache.

/**
 */
private static IgniteCache<Integer, Person> createCache(Ignite ignite) {
    CacheConfiguration<Integer, Person> cacheConfiguration = new CacheConfiguration<>();
    cacheConfiguration.setName("PERSONS");
    cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 2));
    IgniteCache<Integer, Person> persons = ignite.createCache(cacheConfiguration);
    persons.put(1, new Person("Mike", 1, 1));
    persons.put(2, new Person("John", 2, 2));
    persons.put(3, new Person("George", 3, 3));
    persons.put(4, new Person("Karl", 4, 4));
    return persons;
}
Also used : RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Person(org.apache.ignite.examples.ml.dataset.model.Person) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 22 with CacheConfiguration

use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.

the class CacheApiExample method main.

/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 * @throws IgniteException If example execution failed.
 */
public static void main(String[] args) throws IgniteException {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Cache API example started.");
        CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
        cfg.setCacheMode(CacheMode.PARTITIONED);
        cfg.setName(CACHE_NAME);
        // Auto-close cache at the end of the example.
        try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg)) {
            // Demonstrate atomic map operations.
            atomicMapOperations(cache);
        } finally {
            // Distributed cache could be removed from cluster only by #destroyCache() call.
            ignite.destroyCache(CACHE_NAME);
        }
    }
}
Also used : Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 23 with CacheConfiguration

use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.

the class CacheHibernateStoreExample method main.

/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 * @throws IgniteException If example execution failed.
 */
public static void main(String[] args) throws IgniteException {
    ExamplesUtils.checkMinMemory(MIN_MEMORY);
    // To start ignite with desired configuration uncomment the appropriate line.
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Cache store example started.");
        CacheConfiguration<Long, Person> cacheCfg = new CacheConfiguration<>(CACHE_NAME);
        // Set atomicity as transaction, since we are showing transactions in example.
        cacheCfg.setAtomicityMode(TRANSACTIONAL);
        // Configure Hibernate store.
        cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(CacheHibernatePersonStore.class));
        // Configure Hibernate session listener.
        cacheCfg.setCacheStoreSessionListenerFactories(new Factory<CacheStoreSessionListener>() {

            @Override
            public CacheStoreSessionListener create() {
                CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();
                lsnr.setHibernateConfigurationPath(HIBERNATE_CFG);
                return lsnr;
            }
        });
        cacheCfg.setReadThrough(true);
        cacheCfg.setWriteThrough(true);
        // Auto-close cache at the end of the example.
        try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheCfg)) {
            // Make initial cache loading from persistent store. This is a
            // distributed operation and will call CacheStore.loadCache(...)
            // method on all nodes in topology.
            loadCache(cache);
            // Start transaction and execute several cache operations with
            // read/write-through to persistent store.
            executeTransaction(cache);
        } finally {
            // Distributed cache could be removed from cluster only by #destroyCache() call.
            ignite.destroyCache(CACHE_NAME);
        }
    }
}
Also used : CacheHibernateStoreSessionListener(org.apache.ignite.cache.store.hibernate.CacheHibernateStoreSessionListener) Ignite(org.apache.ignite.Ignite) Person(org.apache.ignite.examples.model.Person) CacheStoreSessionListener(org.apache.ignite.cache.store.CacheStoreSessionListener) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 24 with CacheConfiguration

use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.

the class CacheAffinityExample method main.

/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 * @throws IgniteException If example execution failed.
 */
public static void main(String[] args) throws IgniteException {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Cache affinity example started.");
        CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
        cfg.setCacheMode(CacheMode.PARTITIONED);
        cfg.setName(CACHE_NAME);
        // Auto-close cache at the end of the example.
        try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg)) {
            for (int i = 0; i < KEY_CNT; i++) cache.put(i, Integer.toString(i));
            // Co-locates jobs with data using IgniteCompute.affinityRun(...) method.
            visitUsingAffinityRun();
            // Co-locates jobs with data using IgniteCluster.mapKeysToNodes(...) method.
            visitUsingMapKeysToNodes();
        } finally {
            // Distributed cache could be removed from cluster only by #destroyCache() call.
            ignite.destroyCache(CACHE_NAME);
        }
    }
}
Also used : Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 25 with CacheConfiguration

use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.

the class CacheAsyncApiExample method main.

/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 * @throws IgniteException If example execution failed.
 */
public static void main(String[] args) throws IgniteException {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Cache asynchronous API example started.");
        CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
        cfg.setCacheMode(CacheMode.PARTITIONED);
        cfg.setName(CACHE_NAME);
        // Auto-close cache at the end of the example.
        try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg)) {
            // Enable asynchronous mode.
            IgniteCache<Integer, String> asyncCache = cache.withAsync();
            Collection<IgniteFuture<?>> futs = new ArrayList<>();
            // Execute several puts asynchronously.
            for (int i = 0; i < 10; i++) {
                asyncCache.put(i, String.valueOf(i));
                futs.add(asyncCache.future());
            }
            // Wait for completion of all futures.
            futs.forEach(IgniteFuture::get);
            // Execute get operation asynchronously.
            asyncCache.get(1);
            // Asynchronously wait for result.
            asyncCache.<String>future().listen(fut -> System.out.println("Get operation completed [value=" + fut.get() + ']'));
        } finally {
            // Distributed cache could be removed from cluster only by #destroyCache() call.
            ignite.destroyCache(CACHE_NAME);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1234 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)474 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)330 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)292 Ignite (org.apache.ignite.Ignite)202 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)127 ArrayList (java.util.ArrayList)95 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)82 IgniteEx (org.apache.ignite.internal.IgniteEx)60 QueryEntity (org.apache.ignite.cache.QueryEntity)59 IgniteCache (org.apache.ignite.IgniteCache)55 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)54 CacheException (javax.cache.CacheException)51 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)51 IgniteException (org.apache.ignite.IgniteException)50 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)45 LinkedHashMap (java.util.LinkedHashMap)41 IgfsGroupDataBlocksKeyMapper (org.apache.ignite.igfs.IgfsGroupDataBlocksKeyMapper)41 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)38 Transaction (org.apache.ignite.transactions.Transaction)35