Search in sources :

Example 6 with ResultSender

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);
        }
    }
}
Also used : FunctionContextImpl(org.apache.geode.internal.cache.execute.FunctionContextImpl) MultiRegionFunctionContextImpl(org.apache.geode.internal.cache.execute.MultiRegionFunctionContextImpl) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) MemberFunctionResultSender(org.apache.geode.internal.cache.execute.MemberFunctionResultSender) ResultSender(org.apache.geode.cache.execute.ResultSender) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException) QueryException(org.apache.geode.cache.query.QueryException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionStats(org.apache.geode.internal.cache.execute.FunctionStats) MemberFunctionResultSender(org.apache.geode.internal.cache.execute.MemberFunctionResultSender) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) MultiRegionFunctionContextImpl(org.apache.geode.internal.cache.execute.MultiRegionFunctionContextImpl) HashSet(java.util.HashSet)

Example 7 with ResultSender

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);
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) FunctionContext(org.apache.geode.cache.execute.FunctionContext) ResultSender(org.apache.geode.cache.execute.ResultSender) LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) TreeSet(java.util.TreeSet) LuceneIndexDetails(org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 8 with ResultSender

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);
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) InternalLuceneService(org.apache.geode.cache.lucene.internal.InternalLuceneService) DistributedSystem(org.apache.geode.distributed.DistributedSystem) LuceneIndexFactory(org.apache.geode.cache.lucene.LuceneIndexFactory) FunctionContext(org.apache.geode.cache.execute.FunctionContext) ResultSender(org.apache.geode.cache.execute.ResultSender) Before(org.junit.Before)

Example 9 with ResultSender

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());
}
Also used : LuceneIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo) LuceneIndexDetails(org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) FunctionContext(org.apache.geode.cache.execute.FunctionContext) ResultSender(org.apache.geode.cache.execute.ResultSender) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 10 with ResultSender

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;
    }
}
Also used : RegionFunctionContextImpl(org.apache.geode.internal.cache.execute.RegionFunctionContextImpl) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) FunctionException(org.apache.geode.cache.execute.FunctionException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) DM(org.apache.geode.distributed.internal.DM) FunctionStats(org.apache.geode.internal.cache.execute.FunctionStats) PartitionedRegionFunctionResultSender(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionResultSender) ResultSender(org.apache.geode.cache.execute.ResultSender) PartitionedRegionFunctionResultSender(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionResultSender)

Aggregations

ResultSender (org.apache.geode.cache.execute.ResultSender)13 FunctionContext (org.apache.geode.cache.execute.FunctionContext)6 FunctionException (org.apache.geode.cache.execute.FunctionException)5 FunctionStats (org.apache.geode.internal.cache.execute.FunctionStats)5 IOException (java.io.IOException)4 Set (java.util.Set)4 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)4 UnitTest (org.apache.geode.test.junit.categories.UnitTest)4 Test (org.junit.Test)4 Region (org.apache.geode.cache.Region)3 InternalLuceneService (org.apache.geode.cache.lucene.internal.InternalLuceneService)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 ServerToClientFunctionResultSender (org.apache.geode.internal.cache.execute.ServerToClientFunctionResultSender)3 HashSet (java.util.HashSet)2 CancelException (org.apache.geode.CancelException)2 CacheClosedException (org.apache.geode.cache.CacheClosedException)2 LowMemoryException (org.apache.geode.cache.LowMemoryException)2 Function (org.apache.geode.cache.execute.Function)2 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)2 LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)2