You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "Hadrian Zbarcea (JIRA)" <ji...@apache.org> on 2010/10/14 05:38:40 UTC

[jira] Issue Comment Edited: (CAMEL-1823) doCatch(Predicate)

    [ https://issues.apache.org/activemq/browse/CAMEL-1823?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=62567#action_62567 ] 

Hadrian Zbarcea edited comment on CAMEL-1823 at 10/13/10 11:36 PM:
-------------------------------------------------------------------

I've been playing with this one.

It actually could be resolved with a couple of fields.
If we added a new constructor on the TryDefinition, passing in 

something like 
{code}
 public TryDefinition doCatch(Predicate predicateInTry) {
        this.predicate = predicateInTry;
        CatchDefinition answer = new CatchDefinition(RuntimeException.class);
        //CatchPredicateDefinition answer = new CatchPredicateDefinition(predicateInTry);
        addOutput(answer);
        pushBlock(answer);
        return this;
    }
{code}
And then set that field and on the TryProcessor around line 90
{code}
AsyncProcessor processor = processors.next();
            if (catchPredicateProcessor != null && catchPredicateProcessor.getCatchPredicateProcessor().getPredicate().matches(exchange)) {
                if (catchPredicateProcessor == processor) {
                    LOG.info("We should route this " + processor);
                } else {
                    LOG.info("We should not route this" + exchange.getUnitOfWork());
                    exchange.setException(new InternalPredicateRouteInATryCatchContext("met Predicate"));

                }
            }
{code}

We throw an internal exception, this is used from the CatchProcessor/CatchDefinition to bail on the route.

Just an idea, but would be very un-intrusive and easy to test, it also would allow a Predicate to run through 
as many AsyncProcessors as needed inspecting the "last" exchange for the predicate.

/je

      was (Author: joed):
    I've been playing with this one.

It actually could be resolved with a couple of fields.
If we added a new constructor on the TryDefinition, passing in 

something like 

 public TryDefinition doCatch(Predicate predicateInTry) {
        this.predicate = predicateInTry;
        CatchDefinition answer = new CatchDefinition(RuntimeException.class);
        //CatchPredicateDefinition answer = new CatchPredicateDefinition(predicateInTry);
        addOutput(answer);
        pushBlock(answer);
        return this;
    }

And then set that field and on the TryProcessor around line 90

AsyncProcessor processor = processors.next();
            if (catchPredicateProcessor != null && catchPredicateProcessor.getCatchPredicateProcessor().getPredicate().matches(exchange)) {
                if (catchPredicateProcessor == processor) {
                    LOG.info("We should route this " + processor);
                } else {
                    LOG.info("We should not route this" + exchange.getUnitOfWork());
                    exchange.setException(new InternalPredicateRouteInATryCatchContext("met Predicate"));

                }
            }


We throw an internal exception, this is used from the CatchProcessor/CatchDefinition to bail on the route.

Just an idea, but would be very un-intrusive and easy to test, it also would allow a Predicate to run through 
as many AsyncProcessors as needed inspecting the "last" exchange for the predicate.

/je
  
> doCatch(Predicate)
> ------------------
>
>                 Key: CAMEL-1823
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-1823
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>             Fix For: Future
>
>
> As someone suggested on the user forum.
> Letting {{doCatch}} be able to catch and react to a predicate as well. Currently it *only* reacts when an exception has been thrown.
> Letting it react to predicates as well will really set it high over its Java counter part.
> {code}
> doTry()
>    .beanRef("myBean")
>    .to("activemq:queue:foo")
> .doCatch(body().isNull())
>    .to("log:foo?level=WARN")
> .end()
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.