本文整理了Java中org.apache.geode.cache.execute.Execution
类的一些代码示例,展示了Execution
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Execution
类的具体详情如下:
包路径:org.apache.geode.cache.execute.Execution
类名称:Execution
[英]Provides methods to build the context for the execution of a Function . A Context describes the environment in which the Execution will take place.
This interface is implemented by GemFire. To obtain an instance of it use FunctionService.
[中]提供用于构建函数执行上下文的方法。上下文描述执行将在其中进行的环境。
该接口由GemFire实现。要获取它的实例,请使用FunctionService。
代码示例来源: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
@Override
public void touchSessions(Set<String> sessionIds) {
// Get the region attributes id to determine the region type. This is
// problematic since the region attributes id doesn't really define the
// region type. This should look at the actual session region.
String regionAttributesID = getSessionManager().getRegionAttributesId().toLowerCase();
// Invoke the appropriate function depending on the type of region
ResultCollector collector = null;
if (regionAttributesID.startsWith("partition")) {
// Execute the partitioned touch function on the primary server(s)
Execution execution = FunctionService.onRegion(getSessionRegion()).withFilter(sessionIds);
collector = execution.execute(TouchPartitionedRegionEntriesFunction.ID);
} else {
// Execute the member touch function on all the server(s)
Execution execution = FunctionService.onMembers()
.setArguments(new Object[] {this.sessionRegion.getFullPath(), sessionIds});
collector = execution.execute(TouchReplicatedRegionEntriesFunction.ID);
}
// Get the result
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
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
@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
when(context.getResultSender()).thenReturn(resultSender);
when(execution.withFilter(any())).thenReturn(execution);
when(execution.setArguments(any())).thenReturn(execution);
when(execution.withCollector(any())).thenReturn(execution);
when(execution.execute(anyString())).thenReturn(resultCollector);
代码示例来源: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
@Test
@SuppressWarnings("unchecked")
public void executeShouldProperlyConfigureExecutionContext() {
Set<String> filter = new HashSet<>();
filter.add("key1");
filter.add("key2");
arguments = new Object[] {"TestFunction", "key1,key2", "TestResultCollector", "arg1,arg2",
"/TestRegion", new Properties()};
when(context.getArguments()).thenReturn(arguments);
function.execute(context);
verify(execution, times(1)).withFilter(filter);
verify(execution, times(1)).withCollector(resultCollector);
verify(execution, times(1)).setArguments(new String[] {"arg1", "arg2"});
verify(resultSender, times(1)).lastResult(resultCaptor.capture());
CliFunctionResult resultFullArguments = resultCaptor.getValue();
assertThat(resultFullArguments.isSuccessful()).isTrue();
reset(resultSender);
reset(execution);
arguments = new Object[] {"TestFunction", "", "", "", "", new Properties()};
when(context.getArguments()).thenReturn(arguments);
function.execute(context);
verify(execution, never()).withFilter(any());
verify(execution, never()).setArguments(any());
verify(execution, never()).withCollector(any());
verify(resultSender, times(1)).lastResult(resultCaptor.capture());
CliFunctionResult resultNoArguments = resultCaptor.getValue();
assertThat(resultNoArguments.isSuccessful()).isTrue();
}
代码示例来源:origin: apache/geode
execution = FunctionService.onMembers(targetMembers).withCollector(collector);
} else {
execution = FunctionService.onMembers().withCollector(collector);
collector = execution.execute(new CollectDependencyFunction());
代码示例来源:origin: apache/geode
.setArguments(args).withCollector(results);
代码示例来源:origin: apache/geode
@Override
public Map answer(InvocationOnMock invocation) throws Throwable {
ArgumentCaptor<Set> captor = ArgumentCaptor.forClass(Set.class);
verify(execution, atLeast(1)).withFilter(captor.capture());
Collection<String> keys = captor.getValue();
Map<String, String> results = new HashMap<String, String>();
for (String key : keys) {
results.put(key, key.replace("key_", "value_"));
}
return results;
}
});
代码示例来源:origin: spring-projects/spring-gemfire-examples
/**
* Calculate total sales for the given product
* @param productName the name of the product
* @return
*/
public BigDecimal forProduct(String productName) {
Execution functionExecution = FunctionService.onServer(pool)
.withArgs(productName);
ResultCollector<?,?> results = functionExecution.execute("CalculateTotalSalesForProduct");
List<?> list = (List<?>)results.getResult();
return ((BigDecimal)list.get(0));
}
}
代码示例来源:origin: apache/geode
resultTable = resultTable.setHeader("Summary");
Execution execution = FunctionService.onMembers(dsMembers).setArguments(functionArgs);
if (execution == null) {
return ResultBuilder.createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__CANNOT_EXECUTE);
代码示例来源:origin: apache/geode
execution = execution.withCollector(resultCollectorInstance);
execution = execution.setArguments(functionArgs);
execution = execution.withFilter(filters);
List<String> resultMessage = new ArrayList<>();
ResultCollector rc = execution.execute(function.getId());
if (function.hasResult()) {
results = (List) rc.getResult();
代码示例来源: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
@Before
public void setUp() {
hits = new ArrayList<EntryScore<String>>();
for (int i = 0; i < 23; i++) {
hits.add(new EntryScore("key_" + i, i));
expected.add(new LuceneResultStructImpl<String, String>("key_" + i, "value_" + i, i));
}
userRegion = mock(Region.class);
final ResultCollector collector = mock(ResultCollector.class);
execution = mock(Execution.class);
when(execution.withFilter(any())).thenReturn(execution);
when(execution.withCollector(any())).thenReturn(execution);
when(execution.execute(anyString())).thenReturn(collector);
when(collector.getResult()).then(new Answer() {
@Override
public Map answer(InvocationOnMock invocation) throws Throwable {
ArgumentCaptor<Set> captor = ArgumentCaptor.forClass(Set.class);
verify(execution, atLeast(1)).withFilter(captor.capture());
Collection<String> keys = captor.getValue();
Map<String, String> results = new HashMap<String, String>();
for (String key : keys) {
results.put(key, key.replace("key_", "value_"));
}
return results;
}
});
}
代码示例来源:origin: org.apache.geode/geode-modules
@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, true, true, true);
List<Integer> result = (List<Integer>) collector.getResult();
// Return the first (and only) element
return result.get(0);
}
代码示例来源:origin: apache/geode
@Override
public List<Object> executeFunctionOnRegion(String functionID, String regionName,
Object arguments, Set<?> keyFilter) {
Function function = authorizeAndGetFunction(regionName, functionID, arguments);
Region region = getRegion(regionName);
Execution execution = FunctionService.onRegion(region);
if (keyFilter != null) {
execution = execution.withFilter(keyFilter);
}
return executeFunction(execution, functionID, function, arguments);
}
代码示例来源: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: org.springframework.data/spring-data-gemfire
execution = execution.setArguments(getArgs());
execution = getCollector() != null ? execution.withCollector(getCollector()) : execution;
execution = getKeys() != null ? execution.withFilter(getKeys()) : execution;
resultCollector = execution.execute(this.functionId);
resultCollector = execution.execute(this.function);
内容来源于网络,如有侵权,请联系作者删除!