[ 
https://issues.apache.org/jira/browse/CAMEL-27655?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen updated CAMEL-27655:
--------------------------------
    Fix Version/s: 4.25.0
                       (was: 4.24.0)

> camel-bean: Request scope instance sharing, class component ignores scope and 
> cache size
> ----------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27655
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27655
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-bean
>            Reporter: Claus Ibsen
>            Priority: Minor
>             Fix For: 4.25.0
>
>
> Found while improving the option descriptions of camel-bean for CAMEL-23832 
> (commit 
> https://github.com/apache/camel/commit/55c9815b8de5c1e08c040c34b4b89ddb9e526c89).
> These are separate problems of the component; the descriptions commit only 
> documents the current behavior.
> h4. 1. Request scope with {{bean.*}} options on the class component shares 
> one instance
> {{ClassComponent.createEndpoint()}} creates a single bean and a 
> {{ConstantBeanHolder}} when {{bean.*}} options are given. 
> {{BeanEndpoint.doInit()}} replaces that holder only for Prototype scope; for 
> Request scope it wraps it in a {{RequestBeanHolder}}, which returns the same 
> constant bean for every exchange.
> So {{class:com.foo.MyBean?scope=Request&bean.foo=1}} uses one instance for 
> all exchanges, and the bean must be thread-safe after all.
> Proposed change: in {{BeanEndpoint.doInit()}} also use a 
> {{ConstantTypeBeanHolder}} (with the options) for Request scope, as done for 
> Prototype.
> h4. 2. Request-scoped beans of the same class share one instance within an 
> exchange
> {{RequestBeanHolder}} stores the bean in the exchange property 
> {{CamelBeanRequestScope-<class name>}}. Two endpoints with {{scope=Request}} 
> whose beans have the same class, for example {{bean:a?scope=Request}} and 
> {{bean:b?scope=Request}} with two different {{MyBean}} instances in the 
> registry, use the same key: the second call of the exchange invokes the bean 
> of the first endpoint.
> Proposed change: make the key unique per holder (for example add the bean 
> name or an id of the endpoint).
> h4. 3. The scope option of the class component has no effect
> {{ClassComponent.createEndpoint()}} does not call 
> {{endpoint.setScope(scope)}}, unlike {{BeanComponent.createEndpoint()}}. 
> Setting {{camel.component.class.scope=Prototype}} is accepted but class 
> endpoints keep the Singleton default.
> Proposed change: call {{endpoint.setScope(getScope())}} before 
> {{setProperties}} in {{ClassComponent.createEndpoint()}}.
> h4. 4. The beanInfoCacheSize option of the class component has no effect
> {{ClassComponent.doInit()}} passes the {{bean}} component to the bean 
> holders, so the class endpoints use the cache of the bean component. The 
> cache that {{BeanComponent.doStart()}} creates for the class component is 
> never used.
> Proposed change: either use the class component's own cache, or skip the 
> cache of the class component and document that the bean component's 
> {{beanInfoCacheSize}} applies.
> h4. 5. The component option scope has an empty label
> In {{bean.json}} and {{class.json}} the component option {{scope}} has 
> {{"label": ""}} (group producer), while the endpoint option {{scope}} has 
> label {{common}}.
> Proposed change: give the {{@Metadata}} of {{BeanComponent.scope}} a label, 
> such as {{producer}}.
> _Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to