Package org.mule.retry

Examples of org.mule.retry.DefaultRetryContext


    public RetryContext execute(RetryCallback callback, WorkManager workManager) throws Exception
    {
        PolicyStatus status = null;
        RetryPolicy policy = createRetryInstance();
        DefaultRetryContext context = new DefaultRetryContext(callback.getWorkDescription(),
            metaInfo);
        context.setMuleContext(muleContext);

        try
        {
            Exception cause = null;
            do
            {
                try
                {
                    callback.doWork(context);
                    if (notifier != null)
                    {
                        notifier.onSuccess(context);
                    }
                    break;
                }
                catch (Exception e)
                {
                    cause = e;
                    if (logger.isDebugEnabled())
                    {
                        logger.debug(cause);
                    }
                    if (notifier != null)
                    {
                        notifier.onFailure(context, cause);
                    }
                    if (cause instanceof InterruptedException || cause instanceof InterruptedIOException)
                    {
                        logger.error("Process was interrupted (InterruptedException), ceasing process");
                        break;
                    }
                    else
                    {
                        status = policy.applyPolicy(cause);
                    }
                }
            }
            while (status.isOk());

            if (status == null || status.isOk())
            {
                return context;
            }
            else
            {
                context.setFailed(cause);
                throw new RetryPolicyExhaustedException(cause, callback.getWorkDescription());
            }
        }
        finally
        {
View Full Code Here


    public RetryContext execute(RetryCallback callback, WorkManager workManager) throws Exception
    {
        PolicyStatus status = null;
        RetryPolicy policy = createRetryInstance();
        DefaultRetryContext context = new DefaultRetryContext(callback.getWorkDescription(),
            metaInfo);
        context.setMuleContext(muleContext);

        try
        {
            Exception cause = null;
            do
            {
                try
                {
                    callback.doWork(context);
                    if (notifier != null)
                    {
                        notifier.onSuccess(context);
                    }
                    break;
                }
                catch (Exception e)
                {
                    cause = e;
                    if (logger.isDebugEnabled())
                    {
                        logger.debug(cause);
                    }
                    if (notifier != null)
                    {
                        notifier.onFailure(context, cause);
                    }
                    if (cause instanceof InterruptedException || cause instanceof InterruptedIOException)
                    {
                        logger.error("Process was interrupted (InterruptedException), ceasing process");
                        break;
                    }
                    else
                    {
                        status = policy.applyPolicy(cause);
                    }
                }
            }
            while (status.isOk());

            if (status == null || status.isOk())
            {
                return context;
            }
            else
            {
                context.setFailed(cause);
                throw new RetryPolicyExhaustedException(cause, callback.getWorkDescription());
            }
        }
        finally
        {
View Full Code Here

                     O object,
                     MessageProcessor messageProcessor,
                     MuleEvent event) throws Exception
    {
        RetryPolicy retryPolicy = retryPolicyTemplate.createRetryInstance();
        DefaultRetryContext retryContext = new DefaultRetryContext("Work Descriptor", metaInfo);
        retryContext.setMuleContext(muleContext);
        PolicyStatus status = null;
        T result = null;
        try
        {
            Exception cause = null;
            do
            {
                try
                {
                    result = this.next.execute(processCallback, object, messageProcessor, event);
                    if (retryPolicyTemplate.getNotifier() != null)
                    {
                        retryPolicyTemplate.getNotifier().onSuccess(retryContext);
                    }
                    return result;
                }
                catch (Exception e)
                {
                    cause = e;
                    if (logger.isDebugEnabled())
                    {
                        logger.debug(cause.getMessage(), cause);
                    }
                    if (retryPolicyTemplate.getNotifier() != null)
                    {
                        retryPolicyTemplate.getNotifier().onFailure(retryContext, cause);
                    }
                    boolean isManagedException = false;
                    if (processCallback.getManagedExceptions() != null)
                    {
                        for (Class<? extends Exception> exceptionClass : processCallback.getManagedExceptions())
                        {
                            if (exceptionClass.isInstance(e))
                            {
                                isManagedException = true;
                                break;
                            }
                        }
                    }
                    if ((cause instanceof InterruptedException) || (cause instanceof InterruptedIOException))
                    {
                        logger.error("Process was interrupted (InterruptedException), ceasing process");
                        break;
                    }
                    else
                    {
                        if (isManagedException)
                        {
                            status = retryPolicy.applyPolicy(cause);
                        }
                        else
                        {
                            status = PolicyStatus.policyExhausted(cause);
                        }
                    }
                }
            }
            while (status.isOk());
            if ((status != null) && (!status.isOk()))
            {
                retryContext.setFailed(cause);
                throw cause;
            }
        }
        finally
        {
View Full Code Here

TOP

Related Classes of org.mule.retry.DefaultRetryContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.