本文整理了Java中org.apache.geode.cache.execute.Execution.setArguments()
方法的一些代码示例,展示了Execution.setArguments()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Execution.setArguments()
方法的具体详情如下:
包路径:org.apache.geode.cache.execute.Execution
类名称:Execution
方法名:setArguments
[英]Specifies the user data passed to the function when it is executed. The function can retrieve these arguments using FunctionContext#getArguments()
[中]指定执行函数时传递给函数的用户数据。函数可以使用FunctionContext#getArguments()检索这些参数
代码示例来源: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
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 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
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
protected ConfigurationResponse requestConfigurationFromOneLocator(
InternalDistributedMember locator, Set<String> groups) {
ConfigurationResponse configResponse = null;
try {
ResultCollector resultCollector = FunctionService.onMember(locator).setArguments(groups)
.execute(GET_CLUSTER_CONFIG_FUNCTION);
Object result = ((ArrayList) resultCollector.getResult()).get(0);
if (result instanceof ConfigurationResponse) {
configResponse = (ConfigurationResponse) result;
configResponse.setMember(locator);
} else {
logger.error("Received invalid result from {}: {}", locator.toString(), result);
if (result instanceof Throwable) {
// log the stack trace.
logger.error(result.toString(), result);
}
}
} catch (FunctionException fex) {
// Rethrow unless we're possibly reconnecting
if (!(fex.getCause() instanceof LockServiceDestroyedException
|| fex.getCause() instanceof FunctionInvocationTargetException)) {
throw fex;
}
}
return configResponse;
}
代码示例来源: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
/***
* 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
rc = FunctionService.onRegion(this).setArguments((Serializable) value)
.execute(PRContainsValueFunction.class.getName());
List<Boolean> results = ((List<Boolean>) rc.getResult());
代码示例来源:origin: apache/geode
execution.setArguments(indexName).execute(IndexingInProgressFunction.ID);
List<Boolean> results = (List<Boolean>) resultCollector.getResult();
for (Boolean result : 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
@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
when(execution.setArguments(any())).thenReturn(execution);
when(execution.withCollector(any())).thenReturn(execution);
when(execution.execute(anyString())).thenReturn(resultCollector);
代码示例来源:origin: apache/geode
obj[0] = functionId;
Execution execution = FunctionService.onMembers(DsMembers).setArguments(obj);
代码示例来源: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
@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
.setArguments(new Object[] {this.sessionRegion.getFullPath(), sessionIds});
try {
ResultCollector collector = execution.execute(TouchReplicatedRegionEntriesFunction.ID);
代码示例来源: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);
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!