Package org.mule.retry

Examples of org.mule.retry.PolicyStatus


        this.muleContext = context;
    }

    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
        {
            if (status != null && status.getThrowable() != null)
            {
                if (logger.isDebugEnabled())
                {
                    logger.debug(status.getThrowable());
                }
            }
        }
    }
View Full Code Here


        this.muleContext = context;
    }

    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
        {
            if (status != null && status.getThrowable() != null)
            {
                if (logger.isDebugEnabled())
                {
                    logger.debug(status.getThrowable());
                }
            }
        }
    }
View Full Code Here

                     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
        {
            if ((status != null) && (status.getThrowable() != null))
            {
                if (logger.isDebugEnabled())
                {
                    logger.debug(status.getThrowable().getMessage(), status.getThrowable());
                }
            }
        }
        return null;
    }
View Full Code Here

TOP

Related Classes of org.mule.retry.PolicyStatus

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.