You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "Mark Proctor (JIRA)" <ji...@apache.org> on 2010/07/06 21:30:52 UTC

[jira] Created: (CAMEL-2914) ProcessorDefinition aware Policy

ProcessorDefinition aware Policy
--------------------------------

                 Key: CAMEL-2914
                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
             Project: Apache Camel
          Issue Type: Improvement
          Components: camel-core
            Reporter: Mark Proctor
             Fix For: 2.4.0


Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.

As discussed in this mailing list post:
http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Commented: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Hadrian Zbarcea (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=60462#action_60462 ] 

Hadrian Zbarcea commented on CAMEL-2914:
----------------------------------------

I have to update the wiki documentation tomorrow morning and then we can close this issue.

A slightly better variation of this would be to modify the signature of the wrap() method in PolicyDefinition itself and get rid of the DefinitionAwarePolicy class. Now we have these 2 different iterfaces that both represent policies that can inject code to be invoked during processing, but the DefinitionAwarePolicy is also capable of altering the route. No need for both, I think, the implementer of a Policy, could just ignore the last argument if it has no need to alter the route. Although a binary incompatible change, the migration is trivial.

I'll make this change tomorrow morning too, if there's no objection.

> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Commented: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=60473#action_60473 ] 

Claus Ibsen commented on CAMEL-2914:
------------------------------------

Adjusted the SPI a bit to have a {{beforeWrap}} method which ensure the {{Policy}} contract is kept in the wrap method.

{code}

    /**
     * Callback invoked before the wrap.
     * <p/>
     * This allows you to do any custom logic before the processor is wrapped. For example to
     * manipulate the {@link org.apache.camel.model.ProcessorDefinition definiton}
     *
     * @param routeContext   the route context
     * @param definition     the processor definition
     */
    void beforeWrap(RouteContext routeContext, ProcessorDefinition<?> definition);
{code}

trunk: 961251.

> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>            Assignee: Hadrian Zbarcea
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Updated: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Mark Proctor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mark Proctor updated CAMEL-2914:
--------------------------------

    Attachment: DefinitionAwarePolicy.diff

> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Commented: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=60471#action_60471 ] 

Claus Ibsen commented on CAMEL-2914:
------------------------------------

Hadrian Camel already have an API for manipulating the routes before they are created
{{CamelContext.getRouteDefinition}} gives your the route in which you can manipulate all the way you like.

Its just that out of the box Camel will auto start the routes and there is not a super duper easy way of adding a hook which allows you to easily manipulate the route definitions.
See the discussion on the mailing list for a better alternative.

Hacking the policy is not the way to go. 

I am cooking up the {{ProcessorFactory}} SPI now so we have a easy way to register a custom hook.

For example this is from an unit test I got so far, which does what the PolicyAware stuff did.


{code}

    @Override
    protected CamelContext createCamelContext() throws Exception {
        CamelContext context = super.createCamelContext();
        // register our custom factory
        context.setProcessorCreatorFactory(new MyFactory());
        return context;
    }

    public static class MyFactory implements ProcessorFactory {

        public Processor createChildProcessor(RouteContext routeContext, ProcessorDefinition definition, boolean mandatory) throws Exception {
            return null;
        }

        public Processor createProcessor(RouteContext routeContext, ProcessorDefinition definition) throws Exception {
            if (definition instanceof SetBodyDefinition) {
                SetBodyDefinition set = (SetBodyDefinition) definition;
                set.setExpression(new ConstantExpression("body was altered"));
            }

            // return null to let the default implementation create the processor, we just wanted to alter the definition
            // before the processor was created
            return null;
        }
    }



> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>            Assignee: Hadrian Zbarcea
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Commented: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Hadrian Zbarcea (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=60461#action_60461 ] 

Hadrian Zbarcea commented on CAMEL-2914:
----------------------------------------

Patch applied with thanks to Mark: r961060.

I had to make a few changes for checkstyle and I changed the order of params in the swap method to be more like the existing Policy. Then I had to change a bit the test to change the ExpressionClause for the body to be reset.

> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Resolved: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen resolved CAMEL-2914.
--------------------------------

    Resolution: Fixed

> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>            Assignee: Hadrian Zbarcea
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Commented: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Hadrian Zbarcea (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=60470#action_60470 ] 

Hadrian Zbarcea commented on CAMEL-2914:
----------------------------------------

There are already a lot of users who use different uris for the endpoints in different environments (such as using mock endpoints in test environments). Using properties for these uris works very well. What camel lacks is a way to not only substitute endpoint uri values, but also parts of the routes do deal with slas and what not.

I agree that an spi for manipulating the entire ast is a great improvement, but that is not defined yet and this is a simple and non-intrusive solution that allows one to enhance (as opposed to pollute) a route. I don't feel strongly about modifying the Policy interface, we could leave the DefinitionAwarePolicy and deprecate it later if/when the spi will provide a better way.

> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>            Assignee: Hadrian Zbarcea
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Commented: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=60493#action_60493 ] 

Claus Ibsen commented on CAMEL-2914:
------------------------------------

I added a note in the 2.4 release notes about the API change
https://cwiki.apache.org/confluence/display/CAMEL/Camel+2.4.0+Release

> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>            Assignee: Hadrian Zbarcea
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Commented: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Hadrian Zbarcea (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=60483#action_60483 ] 

Hadrian Zbarcea commented on CAMEL-2914:
----------------------------------------

As the beforeWrap cannot be used without Policy so moving the method to Policy instead of having a separate interface makes more sense. The binary incompatibility needs documenting. The solution to migrate is simple, only need to implement beforeWrap() as an empty method.

Commit done r961439. Awaiting documentation.

> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>            Assignee: Hadrian Zbarcea
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Commented: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=60465#action_60465 ] 

Claus Ibsen commented on CAMEL-2914:
------------------------------------

Damn we are still debating a solution on the mailing list. 

So please *don't* be so jumpy and apply patches so fast. I am not convinced this is the best solution right now.
Using policy to hack into the model is not the way to go.

Please discuss the proposal of a new SPI allowing to register a custom hook which can listen and react when the runtime processor model is created.
Then you can register the hook without using Policy or _polluting_ the routes.

> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>            Assignee: Hadrian Zbarcea
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Assigned: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Hadrian Zbarcea (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hadrian Zbarcea reassigned CAMEL-2914:
--------------------------------------

    Assignee: Hadrian Zbarcea

> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>            Assignee: Hadrian Zbarcea
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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


[jira] Issue Comment Edited: (CAMEL-2914) ProcessorDefinition aware Policy

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=60471#action_60471 ] 

Claus Ibsen edited comment on CAMEL-2914 at 7/7/10 1:44 AM:
------------------------------------------------------------

Hadrian Camel already have an API for manipulating the routes before they are created
{{CamelContext.getRouteDefinition}} gives your the route in which you can manipulate all the way you like.

Its just that out of the box Camel will auto start the routes and there is not a super duper easy way of adding a hook which allows you to easily manipulate the route definitions.
See the discussion on the mailing list for a better alternative.

Hacking the policy is not the way to go. 

I am cooking up the {{ProcessorFactory}} SPI now so we have a easy way to register a custom hook.

For example this is from an unit test I got so far, which does what the PolicyAware stuff did.

{code}
    @Override
    protected CamelContext createCamelContext() throws Exception {
        CamelContext context = super.createCamelContext();
        // register our custom factory
        context.setProcessorCreatorFactory(new MyFactory());
        return context;
    }

    public static class MyFactory implements ProcessorFactory {

        public Processor createChildProcessor(RouteContext routeContext, ProcessorDefinition definition, boolean mandatory) throws Exception {
            return null;
        }

        public Processor createProcessor(RouteContext routeContext, ProcessorDefinition definition) throws Exception {
            if (definition instanceof SetBodyDefinition) {
                SetBodyDefinition set = (SetBodyDefinition) definition;
                set.setExpression(new ConstantExpression("body was altered"));
            }

            // return null to let the default implementation create the processor, we just wanted to alter the definition
            // before the processor was created
            return null;
        }
    }
{code}



      was (Author: davsclaus):
    Hadrian Camel already have an API for manipulating the routes before they are created
{{CamelContext.getRouteDefinition}} gives your the route in which you can manipulate all the way you like.

Its just that out of the box Camel will auto start the routes and there is not a super duper easy way of adding a hook which allows you to easily manipulate the route definitions.
See the discussion on the mailing list for a better alternative.

Hacking the policy is not the way to go. 

I am cooking up the {{ProcessorFactory}} SPI now so we have a easy way to register a custom hook.

For example this is from an unit test I got so far, which does what the PolicyAware stuff did.


{code}

    @Override
    protected CamelContext createCamelContext() throws Exception {
        CamelContext context = super.createCamelContext();
        // register our custom factory
        context.setProcessorCreatorFactory(new MyFactory());
        return context;
    }

    public static class MyFactory implements ProcessorFactory {

        public Processor createChildProcessor(RouteContext routeContext, ProcessorDefinition definition, boolean mandatory) throws Exception {
            return null;
        }

        public Processor createProcessor(RouteContext routeContext, ProcessorDefinition definition) throws Exception {
            if (definition instanceof SetBodyDefinition) {
                SetBodyDefinition set = (SetBodyDefinition) definition;
                set.setExpression(new ConstantExpression("body was altered"));
            }

            // return null to let the default implementation create the processor, we just wanted to alter the definition
            // before the processor was created
            return null;
        }
    }


  
> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>            Assignee: Hadrian Zbarcea
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the processor instances are created prior to wrap being called. I would like to see the child Processsor defintions passed to wrap, and the processor instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

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