org.apache.geode.cache.execute.Execution.execute()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(12.7k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中org.apache.geode.cache.execute.Execution.execute()方法的一些代码示例,展示了Execution.execute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Execution.execute()方法的具体详情如下:
包路径:org.apache.geode.cache.execute.Execution
类名称:Execution
方法名:execute

Execution.execute介绍

[英]Executes the function using its Function#getId()

Function#execute(FunctionContext) is called on the instance retrieved using FunctionService#getFunction(String) on the executing member.
[中]使用函数#getId()执行函数
函数#execute(FunctionContext)在执行成员上使用FunctionService#getFunction(String)检索的实例上调用。

代码示例

代码示例来源:origin: apache/geode

@Override
public int size() {
 // Add a single dummy key to force the function to go to one server
 Set<String> filters = new HashSet<String>();
 filters.add("test-key");
 // Execute the function on the session region
 Execution execution = FunctionService.onRegion(getSessionRegion()).withFilter(filters);
 ResultCollector collector = execution.execute(RegionSizeFunction.ID);
 List<Integer> result = (List<Integer>) collector.getResult();
 // Return the first (and only) element
 return result.get(0);
}

代码示例来源:origin: apache/geode

private void createSessionRegionOnServers() {
 // Create the RegionConfiguration
 RegionConfiguration configuration = createRegionConfiguration();
 // Send it to the server tier
 Execution execution = FunctionService.onServer(this.cache).setArguments(configuration);
 ResultCollector collector = execution.execute(CreateRegionFunction.ID);
 // Verify the region was successfully created on the servers
 List<RegionStatus> results = (List<RegionStatus>) collector.getResult();
 for (RegionStatus status : results) {
  if (status == RegionStatus.INVALID) {
   StringBuilder builder = new StringBuilder();
   builder.append(
     "An exception occurred on the server while attempting to create or validate region named ");
   builder.append(properties.get(CacheProperty.REGION_NAME));
   builder.append(". See the server log for additional details.");
   throw new IllegalStateException(builder.toString());
  }
 }
}

代码示例来源:origin: apache/geode

private void snapshotInParallel(ParallelArgs<K, V> args, Function fn) throws IOException {
 try {
  ResultCollector rc = FunctionService.onRegion(region).setArguments(args).execute(fn);
  List result = (List) rc.getResult();
  for (Object obj : result) {
   if (obj instanceof Exception) {
    throw new IOException((Exception) obj);
   }
  }
  return;
 } catch (FunctionException e) {
  throw new IOException(e);
 }
}

代码示例来源:origin: apache/geode

@SuppressWarnings("unchecked")
protected List<LuceneIndexDetails> getIndexListing() {
 final Execution functionExecutor = getMembersFunctionExecutor(getAllMembers());
 if (functionExecutor instanceof AbstractExecution) {
  ((AbstractExecution) functionExecutor).setIgnoreDepartedMembers(true);
 }
 final ResultCollector resultsCollector =
   functionExecutor.execute(new LuceneListIndexFunction());
 final List<Set<LuceneIndexDetails>> results =
   (List<Set<LuceneIndexDetails>>) resultsCollector.getResult();
 List<LuceneIndexDetails> sortedResults =
   results.stream().flatMap(Collection::stream).sorted().collect(Collectors.toList());
 LinkedHashSet<LuceneIndexDetails> uniqResults = new LinkedHashSet<>();
 uniqResults.addAll(sortedResults);
 sortedResults.clear();
 sortedResults.addAll(uniqResults);
 return sortedResults;
}

代码示例来源:origin: apache/geode

private List<Object> executeFunction(Execution execution, String functionID, Function function,
  Object arguments) {
 if (arguments != null) {
  execution = execution.setArguments(arguments);
 }
 ResultCollector<Object, List<Object>> collector = execution.execute(functionID);
 if (function.hasResult()) {
  return collector.getResult();
 } else {
  return Collections.emptyList();
 }
}

代码示例来源:origin: apache/geode

private void bootstrapServers() {
 Execution execution = FunctionService.onServers(this.cache);
 ResultCollector collector = execution.execute(new BootstrappingFunction());
 // Get the result. Nothing is being done with it.
 try {
  collector.getResult();
 } catch (Exception e) {
  // If an exception occurs in the function, log it.
  LOG.warn("Caught unexpected exception:", e);
 }
}

代码示例来源:origin: apache/geode

@SuppressWarnings("unchecked")
List<DiskStoreDetails> getDiskStoreListing(Set<DistributedMember> members) {
 final Execution membersFunctionExecutor = getMembersFunctionExecutor(members);
 if (membersFunctionExecutor instanceof AbstractExecution) {
  ((AbstractExecution) membersFunctionExecutor).setIgnoreDepartedMembers(true);
 }
 final ResultCollector<?, ?> resultCollector =
   membersFunctionExecutor.execute(new ListDiskStoresFunction());
 final List<?> results = (List<?>) resultCollector.getResult();
 final List<DiskStoreDetails> distributedSystemMemberDiskStores =
   new ArrayList<>(results.size());
 for (final Object result : results) {
  if (result instanceof Set) {
   distributedSystemMemberDiskStores.addAll((Set<DiskStoreDetails>) result);
  }
 }
 Collections.sort(distributedSystemMemberDiskStores);
 return distributedSystemMemberDiskStores;
}

代码示例来源:origin: apache/geode

private List<?> getMissingDiskStoresList(Set<DistributedMember> members) {
 final Execution membersFunctionExecutor = getMembersFunctionExecutor(members);
 if (membersFunctionExecutor instanceof AbstractExecution) {
  ((AbstractExecution) membersFunctionExecutor).setIgnoreDepartedMembers(true);
 }
 final ResultCollector<?, ?> resultCollector =
   membersFunctionExecutor.execute(new ShowMissingDiskStoresFunction());
 final List<?> results = (List<?>) resultCollector.getResult();
 final List<?> distributedPersistentRecoveryDetails = new ArrayList<>(results.size());
 for (final Object result : results) {
  if (result instanceof Set) {
   distributedPersistentRecoveryDetails.addAll((Set) result);
  }
 }
 return distributedPersistentRecoveryDetails;
}

代码示例来源:origin: apache/geode

List<IndexDetails> getIndexListing() {
 final Execution functionExecutor = getMembersFunctionExecutor(getAllMembers());
 if (functionExecutor instanceof AbstractExecution) {
  ((AbstractExecution) functionExecutor).setIgnoreDepartedMembers(true);
 }
 final ResultCollector<?, ?> resultsCollector =
   functionExecutor.execute(new ListIndexFunction());
 final List<?> results = (List<?>) resultsCollector.getResult();
 final List<IndexDetails> indexDetailsList = new ArrayList<>(results.size());
 for (Object result : results) {
  if (result instanceof Set) { // ignore FunctionInvocationTargetExceptions and other Exceptions
   indexDetailsList.addAll((Set<IndexDetails>) result);
  }
 }
 Collections.sort(indexDetailsList);
 return indexDetailsList;
}

代码示例来源:origin: apache/geode

private void createSessionRegionOnServers() {
 // Create the RegionConfiguration
 RegionConfiguration configuration = createRegionConfiguration();
 // Send it to the server tier
 Execution execution = FunctionService.onServer(this.cache).setArguments(configuration);
 ResultCollector collector = execution.execute(CreateRegionFunction.ID);
 // Verify the region was successfully created on the servers
 List<RegionStatus> results = (List<RegionStatus>) collector.getResult();
 for (RegionStatus status : results) {
  if (status == RegionStatus.INVALID) {
   StringBuilder builder = new StringBuilder();
   builder
     .append(
       "An exception occurred on the server while attempting to create or validate region named ")
     .append(getSessionManager().getRegionName())
     .append(". See the server log for additional details.");
   throw new IllegalStateException(builder.toString());
  }
 }
}

代码示例来源:origin: apache/geode

@Override
public void dumpFiles(final String directory) {
 ResultCollector results = FunctionService.onRegion(getDataRegion())
   .setArguments(new String[] {directory, indexName}).execute(DumpDirectoryFiles.ID);
 results.getResult();
}

代码示例来源:origin: apache/geode

private static void lockRemoteVM(MemberVM vmToLock) {
 InternalDistributedMember thatInternalMember = getInternalDistributedMember(vmToLock);
 ResultCollector collector =
   FunctionService.onMember(thatInternalMember).execute(new LockFunction());
 collector.getResult();
}

代码示例来源:origin: apache/geode

DiskStoreDetails getDiskStoreDescription(final String memberName, final String diskStoreName) {
 final DistributedMember member = getMember(memberName);
 final ResultCollector<?, ?> resultCollector =
   getMembersFunctionExecutor(Collections.singleton(member)).setArguments(diskStoreName)
     .execute(new DescribeDiskStoreFunction());
 final Object result = ((List<?>) resultCollector.getResult()).get(0);
 if (result instanceof DiskStoreDetails) { // disk store details in hand...
  return (DiskStoreDetails) result;
 } else if (result instanceof EntityNotFoundException) { // bad disk store name...
  throw (EntityNotFoundException) result;
 } else { // unknown and unexpected return type...
  final Throwable cause = (result instanceof Throwable ? (Throwable) result : null);
  throw new RuntimeException(
    CliStrings.format(CliStrings.UNEXPECTED_RETURN_TYPE_EXECUTING_COMMAND_ERROR_MESSAGE,
      ClassUtils.getClassName(result), CliStrings.DESCRIBE_DISK_STORE),
    cause);
 }
}

代码示例来源:origin: apache/geode

@Override
public boolean waitUntilFlushed(String indexName, String regionPath, long timeout, TimeUnit unit)
  throws InterruptedException {
 Region dataRegion = this.cache.getRegion(regionPath);
 if (dataRegion == null) {
  logger.info("Data region " + regionPath + " not found");
  return false;
 }
 WaitUntilFlushedFunctionContext context =
   new WaitUntilFlushedFunctionContext(indexName, timeout, unit);
 Execution execution = FunctionService.onRegion(dataRegion);
 ResultCollector rs = execution.setArguments(context).execute(WaitUntilFlushedFunction.ID);
 List<Boolean> results = (List<Boolean>) rs.getResult();
 for (Boolean oneResult : results) {
  if (oneResult == false) {
   return false;
  }
 }
 return true;
}

代码示例来源:origin: apache/geode

protected Map<K, V> getValues(final Set<K> keys) {
 ResultCollector resultCollector = onRegion().withFilter(keys)
   .withCollector(new MapResultCollector()).execute(LuceneGetPageFunction.ID);
 return (Map<K, V>) resultCollector.getResult();
}

代码示例来源:origin: apache/geode

/***
 * Executes a function with arguments on a set of members, ignoring the departed members.
 *
 * @param function Function to be executed.
 * @param args Arguments passed to the function, pass null if you wish to pass no arguments to the
 *        function.
 * @param targetMembers Set of members on which the function is to be executed.
 *
 */
public static ResultCollector<?, ?> executeFunction(final Function function, Object args,
  final Set<DistributedMember> targetMembers) {
 Execution execution;
 if (args != null) {
  execution = FunctionService.onMembers(targetMembers).setArguments(args);
 } else {
  execution = FunctionService.onMembers(targetMembers);
 }
 ((AbstractExecution) execution).setIgnoreDepartedMembers(true);
 return execution.execute(function);
}

代码示例来源:origin: apache/geode

private void bootstrapMember(InternalDistributedMember member) {
 // Create and execute the function
 Cache cache = CacheFactory.getAnyInstance();
 Execution execution = FunctionService.onMember(member);
 ResultCollector collector = execution.execute(this);
 // Get the result. Nothing is being done with it.
 try {
  collector.getResult();
 } catch (Exception e) {
  // If an exception occurs in the function, log it.
  cache.getLogger().warning("Caught unexpected exception:", e);
 }
}

代码示例来源:origin: apache/geode

private void bootstrapServers() {
 Execution execution = FunctionService.onServers(this.cache);
 ResultCollector collector = execution.execute(new BootstrappingFunction());
 // Get the result. Nothing is being done with it.
 try {
  collector.getResult();
 } catch (Exception e) {
  // If an exception occurs in the function, log it.
  getSessionManager().getLogger().warn("Caught unexpected exception:", e);
 }
}

代码示例来源:origin: apache/geode

@Override
public long export(Region<K, V> region, ExportSink sink, SnapshotOptions<K, V> options)
  throws IOException {
 try {
  ClientArgs<K, V> args =
    new ClientArgs<K, V>(region.getFullPath(), pool.getPRSingleHopEnabled(), options);
  ClientExportCollector results = new ClientExportCollector(sink);
  // For single hop we rely on tcp queuing to throttle the export; otherwise
  // we allow the WindowedExporter to provide back pressure.
  Execution exec = pool.getPRSingleHopEnabled() ? FunctionService.onRegion(region)
    : FunctionService.onServer(pool);
  ResultCollector<?, ?> rc =
    exec.setArguments(args).withCollector(results).execute(new ProxyExportFunction<K, V>());
  // Our custom result collector is writing the data, but this will
  // check for errors.
  return (Long) rc.getResult();
 } catch (FunctionException e) {
  throw new IOException(e);
 }
}

代码示例来源:origin: apache/geode

@Test
public void shouldInvokeLuceneFunctionWithCorrectArguments() throws Exception {
 addValueToResults();
 PageableLuceneQueryResults<Object, Object> results = query.findPages();
 verify(execution).execute(eq(LuceneQueryFunction.ID));
 ArgumentCaptor<LuceneFunctionContext> captor =
   ArgumentCaptor.forClass(LuceneFunctionContext.class);
 verify(execution).setArguments(captor.capture());
 LuceneFunctionContext context = captor.getValue();
 assertEquals(LIMIT, context.getLimit());
 assertEquals(provider, context.getQueryProvider());
 assertEquals("index", context.getIndexName());
 assertEquals(5, results.getMaxScore(), 0.01);
 assertEquals(1, results.size());
 final List<LuceneResultStruct<Object, Object>> page = results.next();
 assertEquals(1, page.size());
 LuceneResultStruct element = page.iterator().next();
 assertEquals("hi", element.getKey());
 assertEquals("value", element.getValue());
 assertEquals(5, element.getScore(), 0.01);
}

相关文章