@Override public void execute(FunctionContext context) { StringBuilder str1 = new StringBuilder(); Map<String, String> resultMap = null; try { Cache cache = CacheFactory.getAnyInstance(); DistributedMember member = cache.getDistributedSystem().getDistributedMember(); long freeMemoeryBeforeGC = Runtime.getRuntime().freeMemory(); long totalMemoryBeforeGC = Runtime.getRuntime().totalMemory(); long timeBeforeGC = System.currentTimeMillis(); Runtime.getRuntime().gc(); long freeMemoeryAfterGC = Runtime.getRuntime().freeMemory(); long totalMemoryAfterGC = Runtime.getRuntime().totalMemory(); long timeAfterGC = System.currentTimeMillis(); long megaBytes = 131072; resultMap = new HashMap<String, String>(); resultMap.put("MemberId", member.getId()); resultMap.put( "HeapSizeBeforeGC", String.valueOf((totalMemoryBeforeGC - freeMemoeryBeforeGC) / megaBytes)); resultMap.put( "HeapSizeAfterGC", String.valueOf((totalMemoryAfterGC - freeMemoeryAfterGC) / megaBytes)); resultMap.put("TimeSpentInGC", String.valueOf(timeAfterGC - timeBeforeGC)); } catch (Exception ex) { str1.append( "Exception in GC:" + ex.getMessage() + CliUtil.stackTraceAsString((Throwable) ex)); context.getResultSender().lastResult(str1.toString()); } context.getResultSender().lastResult(resultMap); }
@Override public void execute(FunctionContext context) { try { Region<K, V> local = PartitionRegionHelper.getLocalDataForContext((RegionFunctionContext) context); ParallelArgs<K, V> args = (ParallelArgs<K, V>) context.getArguments(); File[] files = args.getOptions() .getMapper() .mapImportPath( local.getCache().getDistributedSystem().getDistributedMember(), args.getFile()); if (files != null) { for (File f : files) { if (f.isDirectory() || !f.exists()) { throw new IOException( LocalizedStrings.Snapshot_INVALID_IMPORT_FILE.toLocalizedString(f)); } local.getSnapshotService().load(f, args.getFormat(), args.getOptions()); } } context.getResultSender().lastResult(Boolean.TRUE); } catch (Exception e) { context.getResultSender().sendException(e); } }
@Override public void execute(FunctionContext context) { InternalLocator locator = InternalLocator.getLocator(); GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); DistributedMember member = cache.getDistributedSystem().getDistributedMember(); SharedConfigurationStatus status = locator.getSharedConfigurationStatus().getStatus(); String memberId = member.getName(); if (StringUtils.isBlank(memberId)) { memberId = member.getId(); } CliFunctionResult result = new CliFunctionResult(memberId, new String[] {status.name()}); context.getResultSender().lastResult(result); }
@Override public void execute(FunctionContext context) { final IndexInfo indexInfo = (IndexInfo) context.getArguments(); String memberId = null; try { Cache cache = CacheFactory.getAnyInstance(); memberId = cache.getDistributedSystem().getDistributedMember().getId(); QueryService queryService = cache.getQueryService(); String indexName = indexInfo.getIndexName(); String indexedExpression = indexInfo.getIndexedExpression(); String regionPath = indexInfo.getRegionPath(); switch (indexInfo.getIndexType()) { case IndexInfo.RANGE_INDEX: queryService.createIndex(indexName, indexedExpression, regionPath); break; case IndexInfo.KEY_INDEX: queryService.createKeyIndex(indexName, indexedExpression, regionPath); break; case IndexInfo.HASH_INDEX: queryService.createHashIndex(indexName, indexedExpression, regionPath); break; default: queryService.createIndex(indexName, indexedExpression, regionPath); } XmlEntity xmlEntity = new XmlEntity(CacheXml.REGION, "name", cache.getRegion(regionPath).getName()); context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity)); } catch (IndexExistsException e) { String message = CliStrings.format(CliStrings.CREATE_INDEX__INDEX__EXISTS, indexInfo.getIndexName()); context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message)); } catch (IndexNameConflictException e) { String message = CliStrings.format(CliStrings.CREATE_INDEX__NAME__CONFLICT, indexInfo.getIndexName()); context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message)); } catch (RegionNotFoundException e) { String message = CliStrings.format( CliStrings.CREATE_INDEX__INVALID__REGIONPATH, indexInfo.getRegionPath()); context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message)); } catch (IndexInvalidException e) { context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage())); } catch (Exception e) { String exceptionMessage = CliStrings.format( CliStrings.EXCEPTION_CLASS_AND_MESSAGE, e.getClass().getName(), e.getMessage()); context.getResultSender().lastResult(new CliFunctionResult(memberId, e, exceptionMessage)); } }
/* (non-Javadoc) * @see com.gemstone.gemfire.cache.execute.FunctionAdapter#execute(com.gemstone.gemfire.cache.execute.FunctionContext) */ @Override public void execute(FunctionContext context) { // retrieve and log function arguments List arguments = (ArrayList) (context.getArguments()); Object initiatingThreadID = arguments.get(0); String task = (String) arguments.get(1); Log.getLogWriter() .info( "In execute with context " + context + " initiated in hydra thread thr_" + initiatingThreadID + "_; fcn task is " + task); if (task.equals(VERIFY_CLASS_AVAILABILITY)) { List<String> expectAvailable = (List) arguments.get(2); List<String> expectUnavailable = (List) arguments.get(3); Log.getLogWriter().info("Expect available: " + Arrays.asList(expectAvailable)); Log.getLogWriter().info("Expect unavailable: " + Arrays.asList(expectUnavailable)); // Test that the classes we expect to see are available Set<Region<?, ?>> allRegions = getAllRegions(); RandomValues rv = new RandomValues(); for (String className : expectAvailable) { Log.getLogWriter() .info("Attempting to create instance of " + className + "; expect this to succeed"); String key = NameFactory.getNextPositiveObjectName(); Object newObj = null; try { newObj = createValueHolderInstance(className, key, rv); } catch (ClassNotFoundException e) { throw new TestException("Got unexpected " + TestHelper.getStackTrace(e)); } String newObjStr = TestHelper.toString(newObj); Log.getLogWriter().info("Successfully created " + newObjStr); for (Region aRegion : allRegions) { Log.getLogWriter() .info("Putting " + key + ", " + newObjStr + " into " + aRegion.getFullPath()); aRegion.put(key, newObj); } } // Test that the classes we expect to not see are unavailable String key = NameFactory.getNextPositiveObjectName(); for (String className : expectUnavailable) { Log.getLogWriter() .info("Attempting to create instance of " + className + "; expect this to fail"); try { Object newObj = createValueHolderInstance(className, key, rv); throw new TestException( "Expected to not find " + className + " but was able to create " + TestHelper.toString(newObj)); } catch (ClassNotFoundException e) { Log.getLogWriter().info("Test got expected exception for " + className + ": " + e); } } context .getResultSender() .lastResult("Validation was successful for vm_" + RemoteTestModule.getMyVmid()); } else { throw new TestException("Unknown task specified for function: " + task); } }
public void execute(FunctionContext functionContext) { logger.debug("Starting expiration"); long destroyedEntriesCount = 0; ResultSender<Serializable> resultSender = functionContext.getResultSender(); try { if (functionContext instanceof RegionFunctionContext) { RegionFunctionContext context = (RegionFunctionContext) functionContext; Serializable arguments = context.getArguments(); if (arguments instanceof ExpirationFunctionArguments) { ExpirationFunctionArguments expirationFunctionArguments = (ExpirationFunctionArguments) arguments; long packetDelay = expirationFunctionArguments.getPacketDelay(); long packetSize = expirationFunctionArguments.getPacketSize(); logger.debug( "Expiration configured with packetSize = " + packetSize + ", packetDelay = " + packetDelay); Region<Object, Object> region = PartitionRegionHelper.getLocalDataForContext(context); Set<Entry<Object, Object>> entrySet = region.entrySet(); int numberOfEntries = entrySet.size(); logger.debug("There are " + numberOfEntries + " entries to check"); logger.debug("Starting the check"); long packetCounter = 1; for (Entry<Object, Object> entry : entrySet) { if ((packetDelay > 0) && ((packetCounter % packetSize) == 0)) { logger.debug("Checking the " + packetCounter + " of " + numberOfEntries + " entry."); Thread.sleep(packetDelay); } if (entry instanceof Region.Entry) { Region.Entry<Object, Object> regionEntry = (Region.Entry<Object, Object>) entry; if ((policy != null) && policy.isExpired(regionEntry)) { Object key = entry.getKey(); logger.trace("Destroing the entry with key " + key); region.destroy(key); destroyedEntriesCount++; } } packetCounter++; } logger.debug( "The check is finished. " + destroyedEntriesCount + " entries have been destroyed."); } else { throw new IllegalArgumentException( "The specified arguments are of type \"" + arguments.getClass().getName() + "\". Should be of type \"" + ExpirationFunctionArguments.class.getName() + "\""); } } } catch (Throwable t) { logger.error("Throwable during the expiration processing", t); resultSender.sendException(t); } resultSender.lastResult(destroyedEntriesCount); }
public void execute(FunctionContext fc) { BigInteger two = new BigInteger("2"); long l = two.pow(53).longValue(); fc.getResultSender().lastResult(l); }