Java Code Examples for org.apache.ignite.configuration.CacheConfiguration#setWriteThrough()

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setWriteThrough() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteCacheReadThroughStoreCallTest.java    From ignite with Apache License 2.0 7 votes vote down vote up
/**
 * @param cacheMode Cache mode.
 * @param atomicityMode Atomicity mode.
 * @param backups Number of backups.
 * @return Cache configuration.
 */
@SuppressWarnings("unchecked")
protected CacheConfiguration<Object, Object> cacheConfiguration(CacheMode cacheMode,
    CacheAtomicityMode atomicityMode,
    int backups) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setReadThrough(true);
    ccfg.setWriteThrough(true);
    ccfg.setCacheStoreFactory(new TestStoreFactory());
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setCacheMode(cacheMode);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));

    if (cacheMode == PARTITIONED)
        ccfg.setBackups(backups);

    return ccfg;
}
 
Example 2
Source File: CacheInterceptorPartitionCounterRandomOperationsTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param cacheMode Cache mode.
 * @param backups Number of backups.
 * @param atomicityMode Cache atomicity mode.
 * @param store If {@code true} configures dummy cache store.
 * @return Cache configuration.
 */
protected CacheConfiguration<Object, Object> cacheConfiguration(
    CacheMode cacheMode,
    int backups,
    CacheAtomicityMode atomicityMode,
    boolean store) {
    CacheConfiguration<TestKey, TestValue> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setCacheMode(cacheMode);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);

    if (cacheMode == PARTITIONED)
        ccfg.setBackups(backups);

    if (store) {
        ccfg.setCacheStoreFactory(new TestStoreFactory());
        ccfg.setReadThrough(true);
        ccfg.setWriteThrough(true);
    }

    ccfg.setInterceptor(new TestInterceptor());

    return (CacheConfiguration)ccfg;
}
 
Example 3
Source File: IgniteCacheQueryLoadSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setCacheMode(REPLICATED);
    ccfg.setCacheStoreFactory(singletonFactory(new TestStore()));
    ccfg.setReadThrough(true);
    ccfg.setWriteThrough(true);
    ccfg.setLoadPreviousValue(true);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setIndexedTypes(
        Integer.class, ValueObject.class
    );

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 4
Source File: IgniteCacheStoreSessionWriteBehindAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param igniteInstanceName Ignite instance name.
 * @return Cache configuration.
 * @throws Exception In case of error.
 */
@Override @SuppressWarnings("unchecked")
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg0 = super.cacheConfiguration(igniteInstanceName);

    ccfg0.setReadThrough(true);
    ccfg0.setWriteThrough(true);
    ccfg0.setWriteBehindBatchSize(10);
    ccfg0.setWriteBehindFlushSize(10);
    ccfg0.setWriteBehindFlushFrequency(600);
    ccfg0.setWriteBehindEnabled(true);

    ccfg0.setCacheStoreFactory(singletonFactory(new TestStore()));

    return ccfg0;
}
 
Example 5
Source File: CacheContinuousQueryCounterAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @return Cache configuration.
 */
@NotNull private CacheConfiguration cacheConfiguration() {
    CacheConfiguration cacheCfg = defaultCacheConfiguration();

    cacheCfg.setName(CACHE_NAME);
    cacheCfg.setCacheMode(cacheMode());
    cacheCfg.setAtomicityMode(atomicityMode());
    cacheCfg.setNearConfiguration(nearConfiguration());
    cacheCfg.setRebalanceMode(ASYNC);
    cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
    cacheCfg.setCacheStoreFactory(new StoreFactory());
    cacheCfg.setReadThrough(true);
    cacheCfg.setWriteThrough(true);
    cacheCfg.setLoadPreviousValue(true);

    return cacheCfg;
}
 
Example 6
Source File: GridCachePartitionedLoadCacheSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setCacheMode(PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setCacheStoreFactory(singletonFactory(new TestStore()));
    ccfg.setReadThrough(true);
    ccfg.setWriteThrough(true);
    ccfg.setLoadPreviousValue(true);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 7
Source File: GridCacheAbstractTransformWriteThroughSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    GridCacheGenericTestStore<String, Integer> store = new GridCacheGenericTestStore<>();

    stores.add(store);

    CacheConfiguration cacheCfg = defaultCacheConfiguration();

    cacheCfg.setCacheMode(PARTITIONED);
    cacheCfg.setBackups(1);
    cacheCfg.setCacheStoreFactory(singletonFactory(store));
    cacheCfg.setReadThrough(true);
    cacheCfg.setWriteThrough(true);
    cacheCfg.setLoadPreviousValue(true);
    cacheCfg.setAtomicityMode(TRANSACTIONAL);
    cacheCfg.setNearConfiguration(new NearCacheConfiguration());

    cfg.setCacheConfiguration(cacheCfg);

    return cfg;
}
 
Example 8
Source File: GridCacheLoadOnlyStoreAdapterSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @return Cache configuration.
 */
@SuppressWarnings("unchecked")
private CacheConfiguration<?, ?> cacheConfiguration() {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    CacheConfiguration cfg = defaultCacheConfiguration();

    assertNotNull(store);

    cfg.setCacheStoreFactory(singletonFactory(store));
    cfg.setReadThrough(true);
    cfg.setWriteThrough(true);
    cfg.setLoadPreviousValue(true);

    return cfg;
}
 
Example 9
Source File: GridCacheMultinodeUpdateAbstractSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);

    ccfg.setCacheStoreFactory(null);
    ccfg.setReadThrough(false);
    ccfg.setWriteThrough(false);

    return ccfg;
}
 
Example 10
Source File: GridCachePartitionedStorePutSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Cache configuration.
 */
@SuppressWarnings("unchecked")
private CacheConfiguration cacheConfiguration() {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setCacheMode(PARTITIONED);
    cfg.setCacheStoreFactory(singletonFactory(new TestStore()));
    cfg.setReadThrough(true);
    cfg.setWriteThrough(true);
    cfg.setLoadPreviousValue(true);
    cfg.setAffinity(new GridCacheModuloAffinityFunction(3, 1));
    cfg.setWriteSynchronizationMode(FULL_SYNC);

    return cfg;
}
 
Example 11
Source File: GridCachePartitionedBasicStoreMultiNodeSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected final IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    if (nearCacheConfiguration() != null)
        MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.NEAR_CACHE);

    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(PARTITIONED);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setBackups(1);

    cc.setCacheStoreFactory(new StoreFactory());
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);

    cc.setNearConfiguration(nearCacheConfiguration());

    c.setCacheConfiguration(cc);

    return c;
}
 
Example 12
Source File: GridCacheEmptyEntriesAbstractSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

    TransactionConfiguration txCfg = c.getTransactionConfiguration();

    txCfg.setDefaultTxConcurrency(txConcurrency);
    txCfg.setDefaultTxIsolation(txIsolation);
    txCfg.setTxSerializableEnabled(true);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(cacheMode());
    cc.setAtomicityMode(TRANSACTIONAL);

    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

    cc.setEvictionPolicy(plc);
    cc.setOnheapCacheEnabled(true);

    if (testStore != null) {
        cc.setCacheStoreFactory(singletonFactory(testStore));
        cc.setReadThrough(true);
        cc.setWriteThrough(true);
        cc.setLoadPreviousValue(true);
    }
    else
        cc.setCacheStoreFactory(null);

    c.setCacheConfiguration(cc);

    return c;
}
 
Example 13
Source File: CacheStoreSessionListenerLifecycleSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param name Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration<Integer, Integer> cacheConfiguration(String name) {
    CacheConfiguration<Integer, Integer> cacheCfg = new CacheConfiguration<>(name);

    cacheCfg.setAtomicityMode(TRANSACTIONAL);
    cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(Store.class));
    cacheCfg.setWriteThrough(true);

    return cacheCfg;
}
 
Example 14
Source File: IgniteSqlNotNullConstraintTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
private CacheConfiguration buildCacheConfiguration(CacheMode mode,
    CacheAtomicityMode atomicityMode, boolean hasNear, boolean writeThrough, boolean notNullAnnotated) {

    CacheConfiguration cfg = new CacheConfiguration(CACHE_PREFIX + "-" +
        mode.name() + "-" + atomicityMode.name() + (hasNear ? "-near" : "") +
        (writeThrough ? "-writethrough" : "") + (notNullAnnotated ? "-annot" : ""));

    cfg.setCacheMode(mode);
    cfg.setAtomicityMode(atomicityMode);
    cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

    QueryEntity qe = new QueryEntity(new QueryEntity(Integer.class, Person.class));

    if (!notNullAnnotated)
        qe.setNotNullFields(Collections.singleton("name"));

    cfg.setQueryEntities(F.asList(qe));

    if (hasNear)
        cfg.setNearConfiguration(new NearCacheConfiguration().setNearStartSize(100));

    if (writeThrough) {
        cfg.setCacheStoreFactory(singletonFactory(new TestStore()));
        cfg.setWriteThrough(true);
    }

    return cfg;
}
 
Example 15
Source File: CacheAsyncOperationsFailoverAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);

    ccfg.setCacheStoreFactory(null);
    ccfg.setReadThrough(false);
    ccfg.setWriteThrough(false);

    return ccfg;
}
 
Example 16
Source File: DataStreamProcessorSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings({"unchecked"})
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setPeerClassLoadingEnabled(false);

    cfg.setIncludeProperties();

    if (useCache) {
        CacheConfiguration cc = defaultCacheConfiguration();

        cc.setCacheMode(mode);
        cc.setAtomicityMode(getCacheAtomicityMode());

        if (nearEnabled) {
            NearCacheConfiguration nearCfg = new NearCacheConfiguration();

            cc.setNearConfiguration(nearCfg);
        }

        cc.setWriteSynchronizationMode(FULL_SYNC);

        if (store != null) {
            cc.setCacheStoreFactory(new IgniteReflectionFactory<CacheStore>(TestStore.class));
            cc.setReadThrough(true);
            cc.setWriteThrough(true);
        }

        cfg.setCacheConfiguration(cc);

        if (persistenceEnabled())
            cfg.setDataStorageConfiguration(new DataStorageConfiguration()
                .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
                        .setPersistenceEnabled(true))
                .setWalMode(WALMode.LOG_ONLY));
    }
    else {
        cfg.setCacheConfiguration();

        cfg.setClientMode(true);
    }

    cfg.setIncludeEventTypes(EventType.EVTS_ALL);

    return cfg;
}
 
Example 17
Source File: CacheHibernateStoreExample.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 18
Source File: CacheStoreSample.java    From ignite-book-code-samples with GNU General Public License v3.0 4 votes vote down vote up
private static void jdbcStoreExample() throws Exception{
    //let's make a dynamic cache on the fly which is distributed across all running nodes.
    //the same configuration you would probably set in configuration xml format
    IgniteConfiguration cfg = new IgniteConfiguration();

    CacheConfiguration configuration = new CacheConfiguration();
    configuration.setName("dynamicCache");
    configuration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);

    configuration.setCacheStoreFactory(FactoryBuilder.factoryOf(PostgresDBStore.class));
    configuration.setReadThrough(true);
    configuration.setWriteThrough(true);

    configuration.setWriteBehindEnabled(true);

    log("Start. PersistenceStore example.");
    cfg.setCacheConfiguration(configuration);

    try (Ignite ignite = Ignition.start(cfg)) {
        //create cache if it doesn't exist
        int count = 10;
        try (IgniteCache<String, Post> igniteCache = ignite.getOrCreateCache(configuration)) {
            try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                //let us clear

                for (int i = 1; i <= count; i++)
                    igniteCache.put("_" + i, new Post("_" + i, "title-" + i, "description-" + i, LocalDate.now().plus(i, ChronoUnit.DAYS), "author-" + i));

                tx.commit();

                for (int i = 1; i < count; i += 2) {
                    igniteCache.clear("_" + i);
                    log("Clear every odd key: " + i);
                }

                for (long i = 1; i <= count; i++)
                    log("Local peek at [key=_" + i + ", val=" + igniteCache.localPeek("_" + i) + ']');

                for (long i = 1; i <= count; i++)
                    log("Got [key=_" + i + ", val=" + igniteCache.get("_" + i) + ']');

                tx.commit();
            }
        }

        log("PersistenceStore example finished.");
        //ignite.destroyCache("dynamicCache");
        Thread.sleep(Integer.MAX_VALUE);
    }
}
 
Example 19
Source File: GridCacheWriteBehindStoreLoadTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings({"unchecked"})
@Override protected final IgniteConfiguration getConfiguration() throws Exception {
    IgniteConfiguration c = super.getConfiguration();

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    c.setDiscoverySpi(disco);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(cacheMode());
    cc.setWriteSynchronizationMode(FULL_SYNC);

    cc.setCacheStoreFactory(singletonFactory(store));
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);

    cc.setWriteBehindEnabled(true);
    cc.setWriteBehindFlushFrequency(WRITE_FROM_BEHIND_FLUSH_FREQUENCY);

    c.setCacheConfiguration(cc);

    return c;
}
 
Example 20
Source File: GridCacheWriteBehindStoreAbstractTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected IgniteConfiguration getConfiguration() throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    IgniteConfiguration c = super.getConfiguration();

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    c.setDiscoverySpi(disco);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(cacheMode());
    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cc.setAtomicityMode(TRANSACTIONAL);

    cc.setCacheStoreFactory(singletonFactory(store));
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);

    cc.setWriteBehindEnabled(true);
    cc.setWriteBehindFlushFrequency(WRITE_FROM_BEHIND_FLUSH_FREQUENCY);

    c.setCacheConfiguration(cc);

    return c;
}