• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NamedCache类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: loadCoherence

import com.tangosol.net.NamedCache; //导入依赖的package包/类
/**
 * Load the cache with 3 trades and 10 legs for each trade.
 * 
 * @throws Exception
 */
private static void loadCoherence() throws Exception {
	NamedCache tradesCache = CacheFactory.getCache(CACHE_NAME);

	// populate the cache
	Map legsMap = new HashMap();
	Trade trade = new Trade();

	for (int i = 1; i <= NUMTRADES; i++) {

		for (int j = 1; j <= NUMLEGS; j++) {
			Leg leg = new Leg();
			leg.setId(j);
			leg.setNotional(i + j);
			legsMap.put(j, leg);
		}
		trade.setId(i);
		trade.setName("NameIs " + i);
		trade.setLegs(legsMap);
		tradesCache.put(i, trade);
	}

	System.out.println("Loaded Coherence");

}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:30,代码来源:TestCoherenceConnection.java


示例2: run

import com.tangosol.net.NamedCache; //导入依赖的package包/类
/**
 * Run method
 */
@Override
public void run() {
    log.trace("run.enter");
    try {
        NamedCache cache = getCache();
        if (populating) {
        	CacheService svc = cache.getCacheService();
        	BackingMapManager mgr = svc.getBackingMapManager();
        	BackingMapManagerContext ctx = mgr.getContext();
        	if (store == null) {
        		Map map = ctx.getBackingMapContext(cache.getCacheName()).getBackingMap(); // got NPE here!!!
        		store = (AbstractCacheStore) ((ReadWriteBackingMap) map).getCacheStore().getStore(); 
        	}
        	populate(cache);
        }
        ensureIndexes(cache);
        ensureTriggers(cache);
        //ensureListener(cache, ctx);
    } catch (Exception ex) {
        log.error("Exception on population: {}", ex.getMessage(), ex);
    }
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:26,代码来源:AbstractPopulator.java


示例3: populateCache

import com.tangosol.net.NamedCache; //导入依赖的package包/类
/**
 * @param cache Named cache
 */
@Override
protected void populateCache(NamedCache cache) {
    final AbstractCacheStore store = getStore();
    if (store.isSupportBatchLoading()) {
        loadBatches(cache);
    } else {
        loadAllAtOnce(cache);
    }

    //stamp = System.currentTimeMillis() - stamp;
    //if (store instanceof SpotRateCacheStore) {
    //    getRFM().addStatisticSeries(Calendar.getInstance().getTime(), true, stamp, cache.size());
    //}
    //log.info("Cache {} populated; time taken: {}", cache.getCacheName(), stamp);
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:19,代码来源:ReplicatedCachePopulator.java


示例4: loadBatches

import com.tangosol.net.NamedCache; //导入依赖的package包/类
protected void loadBatches(NamedCache cache) {
     AbstractCacheStore store = getStore();
     List allKeys = store.getDataKeys();
 	keys = allKeys.size();
 	log.debug("Got {} keys to populate", keys);
     int idx = 0;
     while (idx < keys) {
         GuardSupport.heartbeat();
         int next = Math.min(idx + getBatchSize(), keys);
         queried = next;
         Map data = store.loadAll(allKeys.subList(idx, next));
loaded += data.size();
         cache.putAll(data);
         log.debug("Got {} entities populated", data.size());
         idx += getBatchSize();
batches++;
     }
 }
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:19,代码来源:ReplicatedCachePopulator.java


示例5: putIfAbsent

import com.tangosol.net.NamedCache; //导入依赖的package包/类
@Override
protected <K, V> V putIfAbsent(Map<K, V> map, K key, V value) {
	NamedCache cache = (NamedCache) map;
	try {
		boolean locked = cache.lock(key, timeout);
		if (!locked) {
			throw new IllegalStateException("Can't get lock on cache " + cache.getCacheName() + " for key " + key);
		}

		V val2 = (V) cache.get(key);
		if (val2 == null) {
			map.put(key, value);
			return value;
		}
		getLogger().debug("putIfAbsent; got collision on cache: {}, key: {}; returning: {}", 
				new Object[] {cache.getCacheName(), key, val2});
		return val2;
	} finally {
		cache.unlock(key); 
	}
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:22,代码来源:CoherenceSchemaDictionary.java


示例6: shouldCreateCustomLocalCache

import com.tangosol.net.NamedCache; //导入依赖的package包/类
@Test
public void shouldCreateCustomLocalCache() throws Exception {
    // Given:
    ccf = initialiseCacheFactory(
            "    <caching-scheme-mapping>\n" +
                    "        <cache-mapping>\n" +
                    "            <cache-name>test-cache</cache-name>\n" +
                    "            <scheme-name>custom-local</scheme-name>\n" +
                    "        </cache-mapping>\n" +
                    "    </caching-scheme-mapping>\n" +
                    "    <caching-schemes>\n" +
                    "        <acc:custom-local-scheme>\n" +
                    "            <acc:scheme-name>custom-local</acc:scheme-name>\n" +
                    "            <acc:service-name>CustomLocalService</acc:service-name>\n" +
                    "        </acc:custom-local-scheme>\n" +
                    "    </caching-schemes>\n");

    // When:
    final NamedCache cache = ccf.ensureCache("test-cache", null);

    // Then:
    assertThat(getBackingMap(cache), instanceOf(CustomLocalCache.class));
}
 
开发者ID:datalorax,项目名称:datagrids,代码行数:24,代码来源:CustomLocalCacheTest.java


示例7: shouldCreateDistributedCacheUsingCustomLocalCache

import com.tangosol.net.NamedCache; //导入依赖的package包/类
@Test
public void shouldCreateDistributedCacheUsingCustomLocalCache() throws Exception {
    // Given:
    ccf = initialiseCacheFactory(
            "    <caching-scheme-mapping>\n" +
                    "        <cache-mapping>\n" +
                    "            <cache-name>test-cache</cache-name>\n" +
                    "            <scheme-name>custom-distributed</scheme-name>\n" +
                    "        </cache-mapping>\n" +
                    "    </caching-scheme-mapping>\n" +
                    "    <caching-schemes>\n" +
                    "      <distributed-scheme>\n" +
                    "            <scheme-name>custom-distributed</scheme-name>\n" +
                    "            <service-name>DistributedService</service-name>\n" +
                    "            <backing-map-scheme>\n" +
                    "                <acc:custom-local-scheme/>\n" +
                    "            </backing-map-scheme>\n" +
                    "        </distributed-scheme>" +
                    "    </caching-schemes>\n");

    // When:
    NamedCache cache = ccf.ensureCache("test-cache", null);

    // Then:
    assertThat(getBackingMap(cache), instanceOf(CustomLocalCache.class));
}
 
开发者ID:datalorax,项目名称:datagrids,代码行数:27,代码来源:CustomLocalCacheTest.java


示例8: shouldInjectStandardCacheName

import com.tangosol.net.NamedCache; //导入依赖的package包/类
@Test
public void shouldInjectStandardCacheName() {
    // Given:
    ccf = initialiseCacheFactory(
            "    <caching-scheme-mapping>\n" +
                    "        <cache-mapping>\n" +
                    "            <cache-name>test-cache</cache-name>\n" +
                    "            <scheme-name>custom-local</scheme-name>\n" +
                    "        </cache-mapping>\n" +
                    "    </caching-scheme-mapping>\n" +
                    "    <caching-schemes>\n" +
                    "        <acc:custom-local-scheme>\n" +
                    "            <acc:scheme-name>custom-local</acc:scheme-name>\n" +
                    "            <acc:service-name>CustomLocalService</acc:service-name>\n" +
                    "            <acc:example-custom-string-param>Some Value</acc:example-custom-string-param>\n" +
                    "        </acc:custom-local-scheme>\n" +
                    "    </caching-schemes>\n");

    // When:
    final NamedCache cache = ccf.ensureCache("test-cache", null);

    // Then:
    final CustomLocalCache backingMap = (CustomLocalCache)getBackingMap(cache);
    assertThat(backingMap.getStandardInjectableParam(), is("test-cache"));
}
 
开发者ID:datalorax,项目名称:datagrids,代码行数:26,代码来源:CustomLocalCacheTest.java


示例9: shouldInjectStandardHighUnits

import com.tangosol.net.NamedCache; //导入依赖的package包/类
@Test
public void shouldInjectStandardHighUnits() {
    // Given:
    ccf = initialiseCacheFactory(
            "    <caching-scheme-mapping>\n" +
                    "        <cache-mapping>\n" +
                    "            <cache-name>test-cache</cache-name>\n" +
                    "            <scheme-name>custom-local</scheme-name>\n" +
                    "        </cache-mapping>\n" +
                    "    </caching-scheme-mapping>\n" +
                    "    <caching-schemes>\n" +
                    "        <acc:custom-local-scheme>\n" +
                    "            <acc:scheme-name>custom-local</acc:scheme-name>\n" +
                    "            <acc:service-name>CustomLocalService</acc:service-name>\n" +
                    "            <acc:example-custom-string-param>Some Value</acc:example-custom-string-param>\n" +
                    "            <acc:high-units>32000</acc:high-units>\n" +
                    "        </acc:custom-local-scheme>\n" +
                    "    </caching-schemes>\n");

    // When:
    final NamedCache cache = ccf.ensureCache("test-cache", null);

    // Then:
    final CustomLocalCache backingMap = (CustomLocalCache)getBackingMap(cache);
    assertThat(backingMap.getHighUnits(), is(32000));
}
 
开发者ID:datalorax,项目名称:datagrids,代码行数:27,代码来源:CustomLocalCacheTest.java


示例10: shouldInjectStandardExpiryDelay

import com.tangosol.net.NamedCache; //导入依赖的package包/类
@Test
public void shouldInjectStandardExpiryDelay() {
    // Given:
    ccf = initialiseCacheFactory(
            "    <caching-scheme-mapping>\n" +
                    "        <cache-mapping>\n" +
                    "            <cache-name>test-cache</cache-name>\n" +
                    "            <scheme-name>custom-local</scheme-name>\n" +
                    "        </cache-mapping>\n" +
                    "    </caching-scheme-mapping>\n" +
                    "    <caching-schemes>\n" +
                    "        <acc:custom-local-scheme>\n" +
                    "            <acc:scheme-name>custom-local</acc:scheme-name>\n" +
                    "            <acc:service-name>CustomLocalService</acc:service-name>\n" +
                    "            <acc:example-custom-string-param>Some Value</acc:example-custom-string-param>\n" +
                    "            <acc:expiry-delay>60s</acc:expiry-delay>\n" +
                    "        </acc:custom-local-scheme>\n" +
                    "    </caching-schemes>\n");

    // When:
    final NamedCache cache = ccf.ensureCache("test-cache", null);

    // Then:
    final CustomLocalCache backingMap = (CustomLocalCache)getBackingMap(cache);
    assertThat(backingMap.getExpiryDelay(), is(60 * 1000));
}
 
开发者ID:datalorax,项目名称:datagrids,代码行数:27,代码来源:CustomLocalCacheTest.java


示例11: shouldInjectCustomMacroParam

import com.tangosol.net.NamedCache; //导入依赖的package包/类
@Test
public void shouldInjectCustomMacroParam() {
    // Given:
    ccf = initialiseCacheFactory(
            "    <caching-scheme-mapping>\n" +
                    "        <cache-mapping>\n" +
                    "            <cache-name>test-cache</cache-name>\n" +
                    "            <scheme-name>custom-local</scheme-name>\n" +
                    "        </cache-mapping>\n" +
                    "    </caching-scheme-mapping>\n" +
                    "    <caching-schemes>\n" +
                    "        <acc:custom-local-scheme>\n" +
                    "            <acc:scheme-name>custom-local</acc:scheme-name>\n" +
                    "            <acc:service-name>CustomLocalService</acc:service-name>\n" +
                    "            <acc:example-custom-macro-param>{manager-context}</acc:example-custom-macro-param>\n" +
                    "        </acc:custom-local-scheme>\n" +
                    "    </caching-schemes>\n");

    // When:
    final NamedCache cache = ccf.ensureCache("test-cache", null);

    // Then:
    final CustomLocalCache backingMap = (CustomLocalCache)getBackingMap(cache);
    assertThat(backingMap.getBackingMapManagerContext(), is(notNullValue()));
}
 
开发者ID:datalorax,项目名称:datagrids,代码行数:26,代码来源:CustomLocalCacheTest.java


示例12: shouldInjectCustomLongParam

import com.tangosol.net.NamedCache; //导入依赖的package包/类
@Test
public void shouldInjectCustomLongParam() throws Exception {
    // Given:
    ccf = initialiseCacheFactory(
            "    <caching-scheme-mapping>\n" +
                    "        <cache-mapping>\n" +
                    "            <cache-name>test-cache</cache-name>\n" +
                    "            <scheme-name>custom-local</scheme-name>\n" +
                    "        </cache-mapping>\n" +
                    "    </caching-scheme-mapping>\n" +
                    "    <caching-schemes>\n" +
                    "        <acc:custom-local-scheme>\n" +
                    "            <acc:scheme-name>custom-local</acc:scheme-name>\n" +
                    "            <acc:service-name>CustomLocalService</acc:service-name>\n" +
                    "            <acc:example-custom-long-param>10</acc:example-custom-long-param>\n" +
                    "        </acc:custom-local-scheme>\n" +
                    "    </caching-schemes>\n");

    // When:
    NamedCache cache = ccf.ensureCache("test-cache", null);

    // Then:
    final CustomLocalCache backingMap = (CustomLocalCache)getBackingMap(cache);
    assertThat(backingMap.getExampleCustomLongParam(), is(10L));
}
 
开发者ID:datalorax,项目名称:datagrids,代码行数:26,代码来源:CustomLocalCacheTest.java


示例13: shouldInjectFromResourceRegistry

import com.tangosol.net.NamedCache; //导入依赖的package包/类
@Test
public void shouldInjectFromResourceRegistry() throws Exception {
    // Given:
    ccf = initialiseCacheFactory(
            "    <caching-scheme-mapping>\n" +
                    "        <cache-mapping>\n" +
                    "            <cache-name>test-cache</cache-name>\n" +
                    "            <scheme-name>custom-local</scheme-name>\n" +
                    "        </cache-mapping>\n" +
                    "    </caching-scheme-mapping>\n" +
                    "    <caching-schemes>\n" +
                    "        <acc:custom-local-scheme>\n" +
                    "            <acc:scheme-name>custom-local</acc:scheme-name>\n" +
                    "            <acc:service-name>CustomLocalService</acc:service-name>\n" +
                    "        </acc:custom-local-scheme>\n" +
                    "    </caching-schemes>\n");

    ccf.getResourceRegistry().registerResource(ExampleResource.class, new ExampleResource());

    // When:
    NamedCache cache = ccf.ensureCache("test-cache", null);

    // Then:
    final CustomLocalCache backingMap = (CustomLocalCache)getBackingMap(cache);
    assertThat(backingMap.getExampleInjectedResource(), is(notNullValue()));
}
 
开发者ID:datalorax,项目名称:datagrids,代码行数:27,代码来源:CustomLocalCacheTest.java


示例14: testIndexingCoherenceFilter

import com.tangosol.net.NamedCache; //导入依赖的package包/类
@Test
public void testIndexingCoherenceFilter() throws Exception
{
	NamedCache cache = CacheFactory.getCache("TEST_CACHE");
	// Add to cache
	cache.put(-1, getTestBean(1));
	// River
	XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
	builder.field("type", "coherence");
	builder.startObject("coherence");
	builder.field("cache", "TEST_CACHE");
	builder.field("query", "key() between 500 and 800");
	builder.endObject();
	builder.endObject();

	logger.info("Adding river \n{}", builder.string());
	client().prepareIndex(RiverIndexName.Conf.DEFAULT_INDEX_NAME, "coherence_river_3", "_meta")
			.setSource(builder).get();
	// Add to cache
	for (int i = 0; i < 1000; i++)
	{
		cache.put(i, getTestBean(1));
	}
	checkCount("coherence", 301);
}
 
开发者ID:dmcarba,项目名称:elasticsearch-river-coherence,代码行数:26,代码来源:CoherenceRiverTest.java


示例15: onPutInCache

import com.tangosol.net.NamedCache; //导入依赖的package包/类
/**
 * @see AbstractCacheProviderFacade#onPutInCache(Serializable,CachingModel,
 *Object)
 */
protected void onPutInCache(Serializable key, CachingModel model, Object obj)
		throws CacheException {
	CoherenceCachingModel coherenceCachingModel = (CoherenceCachingModel) model;
	String name = coherenceCachingModel.getCacheName();
	NamedCache cache = getCache(name);

	Long timeToLive = coherenceCachingModel.getTimeToLive();
	if (timeToLive != null) {
		cache.put(key, obj, timeToLive.longValue());
	} else {
		cache.put(key, obj);
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:18,代码来源:CoherenceFacade.java


示例16: add

import com.tangosol.net.NamedCache; //导入依赖的package包/类
public void add(Object key, Object value) throws ResourceException {
	 
		NamedCache sourceCache =  getCache();
		if (sourceCache.containsKey(key)) {
			throw new ResourceException("Unable to add object for key: " + key + " to cache " + this.cacheName + ", because it already exist");
		}
		
		TransactionMap tmap = CacheFactory.getLocalTransaction(sourceCache);

		tmap.setTransactionIsolation(TransactionMap.TRANSACTION_REPEATABLE_GET);
		tmap.setConcurrency(TransactionMap.CONCUR_PESSIMISTIC);
		
		tmap.begin();
		try
		    {
		    tmap.put(key, value);
		    tmap.prepare();
		    tmap.commit();
		    }
		catch (Exception e) {
			throw new ResourceException(e);
		}
		
		sourceCache = getCache();
		if (!sourceCache.containsKey(key)) {
			throw new ResourceException("Problem adding object for key: " + key + " to the cache " + this.cacheName +", object not found after add");
		}
	
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:30,代码来源:CoherenceConnectionImpl.java


示例17: update

import com.tangosol.net.NamedCache; //导入依赖的package包/类
public void update(Object key, Object object) throws ResourceException {
	NamedCache sourceCache =  getCache();
	if (!sourceCache.containsKey(key)) {
		throw new ResourceException("Unable to update object for key: " + key + " to cache " + this.cacheName + ", because it already exist");
	}
	
	TransactionMap tmap = CacheFactory.getLocalTransaction(sourceCache);

	tmap.setTransactionIsolation(TransactionMap.TRANSACTION_REPEATABLE_GET);
	tmap.setConcurrency(TransactionMap.CONCUR_PESSIMISTIC);
	
	tmap.begin();
	try
	    {
	    tmap.put(key, object);
	    tmap.prepare();
	    tmap.commit();
	    }
	catch (Exception e) {
		throw new ResourceException(e);
	}
	
	sourceCache = getCache();
	if (!sourceCache.containsKey(key)) {
		throw new ResourceException("Problem updating object for key: " + key + " to the cache " + this.cacheName +", object not found after add");
	}

	
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:30,代码来源:CoherenceConnectionImpl.java


示例18: remove

import com.tangosol.net.NamedCache; //导入依赖的package包/类
public void remove(Object key) throws ResourceException {
	System.out.println("Remove: " + key);
	NamedCache sourceCache =  getCache();
	if (!sourceCache.containsKey(key)) {
		throw new ResourceException("Unable to remove object for key: " + key + " from cache " + this.cacheName + ", because it doesn't exist");
	}
	
	TransactionMap tmap = CacheFactory.getLocalTransaction(sourceCache);

	tmap.setTransactionIsolation(TransactionMap.TRANSACTION_REPEATABLE_GET);
	tmap.setConcurrency(TransactionMap.CONCUR_OPTIMISTIC);
	
	tmap.begin();
	try
	    {
	    tmap.remove(key);
	    tmap.prepare();
	    tmap.commit();
	    }
	catch (Exception e) {
		throw new ResourceException(e);

	}
	
	if (getCache().containsKey(key)) {
		throw new ResourceException("Unable to remove object for key: " + key + " from the cache " + this.cacheName );
	}

}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:30,代码来源:CoherenceConnectionImpl.java


示例19: loadCoherence

import com.tangosol.net.NamedCache; //导入依赖的package包/类
/**
	 * Load the cache with 3 trades and 10 legs for each trade.
	 * 
	 * @throws Exception
	 */
	private static void loadCoherence() throws Exception {
		NamedCache tradesCache = CacheFactory.getCache(CACHE_NAME);
		TradesCacheSource translator = new TradesCacheSource();
		
		for (int i = 1; i <= NUMTRADES; i++) {

			Trade trade = (Trade) translator.createObjectFromMetadata("org.teiid.translator.coherence.Trade");
//			execFactory.getCacheTranslator().createObject("org.teiid.translator.coherence.Trade");
			
			Map legsMap = new HashMap();
			for (int j = 1; j <= NUMLEGS; j++) {
	
				Object leg = translator.createObjectFromMetadata("org.teiid.translator.coherence.Leg");
					//createObject("org.teiid.translator.coherence.Leg");
					//new Leg();
				if (leg == null) {
					throw new Exception("Unable to create leg");
				}
				translator.setValue("Trade", "LegId", leg, j, long.class);
				translator.setValue("Trade", "Notational", leg, j, double.class);
				translator.setValue("Trade", "Name", leg, "LegName " + j, String.class);
				
				legsMap.put(j, leg);
			}
			
			translator.setValue("Trade", "TradeId", trade, i, long.class);
			translator.setValue("Trade", "Name", trade, "TradeName " + i, String.class);
			translator.setValue("Trade", "Legs", trade, legsMap, Map.class);
			
			tradesCache.put(i, trade);
		}


	}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:40,代码来源:TradesCacheSource.java


示例20: getDistributedMap

import com.tangosol.net.NamedCache; //导入依赖的package包/类
public Map getDistributedMap(String name) {		 
	NamedCache sharedCache = null;
	try {
		sharedCache = CacheFactory.getCache(name);			
	} catch (Exception e) {
		e.printStackTrace();
		throw new IllegalStateException(e.getMessage());
	}
	return sharedCache;
}
 
开发者ID:qafedev,项目名称:qafe-platform,代码行数:11,代码来源:CacheManager.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CmdLineParser类代码示例发布时间:2022-05-21
下一篇:
Java PackageResourceReference类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap