List of usage examples for org.springframework.data.gemfire GemfireTemplate getRegion
@SuppressWarnings("unchecked") public <K, V> Region<K, V> getRegion()
From source file:demo.vmware.commands.CommandRegionUtils.java
/** * this is an argument for making this a singleton bean instead of static. We cold then make this * ApplicationContextAware// w ww . j a va 2s . c o m * * @param mainContext * @param targetRegionName * @return */ public static GemfireTemplate findTemplateForRegionName(ApplicationContext mainContext, String targetRegionName) { Map<String, GemfireTemplate> allRegionTemplates = getAllGemfireTemplates(mainContext); for (String key : allRegionTemplates.keySet()) { GemfireTemplate oneTemplate = allRegionTemplates.get(key); if (oneTemplate.getRegion().getName().equals(targetRegionName)) { return oneTemplate; } } throw new IllegalArgumentException("region not found " + targetRegionName); }
From source file:demo.vmware.commands.CommandGetOneObject.java
@Override public CommandResult run(ConfigurableApplicationContext mainContext, List<String> parameters) { List<String> messages = new ArrayList<String>(); String targetRegionName = parameters.get(0); String targetKey = parameters.get(1); Map<String, GemfireTemplate> allRegionTemplates = CommandRegionUtils.getAllGemfireTemplates(mainContext); for (String key : allRegionTemplates.keySet()) { GemfireTemplate oneTemplate = allRegionTemplates.get(key); if (oneTemplate.getRegion().getName().equals(targetRegionName)) { Date startTimer = new Date(); Object foundObject = oneTemplate.get(targetKey); Date endTimer = new Date(); long timeDiffInMsec = endTimer.getTime() - startTimer.getTime(); double timeDiff = timeDiffInMsec / 1000.0; messages.add("Region " + targetRegionName + ": get key=" + targetKey + " contains " + foundObject + " took " + timeDiff + " secs"); }/*ww w . j ava 2 s. c o m*/ } if (messages.size() == 0) { messages.add("No data found."); } return new CommandResult(null, messages); }
From source file:demo.vmware.commands.CommandPurgeAllRegions.java
@Override public CommandResult run(ConfigurableApplicationContext mainContext, List<String> parameters) { List<String> messages = new ArrayList<String>(); Map<String, GemfireTemplate> allRegionTemplates = CommandRegionUtils.getAllGemfireTemplates(mainContext); for (String key : allRegionTemplates.keySet()) { GemfireTemplate oneTemplate = allRegionTemplates.get(key); // this throws unsupported operation error // oneTemplate.getRegion().clear(); removeAllFromRegion(oneTemplate.getRegion()); messages.add("Region: " + oneTemplate.getRegion().getName() + " contains " + oneTemplate.getRegion().size() + " elements"); }/*from w w w. j av a2s .c om*/ return new CommandResult(null, messages); }
From source file:demo.vmware.commands.CommandGetAllRegions.java
/** * Retrieve the contents for all regions, one region per task executor *//*from www . j a va 2 s. c o m*/ @Override public CommandResult run(ConfigurableApplicationContext mainContext, List<String> parameters) { // Use the template for this meaning we can only fetch the whole contents of any region we have a template for // CommandGetCounts goes right to the cache so it may list more regions Map<String, GemfireTemplate> allRegionTemplates = CommandRegionUtils.getAllGemfireTemplates(mainContext); // use the Java executor service because of it's awesome invokeAll method. ExecutorService taskExecutor = Executors.newFixedThreadPool(allRegionTemplates.size()); Collection tasks = new ArrayList<RegionFetcher>(); CommandTimer timer = new CommandTimer(); for (String key : allRegionTemplates.keySet()) { GemfireTemplate oneTemplate = allRegionTemplates.get(key); if (parallelFetch) { tasks.add(new RegionFetcher(oneTemplate.getRegion().getName(), 0, oneTemplate)); } else { // don't write anything out and don't capture results fetchOneRegion(oneTemplate.getRegion().getName(), 5, oneTemplate); } } if (parallelFetch) { // invokeAll() returns when all tasks are complete try { List<Future<?>> futures = taskExecutor.invokeAll(tasks); taskExecutor.shutdown(); LOG.info("Fetched " + futures.size() + " regions in threads"); // the futures hold the results at this point futures.get(X).get(); } catch (InterruptedException e) { e.printStackTrace(); } } timer.stop(); return new CommandResult(null, "Loading all regions took " + timer.getTimeDiffInSeconds() + " seconds"); }
From source file:org.springframework.data.gemfire.support.JSONRegionAdvice.java
@Around("execution(* org.springframework.data.gemfire.GemfireOperations.find(..)) " + "|| execution(* org.springframework.data.gemfire.GemfireOperations.findUnique(..)) " + "|| execution(* org.springframework.data.gemfire.GemfireOperations.query(..))") public Object templateQuery(ProceedingJoinPoint pjp) { GemfireTemplate template = (GemfireTemplate) pjp.getTarget(); boolean jsonRegion = isIncludedSONRegion(template.getRegion()); Object returnValue = null;/*from w ww . j a v a 2s . c om*/ try { if (jsonRegion) { returnValue = pjp.proceed(); if (returnValue instanceof SelectResults && convertReturnedCollections) { ResultsBag resultsBag = new ResultsBag(); for (Object obj : (SelectResults<?>) returnValue) { resultsBag.add(convertPdxInstanceToJSONString(obj)); } returnValue = resultsBag; } else { returnValue = convertPdxInstanceToJSONString(returnValue); } } else { returnValue = pjp.proceed(); } } catch (Throwable t) { handleThrowable(t); } return returnValue; }
From source file:org.springframework.data.gemfire.serialization.json.JSONRegionAdvice.java
@Around("execution(* org.springframework.data.gemfire.GemfireOperations.find(..)) " + "|| execution(* org.springframework.data.gemfire.GemfireOperations.findUnique(..)) " + "|| execution(* org.springframework.data.gemfire.GemfireOperations.query(..))") public Object templateQuery(ProceedingJoinPoint pjp) { GemfireTemplate template = (GemfireTemplate) pjp.getTarget(); boolean jsonRegion = isIncludedJsonRegion(template.getRegion()); Object returnValue = null;/*from w ww . j a v a 2s .c o m*/ try { if (jsonRegion) { returnValue = pjp.proceed(); if (returnValue instanceof SelectResults && this.convertReturnedCollections) { ResultsBag resultsBag = new ResultsBag(); for (Object obj : (SelectResults<?>) returnValue) { resultsBag.add(convertToJson(obj)); } returnValue = resultsBag; } else { returnValue = convertToJson(returnValue); } } else { returnValue = pjp.proceed(); } } catch (Throwable cause) { handleThrowable(cause); } return returnValue; }