本文整理汇总了Java中javax.cache.Cache.Entry类的典型用法代码示例。如果您正苦于以下问题:Java Entry类的具体用法?Java Entry怎么用?Java Entry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Entry类属于javax.cache.Cache包,在下文中一共展示了Entry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: selectGeneByChromsomeCriteria
import javax.cache.Cache.Entry; //导入依赖的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();
}
示例2: getChromosomes
import javax.cache.Cache.Entry; //导入依赖的package包/类
/**
* Retrieve chromosomes
*
* @param ignite
* @param query
* @return
*/
public static List<Chromosome> getChromosomes(Ignite ignite, String query)
{
List<Chromosome> chromosomes = new ArrayList();
IgniteCache<Long, Chromosome> populationCache = ignite.getOrCreateCache(PopulationCacheConfig.populationCache());
SqlQuery sql = new SqlQuery(Chromosome.class, query);
try (QueryCursor<Entry<Long, Chromosome>> cursor = populationCache.query(sql)) {
for (Entry<Long, Chromosome> e : cursor)
chromosomes.add(e.getValue());
}
return chromosomes;
}
示例3: getGenesForChromosome
import javax.cache.Cache.Entry; //导入依赖的package包/类
/**
*
* @param ignite
* @param chromosome
* @return List<Gene>
*/
public static List<Gene> getGenesForChromosome(Ignite ignite, Chromosome chromosome) {
List<Gene> genes = new ArrayList();
IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);
StringBuffer sbSqlClause = new StringBuffer();
sbSqlClause.append("_key IN ");
String sqlInClause = Arrays.toString(chromosome.getGenes());
sqlInClause = sqlInClause.replace("[", "(");
sqlInClause = sqlInClause.replace("]", ")");
sbSqlClause.append(sqlInClause);
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;
}
示例4: selectGeneByChromsomeCriteria
import javax.cache.Cache.Entry; //导入依赖的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();
}
示例5: getChromosome
import javax.cache.Cache.Entry; //导入依赖的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;
}
示例6: maybeFireExistingQueryResults
import javax.cache.Cache.Entry; //导入依赖的package包/类
private void maybeFireExistingQueryResults() {
if (!endpoint.isFireExistingQueryResults()) {
LOG.info(String.format("Skipping existing cache results for cache name = %s.", endpoint.getCacheName()));
return;
}
LOG.info(String.format("Processing existing cache results for cache name = %s.", endpoint.getCacheName()));
for (Entry<Object, Object> entry : cursor) {
Exchange exchange = createExchange(entry.getValue());
exchange.getIn().setHeader(IgniteConstants.IGNITE_CACHE_KEY, entry.getKey());
getAsyncProcessor().process(createExchange(entry), new AsyncCallback() {
@Override
public void done(boolean doneSync) {
// do nothing
}
});
}
}
示例7: testQuery
import javax.cache.Cache.Entry; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testQuery() {
IgniteCache<String, String> cache = ignite().getOrCreateCache("testcache1");
Set<String> keys = new HashSet<>();
for (int i = 0; i < 100; i++) {
cache.put("k" + i, "v" + i);
keys.add("k" + i);
}
Query<Entry<String, String>> query = new ScanQuery<String, String>(new IgniteBiPredicate<String, String>() {
private static final long serialVersionUID = 1L;
@Override
public boolean apply(String key, String value) {
return Integer.parseInt(key.replace("k", "")) >= 50;
}
});
List results = template.requestBodyAndHeader("ignite:cache:testcache1?operation=QUERY", keys, IgniteConstants.IGNITE_CACHE_QUERY, query, List.class);
assert_().that(results.size()).isEqualTo(50);
}
示例8: get
import javax.cache.Cache.Entry; //导入依赖的package包/类
public List<Person> get(String name, String timesplice) {
IgniteCache<UUID, Person> cache = ignite.cache(timesplice);
if (cache == null) {
return Arrays.asList();
}
SqlQuery<Object, Object> sqlQuery = new SqlQuery<>(Person.class, " name = ?").setArgs(name);
List<Person> list = new ArrayList<>();
try (QueryCursor<Entry<Object, Object>> queryCursor = cache.query(sqlQuery)) {
for (Entry<Object, Object> entry : queryCursor) {
list.add((Person) entry.getValue());
}
}
return list;
}
示例9: main
import javax.cache.Cache.Entry; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
try (Ignite ignite = Ignition.start("config/default-config.xml")) {
CacheConfiguration<String, LocalDateTime> cacheCfg = new CacheConfiguration<>("CacheQueriesScanQueryExample");
cacheCfg.setCacheMode(CacheMode.PARTITIONED).setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 3)));
try (IgniteCache<String, LocalDateTime> igniteCache = ignite.getOrCreateCache(cacheCfg)) {
LocalDateTime now = LocalDateTime.now();
igniteCache.put("doctor", now);
igniteCache.put("doctor who", now.plusHours(10L));
igniteCache.put("doctor who", now.minusYears(1L));
System.out.println("--------ScanQuery----------");
try (QueryCursor<Entry<Object, Object>> query = igniteCache.query(new ScanQuery<>((k, v) -> v.equals(now)))) {
for (Entry<Object, Object> entry : query) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
}
}
}
}
示例10: peekNext
import javax.cache.Cache.Entry; //导入依赖的package包/类
/**
* Peeks the next element. Calling this method multiple times will always return
* the same value, until {@link #next()} is called. This method skips all invalid
* Holders.
*
* @return The next element, or null if there is no next element
*/
private java.util.Map.Entry<K, AccessTimeObjectHolder<V>> peekNext()
{
if (nextElement != null)
return nextElement;
while (true)
{
if (!mapIterator.hasNext())
return null;
java.util.Map.Entry<K, AccessTimeObjectHolder<V>> entry = mapIterator.next();
AccessTimeObjectHolder<V> holder = entry.getValue();
if (!holder.isInvalid())
{
nextElement = entry;
return nextElement;
}
}
}
示例11: peekNext
import javax.cache.Cache.Entry; //导入依赖的package包/类
/**
* Peeks the next element. Calling this method multiple times will always return
* the same value, until {@link #next()} is called. This method skips all invalid
* Holders.
*
* @return The next element, or null if there is no nbext element
*/
private java.util.Map.Entry<K, AccessTimeObjectHolder<V>> peekNext()
{
if (nextElement != null)
return nextElement;
while (true)
{
if (!mapIterator.hasNext())
return null;
java.util.Map.Entry<K, AccessTimeObjectHolder<V>> entry = mapIterator.next();
AccessTimeObjectHolder<V> holder = entry.getValue();
if (!holder.isInvalid())
{
nextElement = entry;
return nextElement;
}
}
}
示例12: testExpire
import javax.cache.Cache.Entry; //导入依赖的package包/类
/**
* Simple expiration time check.
*
* <pre>
* -|-|-------------------------|-|---------------------> t
* | | | |
* | timePutAtOrBefore | timeMustExpireBefore = timePutAtOrBefore + maxIdleTime
* | |
* cache.put() actual expiration time (10 ms precision)
* </pre>
*/
@Test
public void testExpire()
{
cache.put("1", 2);
long timePutAtOrBefore = System.currentTimeMillis();
TCacheHolderIterator<String, Integer> iterator = cache.iterator();
Entry<String, TCacheHolder<Integer>> first = iterator.next();
TCacheHolder<Integer> holder = first.getValue();
// long timeNow = System.currentTimeMillis();
long timeMustExpireBefore = timePutAtOrBefore + maxIdleTimeMillis*1000;
long expTime = holder.getExpirationTime();
assertTrue("expirationTime later than expected: " + holder.getExpirationTime() + " >= " + timeMustExpireBefore, expTime < timeMustExpireBefore);
}
示例13: getGenesInOrderForChromosome
import javax.cache.Cache.Entry; //导入依赖的package包/类
/**
*
* 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;
}
示例14: writeAll
import javax.cache.Cache.Entry; //导入依赖的package包/类
@Override
public void writeAll(Collection<Entry<? extends K, ? extends V>> entries)
throws CacheWriterException {
List<Put> puts = createPuts(entries);
long start = System.currentTimeMillis();
put(puts);
long time = System.currentTimeMillis() - start;
logger.debug("Put " + puts.size() + " values in " + time + "ms");
}
示例15: createPut
import javax.cache.Cache.Entry; //导入依赖的package包/类
private Put createPut(Entry<? extends K, ? extends V> entry) {
try {
Put put = new Put(keySerializer.serialize(entry.getKey()));
put.addColumn(family(), QUALIFIER, valueSerializer.serialize(entry.getValue()));
return put;
} catch (SerializationException e) {
throw new CacheWriterException("Failed to create put", e);
}
}