use of org.apache.geode.cache.execute.ResultSender in project geode by apache.
the class MemberFunctionStreamingMessage method process.
@Override
protected void process(final DistributionManager dm) {
Throwable thr = null;
ReplyException rex = null;
if (this.functionObject == null) {
rex = new ReplyException(new FunctionException(LocalizedStrings.ExecuteFunction_FUNCTION_NAMED_0_IS_NOT_REGISTERED.toLocalizedString(this.functionName)));
replyWithException(dm, rex);
return;
}
FunctionStats stats = FunctionStats.getFunctionStats(this.functionObject.getId(), dm.getSystem());
TXStateProxy tx = null;
try {
tx = prepForTransaction();
ResultSender resultSender = new MemberFunctionResultSender(dm, this, this.functionObject);
Set<Region> regions = new HashSet<Region>();
if (this.regionPathSet != null) {
InternalCache cache = GemFireCacheImpl.getInstance();
for (String regionPath : this.regionPathSet) {
if (checkCacheClosing(dm) || checkDSClosing(dm)) {
thr = new CacheClosedException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString(dm.getId()));
return;
}
regions.add(cache.getRegion(regionPath));
}
}
FunctionContextImpl context = new MultiRegionFunctionContextImpl(this.functionObject.getId(), this.args, resultSender, regions, isReExecute);
long start = stats.startTime();
stats.startFunctionExecution(this.functionObject.hasResult());
if (logger.isDebugEnabled()) {
logger.debug("Executing Function: {} on remote member with context: {}", this.functionObject.getId(), context.toString());
}
this.functionObject.execute(context);
if (!this.replyLastMsg && this.functionObject.hasResult()) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(functionObject.getId()));
}
stats.endFunctionExecution(start, this.functionObject.hasResult());
} catch (FunctionException functionException) {
if (logger.isDebugEnabled()) {
logger.debug("FunctionException occurred on remote member while executing Function: {}", this.functionObject.getId(), functionException);
}
stats.endFunctionExecutionWithException(this.functionObject.hasResult());
rex = new ReplyException(functionException);
replyWithException(dm, rex);
// thr = functionException.getCause();
} catch (CancelException exception) {
// bug 37026: this is too noisy...
// throw new CacheClosedException("remote system shutting down");
// thr = se; cache is closed, no point trying to send a reply
thr = new FunctionInvocationTargetException(exception);
stats.endFunctionExecutionWithException(this.functionObject.hasResult());
rex = new ReplyException(thr);
replyWithException(dm, rex);
} catch (Exception exception) {
if (logger.isDebugEnabled()) {
logger.debug("Exception occurred on remote member while executing Function: {}", this.functionObject.getId(), exception);
}
stats.endFunctionExecutionWithException(this.functionObject.hasResult());
rex = new ReplyException(exception);
replyWithException(dm, rex);
// thr = e.getCause();
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
thr = t;
} finally {
cleanupTransaction(tx);
if (thr != null) {
rex = new ReplyException(thr);
replyWithException(dm, rex);
}
}
}
use of org.apache.geode.cache.execute.ResultSender in project geode by apache.
the class LuceneListIndexFunctionJUnitTest method testExecute.
@Test
@SuppressWarnings("unchecked")
public void testExecute() throws Throwable {
GemFireCacheImpl cache = Fakes.cache();
final String serverName = "mockServer";
LuceneServiceImpl service = mock(LuceneServiceImpl.class);
when(cache.getService(InternalLuceneService.class)).thenReturn(service);
FunctionContext context = mock(FunctionContext.class);
ResultSender resultSender = mock(ResultSender.class);
when(context.getResultSender()).thenReturn(resultSender);
LuceneIndexImpl index1 = getMockLuceneIndex("index1");
LuceneIndexImpl index2 = getMockLuceneIndex("index2");
TreeSet expectedResult = new TreeSet();
expectedResult.add(new LuceneIndexDetails(index1, serverName));
expectedResult.add(new LuceneIndexDetails(index2, serverName));
ArrayList<LuceneIndex> allIndexes = new ArrayList();
allIndexes.add(index1);
allIndexes.add(index2);
when(service.getAllIndexes()).thenReturn(allIndexes);
LuceneListIndexFunction function = new LuceneListIndexFunction();
function = spy(function);
Mockito.doReturn(cache).when(function).getCache();
function.execute(context);
ArgumentCaptor<Set> resultCaptor = ArgumentCaptor.forClass(Set.class);
verify(resultSender).lastResult(resultCaptor.capture());
Set<String> result = resultCaptor.getValue();
assertEquals(2, result.size());
assertEquals(expectedResult, result);
}
use of org.apache.geode.cache.execute.ResultSender in project geode by apache.
the class LuceneCreateIndexFunctionJUnitTest method prepare.
@Before
public void prepare() {
cache = Fakes.cache();
DistributedSystem ds = Fakes.distributedSystem();
member = ds.getDistributedMember().getId();
service = mock(InternalLuceneService.class);
when(cache.getService(InternalLuceneService.class)).thenReturn(service);
factory = mock(LuceneIndexFactory.class);
when(service.createIndexFactory()).thenReturn(factory);
context = mock(FunctionContext.class);
resultSender = mock(ResultSender.class);
when(context.getResultSender()).thenReturn(resultSender);
XmlEntity xmlEntity = null;
expectedResult = new CliFunctionResult(member, xmlEntity);
}
use of org.apache.geode.cache.execute.ResultSender in project geode by apache.
the class LuceneDescribeIndexFunctionJUnitTest method testExecute.
@Test
@SuppressWarnings("unchecked")
public void testExecute() throws Throwable {
GemFireCacheImpl cache = Fakes.cache();
final String serverName = "mockServer";
LuceneServiceImpl service = mock(LuceneServiceImpl.class);
when(cache.getService(InternalLuceneService.class)).thenReturn(service);
FunctionContext context = mock(FunctionContext.class);
ResultSender resultSender = mock(ResultSender.class);
LuceneIndexInfo indexInfo = getMockLuceneInfo("index1");
LuceneIndexImpl index1 = getMockLuceneIndex("index1");
LuceneDescribeIndexFunction function = spy(LuceneDescribeIndexFunction.class);
doReturn(indexInfo).when(context).getArguments();
doReturn(resultSender).when(context).getResultSender();
doReturn(cache).when(function).getCache();
when(service.getIndex(indexInfo.getIndexName(), indexInfo.getRegionPath())).thenReturn(index1);
function.execute(context);
ArgumentCaptor<LuceneIndexDetails> resultCaptor = ArgumentCaptor.forClass(LuceneIndexDetails.class);
verify(resultSender).lastResult(resultCaptor.capture());
LuceneIndexDetails result = resultCaptor.getValue();
LuceneIndexDetails expected = new LuceneIndexDetails(index1, "mockServer");
assertEquals(expected.getIndexName(), result.getIndexName());
assertEquals(expected.getRegionPath(), result.getRegionPath());
assertEquals(expected.getIndexStats(), result.getIndexStats());
assertEquals(expected.getFieldAnalyzersString(), result.getFieldAnalyzersString());
assertEquals(expected.getSearchableFieldNamesString(), result.getSearchableFieldNamesString());
}
use of org.apache.geode.cache.execute.ResultSender in project geode by apache.
the class PartitionedRegionDataStore method executeOnDataStore.
public void executeOnDataStore(final Set localKeys, final Function function, final Object object, final int prid, final Set<Integer> bucketSet, final boolean isReExecute, final PartitionedRegionFunctionStreamingMessage msg, long time, ServerConnection servConn, int transactionID) {
if (!areAllBucketsHosted(bucketSet)) {
throw new BucketMovedException(LocalizedStrings.FunctionService_BUCKET_MIGRATED_TO_ANOTHER_NODE.toLocalizedString());
}
final DM dm = this.partitionedRegion.getDistributionManager();
ResultSender resultSender = new PartitionedRegionFunctionResultSender(dm, this.partitionedRegion, time, msg, function, bucketSet);
final RegionFunctionContextImpl prContext = new RegionFunctionContextImpl(function.getId(), this.partitionedRegion, object, localKeys, ColocationHelper.constructAndGetAllColocatedLocalDataSet(this.partitionedRegion, bucketSet), bucketSet, resultSender, isReExecute);
FunctionStats stats = FunctionStats.getFunctionStats(function.getId(), dm.getSystem());
try {
long start = stats.startTime();
stats.startFunctionExecution(function.hasResult());
if (logger.isDebugEnabled()) {
logger.debug("Executing Function: {} on Remote Node with context: ", function.getId(), prContext);
}
function.execute(prContext);
stats.endFunctionExecution(start, function.hasResult());
} catch (FunctionException functionException) {
if (logger.isDebugEnabled()) {
logger.debug("FunctionException occurred on remote node while executing Function: {}", function.getId(), functionException);
}
stats.endFunctionExecutionWithException(function.hasResult());
if (functionException.getCause() instanceof QueryInvalidException) {
// create a new FunctionException on the original one's message (not cause).
throw new FunctionException(functionException.getLocalizedMessage());
}
throw functionException;
}
}
Aggregations