Hi Henrik,

What you suggest corresponds to what we have done for "direct-vm" component
of camel (
https://github.com/apache/camel/blob/trunk/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmComponent.java)
where we use a static variable to register Consumer. This is not the case
at all with "direct" component (
https://github.com/apache/camel/blob/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectComponent.java
)

See screenshot here : http://camel.apache.org/direct-vm

Remark : If you plan to share data using a cache, then a solution based on
camel-cache, camel-hazelcast, hazelcast, ... could be also the way to go.

Regards,

Charles


On Mon, Feb 11, 2013 at 9:20 PM, Henryk Konsek <hekon...@gmail.com> wrote:

> Hi,
>
> I would like to have your opinion about sharing static members in the
> Camel components.
>
> Imagine the following scenario.
>
> I want to create a Camel component that would be deployed on
> ServiceMix. I want my component to cache some state and share it
> between the ServiceMix bundles. For example I would like to share a
> cache between bundles.
>
> Let's assume that I cannot use OSGI service registry for some reason.
>
> I decided then to implement my component to contain a shared static state.
>
> class MyComponent extends DefaultComponent {
>
> private static final Map<String,String> sharedCache = ...;
>
> ...
>
> }
>
> I also created Karaf feature for my component.
>
> Then I created bundles with routes making use of my component.
>
> from("my-component://...").to(...);
>
> My assumption would be as follows then - if I install my component as
> a feature in ServiceMix, then the other bundles using it will share
> the static cache MyComponent#sharedCache (because it will be always
> loaded by the same class loader associated with the bundle from
> feature).
>
> Do you see any drawbacks of this approach?
>
> --
> Henryk Konsek
> http://henryk-konsek.blogspot.com
>



-- 
Charles Moulliard
Apache Committer / Sr. Enterprise Architect (RedHat)
Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com

Reply via email to