Search in sources :

Example 1 with MyFunctionExecutionException

use of org.apache.geode.internal.cache.execute.MyFunctionExecutionException in project geode by apache.

the class TestFunction method executeFunctionReexecuteException.

private synchronized void executeFunctionReexecuteException(FunctionContext context) {
    retryCountForExecuteFunctionReexecuteException++;
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.fine("Executing executeException in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (retryCountForExecuteFunctionReexecuteException >= 5) {
        logger.fine("Tried Function Execution 5 times. Now Returning after 5 attempts");
        context.getResultSender().lastResult(new Integer(retryCountForExecuteFunctionReexecuteException));
        retryCountForExecuteFunctionReexecuteException = 0;
        return;
    }
    if (context.getArguments() instanceof Boolean) {
        logger.fine("MyFunctionExecutionException is intentionally thrown");
        throw new FunctionInvocationTargetException(new MyFunctionExecutionException("I have been thrown from TestFunction"));
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) MyFunctionExecutionException(org.apache.geode.internal.cache.execute.MyFunctionExecutionException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 2 with MyFunctionExecutionException

use of org.apache.geode.internal.cache.execute.MyFunctionExecutionException in project geode by apache.

the class TestFunction method executeWithThrowException.

private void executeWithThrowException(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    RegionFunctionContext rfContext = (RegionFunctionContext) context;
    LogWriter logger = ds.getLogWriter();
    logger.fine("Executing executeWithThrowException in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (context.getArguments() instanceof Boolean) {
        logger.fine("MyFunctionExecutionException Exception is intentionally thrown");
        throw new MyFunctionExecutionException("I have been thrown from TestFunction");
    } else if (rfContext.getArguments() instanceof Set) {
        Set origKeys = (Set) rfContext.getArguments();
        for (Iterator i = origKeys.iterator(); i.hasNext(); ) {
            Region r = PartitionRegionHelper.getLocalDataForContext(rfContext);
            Object key = i.next();
            Object val = r.get(key);
            if (val != null) {
                throw new MyFunctionExecutionException("I have been thrown from TestFunction");
            }
        }
    } else {
        logger.fine("Result sent back :" + Boolean.FALSE);
        rfContext.getResultSender().lastResult(Boolean.FALSE);
    }
}
Also used : Set(java.util.Set) LogWriter(org.apache.geode.LogWriter) MyFunctionExecutionException(org.apache.geode.internal.cache.execute.MyFunctionExecutionException) Iterator(java.util.Iterator) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 3 with MyFunctionExecutionException

use of org.apache.geode.internal.cache.execute.MyFunctionExecutionException in project geode by apache.

the class TestFunction method executeFunctionReexecuteExceptionOnServer.

private synchronized void executeFunctionReexecuteExceptionOnServer(FunctionContext context) {
    if (context.isPossibleDuplicate()) {
        retryCount++;
    } else {
        firstExecutionCount++;
    }
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.fine("Executing executeException in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (retryCount >= 5) {
        logger.fine("Tried Function Execution 5 times. Now Returning after 5 attempts");
        context.getResultSender().sendResult(new Integer(firstExecutionCount));
        context.getResultSender().lastResult(new Integer(retryCount));
        firstExecutionCount = 0;
        retryCount = 0;
        return;
    }
    if (context.getArguments() instanceof Boolean) {
        logger.fine("MyFunctionExecutionException Exception is intentionally thrown");
        throw new InternalFunctionInvocationTargetException(new MyFunctionExecutionException("I have been thrown from TestFunction"));
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) MyFunctionExecutionException(org.apache.geode.internal.cache.execute.MyFunctionExecutionException) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 4 with MyFunctionExecutionException

use of org.apache.geode.internal.cache.execute.MyFunctionExecutionException in project geode by apache.

the class TestFunction method executeWithSendException.

private void executeWithSendException(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.fine("Executing executeWithSendException in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (context.getArguments() instanceof Boolean) {
        context.getResultSender().sendException(new MyFunctionExecutionException("I have been send from TestFunction"));
    } else if (context.getArguments() instanceof String) {
        String arg = (String) context.getArguments();
        if (arg.equals("Multiple")) {
            logger.fine("Sending Exception First time");
            context.getResultSender().sendException(new MyFunctionExecutionException("I have been send from TestFunction"));
            logger.fine("Sending Exception Second time");
            context.getResultSender().sendException(new MyFunctionExecutionException("I have been send from TestFunction"));
        }
    } else if (context.getArguments() instanceof Set) {
        Set args = (Set) context.getArguments();
        for (int i = 0; i < args.size(); i++) {
            context.getResultSender().sendResult(new Integer(i));
        }
        context.getResultSender().sendException(new MyFunctionExecutionException("I have been thrown from TestFunction with set"));
    } else {
        logger.fine("Result sent back :" + Boolean.FALSE);
        context.getResultSender().lastResult(Boolean.FALSE);
    }
}
Also used : Set(java.util.Set) LogWriter(org.apache.geode.LogWriter) MyFunctionExecutionException(org.apache.geode.internal.cache.execute.MyFunctionExecutionException) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 5 with MyFunctionExecutionException

use of org.apache.geode.internal.cache.execute.MyFunctionExecutionException in project geode by apache.

the class TestFunction method executeException.

private void executeException(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.fine("Executing executeException in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (context.getArguments() instanceof Boolean) {
        logger.fine("MyFunctionExecutionException Exception is intentionally thrown");
        throw new MyFunctionExecutionException("I have been thrown from TestFunction");
    } else if (context.getArguments() instanceof String) {
        String key = (String) context.getArguments();
        logger.fine("Result sent back :" + key);
        context.getResultSender().lastResult(key);
    } else if (context.getArguments() instanceof Set) {
        Set origKeys = (Set) context.getArguments();
        ArrayList vals = new ArrayList();
        for (Iterator i = origKeys.iterator(); i.hasNext(); ) {
            Object val = i.next();
            if (val != null) {
                vals.add(val);
            }
        }
        logger.fine("Result sent back :" + vals);
        context.getResultSender().lastResult(vals);
    } else {
        logger.fine("Result sent back :" + Boolean.FALSE);
        context.getResultSender().lastResult(Boolean.FALSE);
    }
}
Also used : Set(java.util.Set) LogWriter(org.apache.geode.LogWriter) MyFunctionExecutionException(org.apache.geode.internal.cache.execute.MyFunctionExecutionException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Aggregations

LogWriter (org.apache.geode.LogWriter)5 DistributedSystem (org.apache.geode.distributed.DistributedSystem)5 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)5 MyFunctionExecutionException (org.apache.geode.internal.cache.execute.MyFunctionExecutionException)5 Set (java.util.Set)3 Iterator (java.util.Iterator)2 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)2 ArrayList (java.util.ArrayList)1 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)1 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1