本文整理了Java中org.apache.geode.cache.execute.Execution.withCollector()
方法的一些代码示例,展示了Execution.withCollector()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Execution.withCollector()
方法的具体详情如下:
包路径:org.apache.geode.cache.execute.Execution
类名称:Execution
方法名:withCollector
[英]Specifies the ResultCollector that will receive the results after the function has been executed. Collector will receive results as they are sent from the Function#execute(FunctionContext) using ResultSender.
[中]
代码示例来源: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
@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: 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
when(execution.withCollector(any())).thenReturn(execution);
when(execution.execute(anyString())).thenReturn(resultCollector);
代码示例来源:origin: apache/geode
@Before
public void createMocks() {
region = mock(Region.class);
execution = mock(Execution.class);
collector = mock(ResultCollector.class);
provider = mock(LuceneQueryProvider.class);
cache = mock(Cache.class);
cacheTransactionManager = mock(CacheTransactionManager.class);
when(region.getCache()).thenReturn(cache);
when(region.getCache().getCacheTransactionManager()).thenReturn(cacheTransactionManager);
when(region.getCache().getCacheTransactionManager().exists()).thenReturn(false);
when(execution.setArguments(any())).thenReturn(execution);
when(execution.withCollector(any())).thenReturn(execution);
when(execution.execute(anyString())).thenReturn((ResultCollector) collector);
results = mock(PageableLuceneQueryResults.class);
query = new LuceneQueryImpl<Object, Object>("index", region, provider, LIMIT, 20) {
@Override
protected Execution onRegion() {
return execution;
}
@Override
protected PageableLuceneQueryResults<Object, Object> newPageableResults(final int pageSize,
final TopEntries<Object> entries) {
return results;
}
};
}
代码示例来源:origin: apache/geode
execution = FunctionService.onMembers(targetMembers).withCollector(collector);
} else {
execution = FunctionService.onMembers().withCollector(collector);
代码示例来源:origin: apache/geode
.setArguments(args).withCollector(results);
代码示例来源: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
execution = execution.withCollector(resultCollectorInstance);
代码示例来源:origin: apache/geode
private TopEntries<K> findTopEntries() throws LuceneQueryException {
TopEntriesCollectorManager manager = new TopEntriesCollectorManager(null, limit);
LuceneFunctionContext<TopEntriesCollector> context =
new LuceneFunctionContext<>(query, indexName, manager, limit);
if (region.getCache().getCacheTransactionManager().exists()) {
throw new LuceneQueryException(LUCENE_QUERY_CANNOT_BE_EXECUTED_WITHIN_A_TRANSACTION);
}
// TODO provide a timeout to the user?
TopEntries<K> entries = null;
try {
TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context);
ResultCollector<TopEntriesCollector, TopEntries<K>> rc =
onRegion().setArguments(context).withCollector(collector).execute(LuceneQueryFunction.ID);
entries = rc.getResult();
} catch (FunctionException e) {
if (e.getCause() instanceof LuceneQueryException) {
throw (LuceneQueryException) e.getCause();
} else if (e.getCause() instanceof TransactionException) {
// When run from client with single hop disabled
throw new LuceneQueryException(LUCENE_QUERY_CANNOT_BE_EXECUTED_WITHIN_A_TRANSACTION);
} else if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw e;
} catch (TransactionException e) {
// When function execution is run from server
throw new LuceneQueryException(LUCENE_QUERY_CANNOT_BE_EXECUTED_WITHIN_A_TRANSACTION);
}
return entries;
}
代码示例来源:origin: org.springframework.data/spring-data-gemfire
execution = getCollector() != null ? execution.withCollector(getCollector()) : execution;
execution = getKeys() != null ? execution.withFilter(getKeys()) : execution;
代码示例来源:origin: org.springframework.data/spring-data-geode
execution = getCollector() != null ? execution.withCollector(getCollector()) : execution;
execution = getKeys() != null ? execution.withFilter(getKeys()) : execution;
内容来源于网络,如有侵权,请联系作者删除!