當前位置: 首頁>>代碼示例>>Java>>正文


Java GridCache類代碼示例

本文整理匯總了Java中org.gridgain.grid.cache.GridCache的典型用法代碼示例。如果您正苦於以下問題:Java GridCache類的具體用法?Java GridCache怎麽用?Java GridCache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GridCache類屬於org.gridgain.grid.cache包,在下文中一共展示了GridCache類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: tryCache

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
private static GridCache tryCache(String name) {
    GridCache cache = null;

    if (state.equals(ConnState.CONNECTED)) {
        logger.fine("[State " + state.name() + "] Trying to get cache " + name + " from the grid cause im connected to it");

        try {
            cache = grid.cache(name);
        } catch (RuntimeException e) {
            logger.log(Level.SEVERE, "Runtime exception when calling cache: " + e.getMessage());
            notifyFail();
        }
    } else {
        logger.fine("[State " + state.name() + "] Tried to get cache " + name + " from the grid, but im not connected");
    }

    return cache;
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:19,代碼來源:GridGainManager.java

示例2: main

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public static void main(String[] args) throws FileNotFoundException, IOException, GridException, InterruptedException {
	try (AnnotationConfigApplicationContext appCtx = new AnnotationConfigApplicationContext(LumenConfig.class)) {
		Grid grid = appCtx.getBean(Grid.class);
		
		GridCache<String, YagoRule> ruleCache = YagoRule.cache(grid);
		GridCache<String, YagoLabel> labelCache = YagoLabel.cache(grid);
		GridCache<String, ListMultimap<String, String>> entityByLabelCache = YagoLabel.entityByLabelCache(grid);
		
		grid.compute().broadcast((GridRunnable) () -> {
			try {
				log.info("For yagoRule, I have {} primary out of {} entries + {} swap", 
						ruleCache.primarySize(), ruleCache.size(), ruleCache.swapKeys());
				log.info("For yagoLabel, I have {} primary out of {} entries + {} swap", 
						labelCache.primarySize(), labelCache.size(), labelCache.swapKeys());
				log.info("For entityByLabel, I have {} primary out of {} entries + {} swap", 
						entityByLabelCache.primarySize(), entityByLabelCache.size(), entityByLabelCache.swapKeys());
			} catch (Exception e) {
				log.error("swapKeys error", e);
			}
		});
	}
	
}
 
開發者ID:lumenrobot,項目名稱:lumen-kb,代碼行數:24,代碼來源:CacheStatsCli.java

示例3: main

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public static void main(String[] args) throws GridException {
		try (Grid grid = GridGain.start(
				System.getProperty("user.home") + "/gridgain-platform-os-6.1.9-nix/examples/config/example-cache.xml")) {
			GridCache<Integer, String> cache = grid.cache("partitioned");
//			String oldVal = cache.put(1, "1");
//			boolean success = cache.putx(2, "2");
//			boolean success2 = cache.putxIfAbsent(3, "3");
//			log.info("Current 3 value = {}", cache.get(3));
//			cache.transform(3, (it) -> it + "-transformed");
			log.info("Transformed 3 value = {}", cache.get(3));
		}
	}
 
開發者ID:ceefour,項目名稱:gggettingstarted,代碼行數:13,代碼來源:BasicOperations.java

示例4: main

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public static void main(String[] args) throws GridException {
		try (Grid grid = GridGain.start(
				System.getProperty("user.home") + "/gridgain-platform-os-6.1.9-nix/examples/config/example-cache.xml")) {
			GridCache<Integer, Oya> cache = grid.cache("partitioned");
//			String oldVal = cache.put(1, "1");
//			boolean success = cache.putx(2, "2");
			boolean success2 = cache.putxIfAbsent(3, new Oya("3"));
			log.info("Current 3 value = {}", cache.get(3));
			cache.transform(3, (it) -> new Oya(it.name + "-transformed"));
			log.info("Transformed 3 value = {}", cache.get(3));
		}
	}
 
開發者ID:ceefour,項目名稱:gggettingstarted,代碼行數:13,代碼來源:BasicOperations2.java

示例5: main

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public static void main(String[] args) throws FileNotFoundException, IOException, GridException, InterruptedException {
		try (AnnotationConfigApplicationContext appCtx = new AnnotationConfigApplicationContext(LumenConfig.class)) {
			Grid grid = appCtx.getBean(Grid.class);
			
			GridCache<String, YagoRule> ruleCache = YagoRule.cache(grid);
			if (ruleCache.isEmpty()) {
				log.info("Loading rules...");
				ruleCache.loadCache(null, 0);
			}
			log.info("For yagoRule, I have {} primary out of {} entries + {} swap", 
					ruleCache.primarySize(), ruleCache.size(), ruleCache.swapKeys());
			
			GridCache<String, YagoLabel> labelCache = YagoLabel.cache(grid);
//			if (labelCache.isEmpty()) {
//				log.info("Loading labels...");
//				labelCache.loadCache(null, 0);
//			}
			log.info("For yagoLabel, I have {} primary out of {} entries + {} swap", 
					labelCache.primarySize(), labelCache.size(), labelCache.swapKeys());
			
			GridCache<String, ListMultimap<String, String>> entityByLabelCache = YagoLabel.entityByLabelCache(grid);
//			if (labelCache.isEmpty()) {
//				log.info("Loading labels...");
//				labelCache.loadCache(null, 0);
//			}
			log.info("For entityByLabel, I have {} primary out of {} entries + {} swap", 
					entityByLabelCache.primarySize(), entityByLabelCache.size(), entityByLabelCache.swapKeys());
			
			Thread.currentThread().join();
		}
	}
 
開發者ID:lumenrobot,項目名稱:lumen-kb,代碼行數:32,代碼來源:Worker.java

示例6: main

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public static void main(String[] args) throws FileNotFoundException, IOException, GridException {
	String entityId = "Muhammad";
	
	try (AnnotationConfigApplicationContext appCtx = new AnnotationConfigApplicationContext(LumenConfig.class)) {
		Grid grid = appCtx.getBean(Grid.class);
		GridCache<String, YagoLabel> labelCache = YagoLabel.cache(grid);
		log.info("Label for {}: {}", entityId, labelCache.get(entityId));
	}
	
}
 
開發者ID:lumenrobot,項目名稱:lumen-kb,代碼行數:11,代碼來源:YagoSimpleLabelLookupCli.java

示例7: main

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public static void main(String[] args) throws FileNotFoundException, IOException, GridException {
		String upLabel = "Muhammad";
		
		try (Grid grid = GridGain.start(YagoLabelLookupCli2.class.getResource("yago.gridgain.xml"))) {
			GridCache<String, String> labelCache = grid.cache("yagoLabel");
//			labelCache.queries().createScanQuery(null).execute((GridClosure<Entry<String, String>, String>) (it) ->
//				it.getValue().equalsIgnoreCase(upLabel) ? it.getKey() : null);
			log.info("Finding resource for label '{}'...", upLabel);
			Collection<Set<String>> founds = labelCache.queries().createScanQuery(null).execute(new GridReducer<Entry<String, String>, Set<String>>() {
				Set<String> ids = new HashSet<>();
				
				@Override
				public boolean collect(Entry<String, String> e) {
					if (e.getValue().equalsIgnoreCase(upLabel)) {
						ids.add( e.getKey() );
					}
					return true;
				}
				
				@Override
				public Set<String> reduce() {
					return ids;
				}
			}).get();
			
			log.info("Found for {}: {}", upLabel, founds);
		}
		
	}
 
開發者ID:lumenrobot,項目名稱:lumen-kb,代碼行數:30,代碼來源:YagoLabelLookupCli2.java

示例8: main

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public static void main(String[] args) throws FileNotFoundException, IOException, GridException {
		String upLabel = "Muhammad";
		
		try (AnnotationConfigApplicationContext appCtx = new AnnotationConfigApplicationContext(LumenConfig.class)) {
			Grid grid = appCtx.getBean(Grid.class);
			GridCache<String, ListMultimap<String, String>> entityByLabelCache = YagoLabel.entityByLabelCache(grid);
//			labelCache.queries().createScanQuery(null).execute((GridClosure<Entry<String, String>, String>) (it) ->
//				it.getValue().equalsIgnoreCase(upLabel) ? it.getKey() : null);
			log.info("Finding resource for label '{}'...", upLabel);
//			entityByLabelCache.removex(upLabel);
			ListMultimap<String, String> entities = entityByLabelCache.get(upLabel);
			log.info("Found for {}: {}", upLabel, entities);
		}
		
	}
 
開發者ID:lumenrobot,項目名稱:lumen-kb,代碼行數:16,代碼來源:YagoLabelLookupCli3.java

示例9: main

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public static void main(String[] args) throws FileNotFoundException, IOException, GridException {
		String upLabel = "Muhammad";
		
		try (Grid grid = GridGain.start(YagoLabelLookupCli.class.getResource("yago.gridgain.xml"))) {
			GridCache<String, String> labelCache = grid.cache("yagoLabel");
//			labelCache.queries().createScanQuery(null).execute((GridClosure<Entry<String, String>, String>) (it) ->
//				it.getValue().equalsIgnoreCase(upLabel) ? it.getKey() : null);
			log.info("Finding resource for label '{}'...", upLabel);
			Collection<String> founds = labelCache.queries().createScanQuery(null).execute(new GridReducer<Entry<String, String>, String>() {
				String id;
				
				@Override
				public boolean collect(Entry<String, String> e) {
					if (e.getValue().equalsIgnoreCase(upLabel)) {
						id = e.getKey();
						return false;
					} else {
						return true;
					}
				}
				
				@Override
				public String reduce() {
					return id;
				}
			}).get();
			
			log.info("Found for {}: {}", upLabel, founds);
		}
		
	}
 
開發者ID:lumenrobot,項目名稱:lumen-kb,代碼行數:32,代碼來源:YagoLabelLookupCli.java

示例10: ConnectedGridGainStateCache

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public ConnectedGridGainStateCache(GridCache<K, V> gridMap) {
    setMap(gridMap);
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:4,代碼來源:ConnectedGridGainStateCache.java

示例11: setMap

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public void setMap(GridCache<K, V> gridMap) {
    _gridMap = gridMap;
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:4,代碼來源:ConnectedGridGainStateCache.java

示例12: gridGainStateTest

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
@Test
public void gridGainStateTest() throws GridException {
    List<String> topics = new ArrayList<String>();
    topics.add("location");

    GridConfiguration ggConf = new GridConfiguration();
    GridCacheConfiguration cacheLocation = new GridCacheConfiguration();
    cacheLocation.setName("location");
    cacheLocation.setCacheMode(GridCacheMode.PARTITIONED);
    ggConf.setCacheConfiguration(cacheLocation);
    Grid grid = GridGain.start(ggConf);

    GridCache<String, Map<String, Object>> map = grid.cache("location");

    GridGainStormState state = new GridGainStormState("location");

    List<List<Object>> keysList = new ArrayList<>();

    List<Object> keys = new ArrayList<>();
    keys.add("A");
    keysList.add(keys);

    keys = new ArrayList<>();
    keys.add("B");
    keysList.add(keys);

    keys = new ArrayList<>();
    keys.add("C");
    keysList.add(keys);

    List<Map<String, Map<String, Object>>> valuesList = new ArrayList<>();
    Map<String, Map<String, Object>> values = new HashMap<>();

    Map<String, Object> value = new HashMap<>();

    value.put("A1", 1);
    values.put("A", value);

    value = new HashMap<>();
    value.put("B1", 2);
    values.put("B", value);

    value = new HashMap<>();
    value.put("C1", 3);
    values.put("C", value);

    valuesList.add(values);


    state.multiPut(keysList, valuesList);


    List<Map<String, Map<String, Object>>> restoreList = state.multiGet(keysList);
    Map<String, Map<String, Object>> restore = restoreList.get(0);

    Assert.assertEquals(values.get("A"), restore.get("A"));
    Assert.assertEquals(values.get("A").get("A1"), restore.get("A").get("A1"));
    Assert.assertEquals(values.get("B"), restore.get("B"));
    Assert.assertEquals(values.get("B").get("B1"), restore.get("B").get("B1"));
    Assert.assertEquals(values.get("C"), restore.get("C"));
    Assert.assertEquals(values.get("C").get("C1"), restore.get("C").get("C1"));
    Assert.assertNotEquals(values.get("C").get("C1"), restore.get("B").get("B1"));

    grid.close();
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:66,代碼來源:GridGainStateTest.java

示例13: cache

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public static GridCache<String, YagoLabel> cache(Grid grid) {
	return grid.cache("yagoLabel");
}
 
開發者ID:lumenrobot,項目名稱:lumen-kb,代碼行數:4,代碼來源:YagoLabel.java

示例14: entityByLabelCache

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public static GridCache<String, ListMultimap<String, String>> entityByLabelCache(
		Grid grid) {
	return grid.cache("yagoEntityByLabel");
}
 
開發者ID:lumenrobot,項目名稱:lumen-kb,代碼行數:5,代碼來源:YagoLabel.java

示例15: cache

import org.gridgain.grid.cache.GridCache; //導入依賴的package包/類
public static GridCache<String, YagoRule> cache(Grid grid) {
	return grid.cache("yagoRule");
}
 
開發者ID:lumenrobot,項目名稱:lumen-kb,代碼行數:4,代碼來源:YagoRule.java


注:本文中的org.gridgain.grid.cache.GridCache類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。