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;
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
Aggregations