...
It's confusing to users that geode wraps their result collector in another collector that has different behavior, and it's unclear why the user has to call the returned result collector. We should stop wrapping the user's result collector, and instead .
We should make sure that users don't have to call getResults on the returned ResultCollector. If we want to make it easier for users to implement a ResultCollector that waits for all of the results to arrive, we should provide helper classes like a BlockingResultCollector that waits for all results to arrive in getResults.
Summary of changes
New interfaces
Code Block |
---|
interface RegionFunction<T> {
public T execute(RegionFunctionContext context)
}
interface MemberFunction<T> {
public T execute(FunctionContext context)
}
interface RegionExecution<T,S> extends Execution {
public ResultCollector<T, S> execute(RegionFunction<T> function);
}
interface MemberExecution<T,S> extends Execution {
public ResultCollector<T, S> execute(MemberFunction<T> function);
}
|
New Methods
Code Block |
---|
FunctionService Cache.getFunctionService() Region RegionFunctionContext.getLocalDataSet(); Execution.isHA(boolean value) Execution.optimizeForWrite(boolean value) Execution.hasResult(boolean value) //New instance methods, rather than static FunctionService { public RegionExecution onRegion(Region region); public MemberExecution onServer(RegionService regionService); public MemberExecution onServers(RegionService regionService); public MemberExecution onMember(DistributedMember distributedMember); public MemberExecution onMembers(Set<DistributedMember> distributedMembers); public MemberExecution onMember(String... groups); public void registerFunction(Function function); public void unregisterFunction(String functionId); public boolean isRegistered(String functionId); } |
Deprecated Methods
Code Block |
---|
FunctionService {
public static Execution onRegion(Region region);
public static Execution onServer(Pool pool);
public static Execution onServers(Pool pool);
public static Execution onMember(DistributedMember distributedMember);
public static Execution onMember(String... groups);
public static Function getFunction(String functionId);
public static void registerFunction(Function function);
public static void unregisterFunction(String functionId);
public static boolean isRegistered(String functionId);
}
Function {
public boolean hasResult();
public boolean optimizeForWrite();
public boolean isHA();
} |
Examples of API changes
Code Block |
---|
FunctionService functionService = cache.getFunctionService(); //RegionFunction with a single result ResultCollector<String, Collection<String>> rc = functionService.onRegion(region) .execute(ctx -> ctx.getLocalData().get("key")) Collection<String> values = rc.getResult() //RegionFunction without a result, that is optimized for write, but is not HA functionService.onRegion(region) .optimizeForWrite(true) .isHA(true) .hasResult(false) .execute(ctx -> ctx.getLocalData().put("key", "value)) //On member function that gets the cache from the context functionService.onMembers() .hasResult(false) .execute(ctx -> ctx.getCache().getName()); //Function that streams results back using the result sender functionService.onRegion(region).execute( ctx -> { ResultSender<String> s = ctx.getResultSender(); for(String value : ctx.getRegion().values()) { s.addResult(value) } return null; } |