use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class ServerRegionFunctionExecutor method getServerRegionProxy.
private ServerRegionProxy getServerRegionProxy() throws FunctionException {
ServerRegionProxy srp = region.getServerProxy();
if (srp != null) {
if (logger.isDebugEnabled()) {
logger.debug("Found server region proxy on region. RegionName: {}", region.getName());
}
return srp;
} else {
StringBuilder message = new StringBuilder();
message.append(srp).append(": ");
message.append("No available connection was found. Server Region Proxy is not available for this region ").append(region.getName());
throw new FunctionException(message.toString());
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class ClientExporter method export.
@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>());
// check for errors.
return (Long) rc.getResult();
} catch (FunctionException e) {
throw new IOException(e);
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class MemberFunctionExecutor method executeFunction.
@SuppressWarnings("unchecked")
private ResultCollector executeFunction(final Function function, ResultCollector resultCollector) {
final DM dm = this.ds.getDistributionManager();
final Set dest = new HashSet(this.members);
if (dest.isEmpty()) {
throw new FunctionException(LocalizedStrings.MemberFunctionExecutor_NO_MEMBER_FOUND_FOR_EXECUTING_FUNCTION_0.toLocalizedString(function.getId()));
}
validateExecution(function, dest);
setExecutionNodes(dest);
final InternalDistributedMember localVM = this.ds.getDistributionManager().getDistributionManagerId();
final LocalResultCollector<?, ?> localRC = getLocalResultCollector(function, resultCollector);
boolean remoteOnly = false;
boolean localOnly = false;
if (!dest.contains(localVM)) {
remoteOnly = true;
}
if (dest.size() == 1 && dest.contains(localVM)) {
localOnly = true;
}
final MemberFunctionResultSender resultSender = new MemberFunctionResultSender(dm, localRC, function, localOnly, remoteOnly, sender);
if (dest.contains(localVM)) {
// if member is local VM
dest.remove(localVM);
final FunctionContext context = new FunctionContextImpl(function.getId(), getArgumentsForMember(localVM.getId()), resultSender);
boolean isTx = false;
InternalCache cache = GemFireCacheImpl.getInstance();
if (cache != null) {
isTx = cache.getTxManager().getTXState() == null ? false : true;
}
executeFunctionOnLocalNode(function, context, resultSender, dm, isTx);
}
if (!dest.isEmpty()) {
HashMap<InternalDistributedMember, Object> memberArgs = new HashMap<InternalDistributedMember, Object>();
Iterator<DistributedMember> iter = dest.iterator();
while (iter.hasNext()) {
InternalDistributedMember recip = (InternalDistributedMember) iter.next();
memberArgs.put(recip, getArgumentsForMember(recip.getId()));
}
Assert.assertTrue(memberArgs.size() == dest.size());
MemberFunctionResultWaiter resultReciever = new MemberFunctionResultWaiter(this.ds, localRC, function, memberArgs, dest, resultSender);
ResultCollector reply = resultReciever.getFunctionResultFrom(dest, function, this);
return reply;
}
return localRC;
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class MemberFunctionResultSender method sendResult.
public void sendResult(Object oneResult) {
if (!this.function.hasResult()) {
throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
}
if (this.serverSender != null) {
// Client-Server
if (logger.isDebugEnabled()) {
logger.debug("MemberFunctionResultSender sending result from local node to client {}", oneResult);
}
this.serverSender.sendResult(oneResult);
} else {
// P2P
if (this.msg != null) {
try {
this.msg.sendReplyForOneResult(dm, oneResult, false, enableOrderedResultStreming);
} catch (QueryException e) {
throw new FunctionException(e);
} catch (ForceReattemptException e) {
throw new FunctionException(e);
} catch (InterruptedException e) {
throw new FunctionException(e);
}
} else {
this.rc.addResult(this.dm.getDistributionManagerId(), oneResult);
FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReceived();
}
// incrementing result sent stats.
FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReturned();
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class MemberFunctionResultSender method lastResult.
public void lastResult(Object oneResult) {
if (!this.function.hasResult()) {
throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
}
if (this.serverSender != null) {
// client-server
if (this.localLastResultRecieved) {
return;
}
if (onlyLocal) {
this.serverSender.lastResult(oneResult);
this.rc.endResults();
this.localLastResultRecieved = true;
} else {
lastResult(oneResult, rc, false, true, this.dm.getId());
}
} else {
// P2P
if (this.msg != null) {
try {
this.msg.sendReplyForOneResult(dm, oneResult, true, enableOrderedResultStreming);
} catch (QueryException e) {
throw new FunctionException(e);
} catch (ForceReattemptException e) {
throw new FunctionException(e);
} catch (InterruptedException e) {
throw new FunctionException(e);
}
} else {
if (this.localLastResultRecieved) {
return;
}
if (onlyLocal) {
this.rc.addResult(this.dm.getDistributionManagerId(), oneResult);
this.rc.endResults();
this.localLastResultRecieved = true;
} else {
// call a synchronized method as local node is also waiting to send lastResult
lastResult(oneResult, rc, false, true, this.dm.getDistributionManagerId());
}
FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReceived();
}
}
FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReturned();
}
Aggregations