当前位置: 首页>>代码示例>>Java>>正文


Java IgniteCache类代码示例

本文整理汇总了Java中org.apache.ignite.IgniteCache的典型用法代码示例。如果您正苦于以下问题:Java IgniteCache类的具体用法?Java IgniteCache怎么用?Java IgniteCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IgniteCache类属于org.apache.ignite包,在下文中一共展示了IgniteCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
@PostConstruct
    public void start() {
        log.info("Application is started for Node:" + ignite.cluster().nodes());
        CollectionConfiguration cfg = new CollectionConfiguration();
        IgniteQueue<Object> queue = ignite.queue("main", 0, cfg);
        IgniteCache<UUID, Operation> operationCache = ignite.cache("operationCache");
        log.info("Application is started for KeySizes:" + operationCache.size(CachePeekMode.PRIMARY));
        ArrayList<Event> events = new ArrayList<>();
        events.add(new Event(UUID.randomUUID(), IEventType.EXECUTE, EventState.CREATED, new String[]{"firstpar1","firstpar2"}));
        operationCache.put(UUID.randomUUID(), new Operation("TEST_CREATE", events, TransactionState.RUNNING));
        log.info("Application is started for KeySizes:" + operationCache.size(CachePeekMode.PRIMARY));
/*        Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                kafkaTemplate.send("operation-events",UUID.randomUUID(),
                        new Operation("blaaggre",Arrays.asList(new Event()),TransactionState.RUNNING));

            }
        }, 3,3, TimeUnit.SECONDS);*/

//        log.info(transactionCache.get(UUID.fromString("4447a089-e5f7-477c-9807-79210fafa296")).toString());
    }
 
开发者ID:kloiasoft,项目名称:eventapis,代码行数:23,代码来源:EventController.java

示例2: selectGeneByChromsomeCriteria

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
/**
 * method assumes ChromosomeCriteria is set.
 * 
 * @param k
 *            - gene index in Chromosome.
 * @return
 */
private long selectGeneByChromsomeCriteria(int k) {
    List<Gene> genes = new ArrayList();

    StringBuffer sbSqlClause = new StringBuffer("_val like '");
    sbSqlClause.append("%");
    sbSqlClause.append(config.getChromosomeCritiera().getCriteria().get(k));
    sbSqlClause.append("%'");

    IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);

    SqlQuery sql = new SqlQuery(Gene.class, sbSqlClause.toString());

    try (QueryCursor<Entry<Long, Gene>> cursor = cache.query(sql)) {
        for (Entry<Long, Gene> e : cursor)
            genes.add(e.getValue());
    }

    int idx = selectRandomIndex(genes.size());

    Gene gene = genes.get(idx);
    return gene.id();
}
 
开发者ID:techbysample,项目名称:gagrid,代码行数:30,代码来源:GAGrid.java

示例3: cleanExpiredRecords

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
@Scheduled(initialDelayString = "${initialDelay}", fixedDelayString = "${fixedDelay}")
public void cleanExpiredRecords(){
    // query the matching records first
    logger.debug("Starting the clean up job to clear the expired records");
    long towMinutesRange = System.currentTimeMillis()-900000;
    final IgniteCache<String, List<AlertEntry>> alertsCache = getAlertsCache();
    final String sql = "select * from AlertEntry where timestamp <= ?";
    SqlQuery<String,AlertEntry> query = new SqlQuery(AlertEntry.class,sql);
    query.setArgs(towMinutesRange);
    final List<Cache.Entry<String, AlertEntry>> toDeleteAlerts = alertsCache.query(query).getAll();
    // then call remove all as this will remove the records from the cache and the persistent file system as sql delete will just delete it from the cache layer not the file system
    // or the persistent store
    if(toDeleteAlerts!=null && !toDeleteAlerts.isEmpty()){
        logger.debug("Finished cleaning out {} records",toDeleteAlerts.size());
        alertsCache.removeAll(new HashSet(toDeleteAlerts
                .stream()
                .map(Cache.Entry::getKey)
                .collect(Collectors.toList())));

    }

}
 
开发者ID:Romeh,项目名称:spring-boot-ignite,代码行数:23,代码来源:CleanExpiredAlertsService.java

示例4: onAfterPut

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
@Override
public void onAfterPut(Cache.Entry<Long, JournalItem> entry) {
    IgniteCache<String, Long> sequenceNumberTrack = ignite.getOrCreateCache("sequenceNumberTrack");
    sequenceNumberTrack.invoke(entry.getValue().getPersistenceId(), (mutableEntry, objects) -> {
        if (mutableEntry.exists() && mutableEntry.getValue() != null) {
            // if it is less than the new sequence value , use it
            if (mutableEntry.getValue() < entry.getKey()) {
                mutableEntry.setValue(entry.getKey());
            }
        } else {
            // if does not exist , just use it
            mutableEntry.setValue(entry.getKey());
        }
        // by api design nothing needed here
        return null;
    });
}
 
开发者ID:Romeh,项目名称:akka-persistance-ignite,代码行数:18,代码来源:JournalStoreInterceptor.java

示例5: apply

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
/**
 * @param config      the akka configuration object
 * @param actorSystem the akk actor system
 * @return the created snapshot ignite cache
 */
@Override
public IgniteCache<Long, SnapshotItem> apply(Config config, ActorSystem actorSystem) {
    final IgniteExtension extension = IgniteExtensionProvider.EXTENSION.get(actorSystem);
    final String cachePrefix = config.getString(CACHE_PREFIX_PROPERTY);
    final int cacheBackups = config.getInt(CACHE_BACKUPS);
    final CacheConfiguration<Long, SnapshotItem> eventStore = new CacheConfiguration();
    eventStore.setCopyOnRead(false);
    if (cacheBackups > 0) {
        eventStore.setBackups(cacheBackups);
    } else {
        eventStore.setBackups(1);
    }
    eventStore.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    eventStore.setName(cachePrefix + "_SNAPSHOT");
    eventStore.setCacheMode(CacheMode.PARTITIONED);
    eventStore.setReadFromBackup(true);
    eventStore.setIndexedTypes(Long.class, SnapshotItem.class);
    eventStore.setIndexedTypes(String.class, SnapshotItem.class);
    return extension.getIgnite().getOrCreateCache(eventStore);
}
 
开发者ID:Romeh,项目名称:akka-persistance-ignite,代码行数:26,代码来源:SnapshotCacheProvider.java

示例6: matrixGet

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
/**
 * Distributed matrix get.
 *
 * @param a Row or column index.
 * @param b Row or column index.
 * @return Matrix value at (a, b) index.
 */
private double matrixGet(int a, int b) {
    // Remote get from the primary node (where given row or column is stored locally).
    return ignite().compute(getClusterGroupForGivenKey(CACHE_NAME, getBlockId(a, b))).call(() -> {
        IgniteCache<MatrixBlockKey, MatrixBlockEntry> cache = Ignition.localIgnite().getOrCreateCache(CACHE_NAME);

        MatrixBlockKey key = getCacheKey(getBlockId(a, b));

        // Local get.
        MatrixBlockEntry block = cache.localPeek(key, CachePeekMode.PRIMARY);

        if (block == null)
            block = cache.get(key);

        return block == null ? 0.0 : block.get(a % block.rowSize(), b % block.columnSize());
    });
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:24,代码来源:BlockMatrixStorage.java

示例7: selectGeneByChromsomeCriteria

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
/**
 * method assumes ChromosomeCriteria is set.
 * 
 * @param k - gene index in Chromosome.
 *            
 * @return long
 */
private long selectGeneByChromsomeCriteria(int k) {
    List<Gene> genes = new ArrayList();

    StringBuffer sbSqlClause = new StringBuffer("_val like '");
    sbSqlClause.append("%");
    sbSqlClause.append(config.getChromosomeCritiera().getCriteria().get(k));
    sbSqlClause.append("%'");

    IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);

    SqlQuery sql = new SqlQuery(Gene.class, sbSqlClause.toString());

    try (QueryCursor<Entry<Long, Gene>> cursor = cache.query(sql)) {
        for (Entry<Long, Gene> e : cursor)
            genes.add(e.getValue());
    }

    int idx = selectRandomIndex(genes.size());

    Gene gene = genes.get(idx);
    return gene.id();
}
 
开发者ID:techbysample,项目名称:gagrid,代码行数:30,代码来源:MutateTask.java

示例8: getChromosome

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
private Chromosome getChromosome(Long key) {
    IgniteCache<Long, Chromosome> cache = ignite.cache(GAGridConstants.POPULATION_CACHE);
    StringBuffer sbSqlClause = new StringBuffer();
    sbSqlClause.append("_key IN (");
    sbSqlClause.append(key);
    sbSqlClause.append(")");

    Chromosome chromosome = null;

    SqlQuery sql = new SqlQuery(Chromosome.class, sbSqlClause.toString());

    try (QueryCursor<Entry<Long, Chromosome>> cursor = cache.query(sql)) {
        for (Entry<Long, Chromosome> e : cursor)
            chromosome = (e.getValue())

            ;
    }

    return chromosome;
}
 
开发者ID:techbysample,项目名称:gagrid,代码行数:21,代码来源:TruncateSelectionTask.java

示例9: loadAllPersons

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
@Test(dataProvider = DataProviders.KV_META_LIST_PROVIDER)
public void loadAllPersons(List<KeyValueAndMetadata> kvMetas, String dbMode) throws SQLException {
    JDBCUtil.setDBMode(dataSource, dbMode);
    JDBCUtil.applyInConnection(dataSource, connection -> {
        for (KeyValueAndMetadata kvMeta : kvMetas) {
            JDBCUtil.insertIntoDB(connection, kvMeta);
        }
    });
    Map<Integer, Object> expectedResults = kvMetas
            .stream()
            .collect(Collectors.toMap(KeyValueAndMetadata::getKey, KeyValueAndMetadata::getUnwrappedValue));
    String cacheName = kvMetas.get(0).getCacheName();
    IgniteCache<Integer, Object> cache = ignite().cache(cacheName);
    Map<Integer, Object> results = cache.getAll(expectedResults.keySet());

    assertEquals(results, expectedResults);
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:18,代码来源:JDBCDataCapturerLoaderIntegrationTest.java

示例10: gapDetectionProcessFillsGaps

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
@Test
public void gapDetectionProcessFillsGaps() throws Exception {
    int firstKey = 1;
    PrimitivesHolder firstValue = new PrimitivesHolder();
    IgniteCache<Integer, PrimitivesHolder> cache = ignite().cache(PrimitivesHolder.CACHE);
    cache.put(firstKey, firstValue);

    long missedTx = createGap();
    int lastKey = 2;
    PrimitivesHolder lastValue = new PrimitivesHolder(true, (byte) 1, (short) 1, 1, 1, 1, 1);
    cache.put(lastKey, lastValue);

    awaitReconciliationOnTransaction(missedTx);
    awaitTransactions();
    Map<Integer, PrimitivesHolder> expected = new LinkedHashMap<>();
    expected.put(firstKey, firstValue);
    expected.put(lastKey, lastValue);
    assertObjectsInDB(expected, false);
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:20,代码来源:SubscriberIntegrationTest.java

示例11: getReference

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
public static <V> Reference<V> getReference(Ignite ignite, final String name, boolean create) {
    final IgniteCache<Object, Object> cache = create ? ignite.getOrCreateCache(NAME) : ignite.cache(NAME);
    return new Reference<V>() {
        @Override
        public V get() {
            return cache == null ? null : (V) cache.get(name);
        }

        @Override
        public void set(V value) {
            if (value == null) {
                cache.remove(name);
            } else {
                cache.put(name, value);
            }
        }
    };
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:19,代码来源:MetadataAtomicsHelper.java

示例12: queryAccountBalance

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
/** */
private static double queryAccountBalance(Account account,
    IgniteCache<AccountTransactionKey, AccountTransaction> accountTxCache) {
    double result = 0;
    int accountId = account.getAccountKey().getAccountId();

    for (AccountTransactionKey txKey : account.getTransactionKeys().values()) {
        AccountTransaction transaction = accountTxCache.get(txKey);

        if (accountId == transaction.getFromAccountId()) {
            result -= transaction.getMoneyAmount();
        }
        else {
            result += transaction.getMoneyAmount();
        }
    }
    return result;
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:19,代码来源:SimulationUtil.java

示例13: process

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public void process(final Map<?, ?> entries) {
    long processingStartTime = System.currentTimeMillis();
    ignite.compute().run(new IgniteRunnable() {
        @IgniteInstanceResource
        private Ignite localIgnite;

        @Override public void run() {
            IgniteCache cache = localIgnite.cache(cacheName);

            if (transactional) {
                try (Transaction tx = localIgnite.transactions().txStart()) {
                    process(cache, entries);
                }
            }
            else {
                process(cache, entries);
            }
        }
    });
    Statistics.recordOperation(System.currentTimeMillis() - processingStartTime);
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:23,代码来源:ServerSideEntryProcessor.java

示例14: createCache

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
/**
 * Creates cache with full configuration. Active store is used.
 *
 * @param cacheName name of cache.
 * @param atomicityMode atomicity.
 * @param cacheMode mode.
 * @param writeBehindEnabled should write behind be used for active store.
 * @param flushFreq flush frequency for write behind.
 * @param base configuration to copy settings from.
 * @param <K> type of key.
 * @param <V> type of value
 * @return cache instance.
 */
@SuppressWarnings("unchecked")
public <K, V> IgniteCache<K, V> createCache(String cacheName, CacheAtomicityMode atomicityMode, CacheMode cacheMode,
    boolean writeBehindEnabled, int flushFreq,
    CacheConfiguration<K, V> base) {
    CacheConfiguration<K, V> realConfiguration = base == null
        ? new CacheConfiguration<K, V>()
        : new CacheConfiguration<K, V>(base);
    realConfiguration.setName(cacheName);
    realConfiguration.setAtomicityMode(atomicityMode);
    realConfiguration.setCacheMode(cacheMode);
    realConfiguration.setBackups(2);
    realConfiguration.setWriteThrough(true);
    realConfiguration.setReadThrough(true);
    realConfiguration.setWriteBehindEnabled(writeBehindEnabled);
    realConfiguration.setWriteBehindFlushFrequency(flushFreq);
    realConfiguration.setCacheStoreFactory(activeStoreConfiguration.activeCacheStoreFactory());
    return ignite().createCache(realConfiguration);
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:32,代码来源:TestResources.java

示例15: testRead

import org.apache.ignite.IgniteCache; //导入依赖的package包/类
/** */
@Test
public void testRead() {
    initializeKV();

    Object[] result = resource.ignite().compute().call(new IgniteCallable<Object[]>() {
        @Override public Object[] call() throws Exception {
            IgniteCache<Object, Object> cache = Ignition.localIgnite().cache(firstCache);
            return new Object[] {
                cache.get("a"),
                cache.get("b"),
                cache.get("c"),
                cache.get("d"),
                cache.get("e")
            };
        }
    });

    Assert.assertEquals("1", result[0]);
    Assert.assertEquals("3", result[1]);
    Assert.assertEquals("4", result[2]);
    Assert.assertNull(result[3]);
    Assert.assertNull(result[4]);
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:25,代码来源:ActiveCacheStoreTest.java


注:本文中的org.apache.ignite.IgniteCache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。