Java Code Examples for org.apache.ignite.IgniteCache

The following are top voted examples for showing how to use org.apache.ignite.IgniteCache. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: spring-boot-ignite   File: CleanExpiredAlertsService.java   View source code 6 votes vote down vote up
@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())));

    }

}
 
Example 2
Project: akka-persistance-ignite   File: JournalStoreInterceptor.java   View source code 6 votes vote down vote up
@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;
    });
}
 
Example 3
Project: akka-persistance-ignite   File: SnapshotCacheProvider.java   View source code 6 votes vote down vote up
/**
 * @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);
}
 
Example 4
Project: Higher-Cloud-Computing-Project   File: BlockMatrixStorage.java   View source code 6 votes vote down vote up
/**
 * 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());
    });
}
 
Example 5
Project: eventapis   File: EventController.java   View source code 6 votes vote down vote up
@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());
    }
 
Example 6
Project: gagrid   File: GAGrid.java   View source code 6 votes vote down vote up
/**
 * 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();
}
 
Example 7
Project: gagrid   File: MutateTask.java   View source code 6 votes vote down vote up
/**
 * 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();
}
 
Example 8
Project: gagrid   File: TruncateSelectionTask.java   View source code 6 votes vote down vote up
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;
}
 
Example 9
Project: Lagerta   File: JDBCDataCapturerLoaderIntegrationTest.java   View source code 6 votes vote down vote up
@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);
}
 
Example 10
Project: Lagerta   File: SubscriberIntegrationTest.java   View source code 6 votes vote down vote up
@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);
}
 
Example 11
Project: Lagerta   File: MetadataAtomicsHelper.java   View source code 6 votes vote down vote up
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);
            }
        }
    };
}
 
Example 12
Project: Lagerta   File: SimulationUtil.java   View source code 6 votes vote down vote up
/** */
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;
}
 
Example 13
Project: Lagerta   File: ServerSideEntryProcessor.java   View source code 6 votes vote down vote up
/** {@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);
}
 
Example 14
Project: Lagerta   File: TestResources.java   View source code 6 votes vote down vote up
/**
 * 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);
}
 
Example 15
Project: Lagerta   File: ActiveCacheStoreTest.java   View source code 6 votes vote down vote up
/** */
@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]);
}
 
Example 16
Project: Higher-Cloud-Computing-Project   File: CacheUtils.java   View source code 6 votes vote down vote up
/**
 * @param cacheName Cache name.
 * @param fun An operation that accepts a cache entry and processes it.
 * @param ignite Ignite.
 * @param keysGen Keys generator.
 * @param <K> Cache key object type.
 * @param <V> Cache value object type.
 */
public static <K, V> void update(String cacheName, Ignite ignite, IgniteConsumer<Cache.Entry<K, V>> fun,
    IgniteSupplier<Set<K>> keysGen) {
    bcast(cacheName, ignite, () -> {
        Ignite ig = Ignition.localIgnite();
        IgniteCache<K, V> cache = ig.getOrCreateCache(cacheName);

        Affinity<K> affinity = ig.affinity(cacheName);
        ClusterNode locNode = ig.cluster().localNode();

        Collection<K> ks = affinity.mapKeysToNodes(keysGen.get()).get(locNode);

        if (ks == null)
            return;

        Map<K, V> m = new ConcurrentHashMap<>();

        for (K k : ks) {
            V v = cache.localPeek(k);
            fun.accept(new CacheEntryImpl<>(k, v));
            m.put(k, v);
        }

        cache.putAll(m);
    });
}
 
Example 17
Project: Lagerta   File: SimulationTxProcessor.java   View source code 6 votes vote down vote up
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;
}
 
Example 18
Project: hibernate-ogm-ignite   File: IgniteDatastoreProvider.java   View source code 6 votes vote down vote up
private <K, V> IgniteCache<K, V> getCache(String entityCacheName, boolean keepBinary) {
	IgniteCache<K, V> cache = null;
	try {
		cache = cacheManager.cache( entityCacheName );
	}
	catch (IllegalStateException ex) {
		if ( Ignition.state( gridName ) == IgniteState.STOPPED ) {
			log.stoppedIgnite();
			restart();
			cache = cacheManager.cache( entityCacheName );
		}
		else {
			throw ex;
		}

	}
	if ( cache == null ) {
		throw log.cacheNotFound( entityCacheName );
	}
	if ( keepBinary ) {
		cache = cache.withKeepBinary();
	}
	return cache;
}
 
Example 19
Project: Higher-Cloud-Computing-Project   File: CacheColumnDecisionTreeTrainerInput.java   View source code 6 votes vote down vote up
/**
 * Constructs input for {@link ColumnDecisionTreeTrainer}.
 *
 * @param c Cache.
 * @param valuesMapper Function for mapping cache entry to stream used by {@link ColumnDecisionTreeTrainer}.
 * @param labelsMapper Function used for mapping cache value to labels array.
 * @param keyMapper Function used for mapping feature index to the cache key.
 * @param catFeaturesInfo Information about which features are categorical in form of feature index -> number of
 * categories.
 * @param featuresCnt Count of features.
 * @param samplesCnt Count of samples.
 */
// TODO: IGNITE-5724 think about boxing/unboxing
public CacheColumnDecisionTreeTrainerInput(IgniteCache<K, V> c,
    IgniteSupplier<Stream<K>> labelsKeys,
    IgniteFunction<Cache.Entry<K, V>, Stream<IgniteBiTuple<Integer, Double>>> valuesMapper,
    IgniteFunction<V, DoubleStream> labelsMapper,
    IgniteFunction<Integer, Stream<K>> keyMapper,
    Map<Integer, Integer> catFeaturesInfo,
    int featuresCnt, int samplesCnt) {

    cacheName = c.getName();
    this.labelsKeys = labelsKeys;
    this.valuesMapper = valuesMapper;
    this.labelsMapper = labelsMapper;
    this.keyMapper = keyMapper;
    this.catFeaturesInfo = catFeaturesInfo;
    this.samplesCnt = samplesCnt;
    this.featuresCnt = featuresCnt;
}
 
Example 20
Project: hibernate-ogm-ignite   File: IgniteTestHelper.java   View source code 6 votes vote down vote up
@Override
public Map<String, Object> extractEntityTuple(Session session, EntityKey key) {
	SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) session.getSessionFactory();
	IgniteCache<Object, BinaryObject> cache = getEntityCache( sessionFactory, key.getMetadata() );
	Object cacheKey = getProvider( sessionFactory ).createKeyObject( key );

	Map<String, Object> result = new HashMap<>();
	BinaryObject po = cache.get( cacheKey );

	TupleSnapshot snapshot = new IgniteTupleSnapshot( cacheKey, po, key.getMetadata() );
	for ( String fieldName : snapshot.getColumnNames() ) {
		result.put( fieldName, snapshot.get( fieldName ) );
	}

	return result;
}
 
Example 21
Project: Higher-Cloud-Computing-Project   File: BlockMatrixStorage.java   View source code 6 votes vote down vote up
/**
 * Distributed matrix set.
 *
 * @param a Row or column index.
 * @param b Row or column index.
 * @param v New value to set.
 */
private void matrixSet(int a, int b, double v) {
    IgnitePair<Long> blockId = getBlockId(a, b);
    // Remote set on the primary node (where given row or column is stored locally).
    ignite().compute(getClusterGroupForGivenKey(CACHE_NAME, blockId)).run(() -> {
        IgniteCache<MatrixBlockKey, MatrixBlockEntry> cache = Ignition.localIgnite().getOrCreateCache(CACHE_NAME);

        MatrixBlockKey key = getCacheKey(blockId.get1(), blockId.get2());

        // Local get.
        MatrixBlockEntry block = getEntryById(blockId);

        block.set(a % block.rowSize(), b % block.columnSize(), v);

        // Local put.
        cache.put(key, block);
    });
}
 
Example 22
Project: spring-boot-ignite   File: IgniteAlertsStore.java   View source code 5 votes vote down vote up
@Override
public void updateAlertEntry(String serviceId, String serviceCode, AlertEntry alertEntry) {
    final IgniteCache<String, AlertEntry> alertsCache = getAlertsCache();
    // update the alert entry via cache invoke for atomicity
    alertsCache.invoke(alertEntry.getAlertId(), (mutableEntry, objects) -> {
        if (mutableEntry.exists() && mutableEntry.getValue() != null) {
            logger.debug("updating alert entry into the cache store invoke: {},{}", serviceId, serviceCode);
            mutableEntry.setValue(alertEntry);
        } else {
            throw new ResourceNotFoundException(String.format("Alert for %s with %s not found", serviceId, serviceCode));
        }
        // by api design nothing needed here
        return null;
    });
}
 
Example 23
Project: Higher-Cloud-Computing-Project   File: CacheVectorStorage.java   View source code 5 votes vote down vote up
/**
 * @param size Vector size.
 * @param cache Ignite cache.
 * @param keyMapper {@link VectorKeyMapper} to validate cache key.
 * @param valMapper {@link ValueMapper} to obtain value for given cache key.
 */
public CacheVectorStorage(int size, IgniteCache<K, V> cache, VectorKeyMapper<K> keyMapper,
    ValueMapper<V> valMapper) {
    assert size > 0;
    assert cache != null;
    assert keyMapper != null;
    assert valMapper != null;

    this.size = size;
    this.cache = cache;
    this.keyMapper = keyMapper;
    this.valMapper = valMapper;
}
 
Example 24
Project: spring-boot-ignite   File: IgniteAlertsSoreTest.java   View source code 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    when(ignite.getOrCreateCache(anyString())).thenReturn(IgniteCache);
    List<AlertEntry> entries=new ArrayList<>();
    entries.add(AlertEntry.builder().errorCode("errorCode").build());
    when(IgniteCache.get(anyString())).thenReturn(entries);
}
 
Example 25
Project: ignite_world_demo   File: KeyValueBinaryDataProcessing.java   View source code 5 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
    Ignition.setClientMode(true);

    try (Ignite ignite = Ignition.start("config/ignite-config.xml")) {
        IgniteCache<BinaryObject, BinaryObject> cityCacheBinary = ignite.cache(CITY_CACHE_NAME).withKeepBinary();

        accessCityCache(ignite, cityCacheBinary);

        migrateBetweenCities(ignite, cityCacheBinary);
    }
}
 
Example 26
Project: gagrid   File: GAGridUtils.java   View source code 5 votes vote down vote up
/**
 * 
 * Retrieve genes in order
 * 
 * @param ignite
 * @param chromosome
 * @return List<Gene>
 */

public static List<Gene> getGenesInOrderForChromosome(Ignite ignite, Chromosome chromosome) {
    List<Gene> genes = new ArrayList();
    IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);
  
    long[] primaryKeys = chromosome.getGenes();
    
    for (int k =0; k< primaryKeys.length; k++)
    {
    
      StringBuffer sbSqlClause = new StringBuffer();
      sbSqlClause.append("_key IN ");
      sbSqlClause.append("(");
      sbSqlClause.append(primaryKeys[k]);
      sbSqlClause.append(")");
      
      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());
        }
    }
   
    return genes;
}
 
Example 27
Project: Lagerta   File: JDBCDataCapturerLoaderIntegrationTest.java   View source code 5 votes vote down vote up
@Test(dataProvider = DataProviders.KV_META_PROVIDER)
public void partiallyFoundLoadAll(KeyValueAndMetadata kvMeta, String dbMode) throws SQLException {
    JDBCUtil.setDBMode(dataSource, dbMode);
    JDBCUtil.insertIntoDB(dataSource, kvMeta);

    IgniteCache<Integer, Object> cache = ignite().cache(kvMeta.getCacheName());

    Map<Integer, Object> results = cache.getAll(DataProviders.KEYS);
    Map<Integer, Object> expected = Collections.singletonMap(kvMeta.getKey(), kvMeta.getUnwrappedValue());

    assertEquals(results, expected);
}
 
Example 28
Project: Lagerta   File: JDBCDataCapturerLoaderIntegrationTest.java   View source code 5 votes vote down vote up
@Test(dataProvider = DataProviders.KV_META_PROVIDER)
public void loadPerson(KeyValueAndMetadata kvMeta, String dbMode) throws SQLException {
    JDBCUtil.setDBMode(dataSource, dbMode);
    JDBCUtil.insertIntoDB(dataSource, kvMeta);

    IgniteCache<Integer, Object> cache = ignite().cache(kvMeta.getCacheName());

    Object result = cache.get(kvMeta.getKey());
    Object expected = kvMeta.getUnwrappedValue();

    assertEquals(result, expected);
}
 
Example 29
Project: Lagerta   File: SubscriberIntegrationTest.java   View source code 5 votes vote down vote up
@Test(dataProvider = CACHE_INFO_PROVIDER)
public void sequentialTransactions(String cacheName, boolean asBinary) throws Exception {
    IgniteCache<Integer, PrimitivesHolder> cache = ignite().cache(cacheName);
    PrimitivesHolder first = DataProviders.PH_1;
    PrimitivesHolder second = DataProviders.PH_2;

    cache.put(1, first);
    cache.put(1, second);
    awaitTransactions();

    assertObjectsInDB(Collections.singletonMap(1, second), asBinary);
}
 
Example 30
Project: Higher-Cloud-Computing-Project   File: BiIndexedCacheColumnDecisionTreeTrainerInput.java   View source code 5 votes vote down vote up
/**
 * Construct an input for {@link ColumnDecisionTreeTrainer}.
 *
 * @param cache Bi-indexed cache.
 * @param catFeaturesInfo Information about categorical feature in the form (feature index -> number of
 * categories).
 * @param samplesCnt Count of samples.
 * @param featuresCnt Count of features.
 */
public BiIndexedCacheColumnDecisionTreeTrainerInput(IgniteCache<BiIndex, Double> cache,
    Map<Integer, Integer> catFeaturesInfo, int samplesCnt, int featuresCnt) {
    super(cache,
        () -> IntStream.range(0, samplesCnt).mapToObj(s -> new BiIndex(s, featuresCnt)),
        e -> Stream.of(new IgniteBiTuple<>(e.getKey().row(), e.getValue())),
        DoubleStream::of,
        fIdx -> IntStream.range(0, samplesCnt).mapToObj(s -> new BiIndex(s, fIdx)),
        catFeaturesInfo,
        featuresCnt,
        samplesCnt);
}
 
Example 31
Project: Higher-Cloud-Computing-Project   File: SparseDistributedMatrixStorage.java   View source code 5 votes vote down vote up
/**
 * 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, a)).call(() -> {
        IgniteCache<RowColMatrixKey, Map<Integer, Double>> cache = Ignition.localIgnite().getOrCreateCache(CACHE_NAME);

        // Local get.
        Map<Integer, Double> map = cache.localPeek(getCacheKey(a), CachePeekMode.PRIMARY);

        if (map == null)
            map = cache.get(getCacheKey(a));

        return (map == null || !map.containsKey(b)) ? 0.0 : map.get(b);
    });
}
 
Example 32
Project: Lagerta   File: ReadWorker.java   View source code 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public void process(IgniteCache cache, Map<?, ?> entries) {
    for (Map.Entry<?, ?> entry : entries.entrySet()) {
        cache.get(entry.getKey());
    }
}
 
Example 33
Project: Lagerta   File: BulkReadWorker.java   View source code 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public void process(IgniteCache cache, Map<?, ?> entries) {
    cache.getAll(entries.keySet());
}
 
Example 34
Project: Lagerta   File: WriteWorker.java   View source code 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public void process(IgniteCache cache, Map<?, ?> entries) {
    for (Map.Entry<?, ?> entry : entries.entrySet()) {
        cache.put(entry.getKey(), entry.getValue());
    }
}
 
Example 35
Project: Lagerta   File: TestResources.java   View source code 5 votes vote down vote up
/**
 * Creates cache with minimal configuration. Active store is not used.
 *
 * @param cacheName name of cache.
 * @param atomicityMode atomicity.
 * @param cacheMode mode.
 * @param base configuration to copy settings from.
 * @param <K> type of key.
 * @param <V> type of value
 * @return cache instance.
 */
public <K, V> IgniteCache<K, V> createSimpleCache(String cacheName, CacheAtomicityMode atomicityMode,
    CacheMode cacheMode, 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);
    return ignite().createCache(realConfiguration);
}
 
Example 36
Project: Lagerta   File: BaseCacheStoreTest.java   View source code 5 votes vote down vote up
/** */
protected Map<Object, Object> readFromCache(final String cacheName, final String... keys) {
    return resource.ignite().compute().call(new IgniteCallable<Map<Object, Object>>() {
        @Override public Map<Object, Object> call() throws Exception {
            IgniteCache<Object, Object> cache = Ignition.localIgnite().cache(cacheName);
            return cache.getAll(Sets.newHashSet(keys));
        }
    });
}
 
Example 37
Project: Higher-Cloud-Computing-Project   File: GroupTrainer.java   View source code 5 votes vote down vote up
/**
 * Construct an instance of this class.
 *
 * @param cache Cache on which training is performed.
 * @param ignite Ignite instance.
 */
GroupTrainer(
    IgniteCache<GroupTrainerCacheKey<K>, V> cache,
    Ignite ignite) {
    this.cache = cache;
    this.ignite = ignite;
}
 
Example 38
Project: ignite_world_demo   File: KeyValueDataProcessing.java   View source code 5 votes vote down vote up
/**
 * Moving people between cities using transactions.
 *
 * @param ignite Ignite connection reference.
 * @param cityCache City cache.
 */
private static void migrateBetweenCities(Ignite ignite, IgniteCache<CityKey, City> cityCache) {
    IgniteTransactions igniteTx = ignite.transactions();

    /** Amsterdam Key. */
    CityKey amKey = new CityKey(5, "NLD");

    /** Berlin Key. */
    CityKey berKey = new CityKey(3068, "DEU");

    System.out.println();
    System.out.println(">> Moving people between Amsterdam and Berlin");

    try (Transaction tx = igniteTx.txStart(TransactionConcurrency.PESSIMISTIC,TransactionIsolation.REPEATABLE_READ)) {
        City amsterdam = cityCache.get(amKey);
        City berlin = cityCache.get(berKey);

        System.out.println(">> Before update:");
        System.out.println(amsterdam);
        System.out.println(berlin);

        /** Moving people between cities. **/
        amsterdam.setPopulation(amsterdam.getPopulation() + 100_000);
        berlin.setPopulation(berlin.getPopulation() - 100_000);

        /** Applying changes in a transactional fashion. */
        cityCache.put(amKey, amsterdam);
        cityCache.put(berKey, berlin);
    }

    City amsterdam = cityCache.get(amKey);
    City berlin = cityCache.get(berKey);

    System.out.println(">> After update:");
    System.out.println(amsterdam);
    System.out.println(berlin);
}
 
Example 39
Project: Lagerta   File: BasicSynchronousReplicationIntegrationTest.java   View source code 5 votes vote down vote up
Map<Integer, Integer> readValuesFromCache(Ignite ignite) {
    IgniteCache<Integer, Integer> cache = ignite.cache(CACHE_NAME);
    Set<Integer> keys = new HashSet<>();
    for (int i = startIndex; i < endIndex; i++) {
        keys.add(i);
    }
    return cache.getAll(keys);
}
 
Example 40
Project: Lagerta   File: BasicSynchronousReplicationIntegrationTest.java   View source code 5 votes vote down vote up
void writeValuesToCache(Ignite ignite, boolean withReplication, int startIdx, int endIdx, int modifier) {
    try (Transaction tx = ignite.transactions().txStart()) {
        IgniteCache<Integer, Integer> cache = ignite.cache(CACHE_NAME);
        if (!withReplication) {
            cache = cache.withSkipStore();
        }
        for (int i = startIdx; i < endIdx; i++) {
            cache.put(i, i + modifier);
        }
        tx.commit();
    }
}