use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class LocalResultCollectorImpl method getResult.
public Object getResult() throws FunctionException {
if (this.resultCollected) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_ALREADY_COLLECTED.toLocalizedString());
}
this.resultCollected = true;
try {
this.latch.await();
} catch (InterruptedException e) {
this.latch.countDown();
Thread.currentThread().interrupt();
}
this.latch = new CountDownLatch(1);
if (this.functionException != null && !this.execution.isIgnoreDepartedMembers()) {
if (this.function.isHA()) {
if (this.functionException.getCause() instanceof InternalFunctionInvocationTargetException) {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.function);
} else {
newRc = this.execution.execute(this.function.getId());
}
return newRc.getResult();
}
}
throw this.functionException;
} else {
Object result = this.userRC.getResult();
return result;
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class LocalResultCollectorImpl method getResult.
public Object getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException {
boolean resultRecieved = false;
if (this.resultCollected) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_ALREADY_COLLECTED.toLocalizedString());
}
this.resultCollected = true;
try {
resultRecieved = this.latch.await(timeout, unit);
} catch (InterruptedException e) {
this.latch.countDown();
Thread.currentThread().interrupt();
}
if (!resultRecieved) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_NOT_COLLECTED_IN_TIME_PROVIDED.toLocalizedString());
}
this.latch = new CountDownLatch(1);
if (this.functionException != null && !this.execution.isIgnoreDepartedMembers()) {
if (this.function.isHA()) {
if (this.functionException.getCause() instanceof InternalFunctionInvocationTargetException) {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.function);
} else {
newRc = this.execution.execute(this.function.getId());
}
return newRc.getResult(timeout, unit);
}
}
throw this.functionException;
} else {
Object result = this.userRC.getResult(timeout, unit);
return result;
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class DistributedRegionFunctionExecutor method execute.
public ResultCollector execute(String functionName, boolean hasResult) throws FunctionException {
if (functionName == null) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_THE_INPUT_FUNCTION_FOR_THE_EXECUTE_FUNCTION_REQUEST_IS_NULL.toLocalizedString());
}
Function functionObject = FunctionService.getFunction(functionName);
if (functionObject == null) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_FUNCTION_NAMED_0_IS_NOT_REGISTERED.toLocalizedString(functionObject));
}
if (region.getAttributes().getDataPolicy().isNormal()) {
throw new FunctionException(LocalizedStrings.ExecuteRegionFunction_CAN_NOT_EXECUTE_ON_NORMAL_REGION.toLocalizedString());
}
byte registeredFunctionState = AbstractExecution.getFunctionState(functionObject.isHA(), functionObject.hasResult(), functionObject.optimizeForWrite());
byte functionState = AbstractExecution.getFunctionState(hasResult, hasResult, false);
if (registeredFunctionState != functionState) {
throw new FunctionException(LocalizedStrings.FunctionService_FUNCTION_ATTRIBUTE_MISMATCH_CLIENT_SERVER.toLocalizedString(functionName));
}
this.isFnSerializationReqd = false;
// For other combination use next API
return executeFunction(functionObject);
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class DistributedRegionFunctionResultSender method lastResult.
public void lastResult(Object oneResult) {
if (!this.functionObject.hasResult()) {
throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
}
if (this.localLastResultRecieved) {
return;
}
this.localLastResultRecieved = true;
if (this.sender != null) {
// Client-Server
sender.lastResult(oneResult);
if (this.rc != null) {
this.rc.endResults();
}
} else {
if (isLocal) {
this.rc.addResult(dm.getDistributionManagerId(), oneResult);
this.rc.endResults();
FunctionStats.getFunctionStats(functionObject.getId(), this.dm.getSystem()).incResultsReceived();
} else {
try {
this.msg.sendReplyForOneResult(dm, oneResult, true, enableOrderedResultStreming);
} catch (ForceReattemptException e) {
throw new FunctionException(e);
} catch (InterruptedException e) {
throw new FunctionException(e);
}
}
// incrementing result sent stats.
FunctionStats.getFunctionStats(functionObject.getId(), this.dm.getSystem()).incResultsReturned();
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class DistributedRegionFunctionResultSender method sendResult.
public synchronized void sendResult(Object oneResult) {
if (!this.functionObject.hasResult()) {
throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
}
if (this.sender != null) {
// Client-Server
sender.sendResult(oneResult);
} else {
if (isLocal) {
this.rc.addResult(dm.getDistributionManagerId(), oneResult);
FunctionStats.getFunctionStats(functionObject.getId(), this.dm.getSystem()).incResultsReceived();
} else {
try {
this.msg.sendReplyForOneResult(dm, oneResult, false, enableOrderedResultStreming);
} catch (ForceReattemptException e) {
throw new FunctionException(e);
} catch (InterruptedException e) {
throw new FunctionException(e);
}
}
// incrementing result sent stats.
FunctionStats.getFunctionStats(functionObject.getId(), this.dm.getSystem()).incResultsReturned();
}
}
Aggregations