camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jyrki Ruuskanen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CAMEL-7875) Easier write access to Camel context registry
Date Wed, 01 Oct 2014 17:20:33 GMT

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

Jyrki Ruuskanen commented on CAMEL-7875:
----------------------------------------

I've been just thinking about the possible ways to make it easier to add objects into CamelContext's
registry from routebuilder's configure method. At the same time I'm trying to keep my routebuilders
portable so that they would run the same in org.apache.camel.main.Main and Karaf SCR bundle.

Your approach works fine in both as long as the CamelContext is created with a SimpleRegistry
and the routebuilder knows the registry key ("itself").

The change to SimpleRegistry up there in the original post is of course not possible because
it would make the registry non-empty when it's instanciated, and that would be odd to many
(including me). But the point was to guarantee that if routebuilder knows SimpleRegistry it
would also know its key.

The best solution would be to have a method for adding stuff in the Registry interface. Is
there a reason why Registry should be read-only?

> Easier write access to Camel context registry
> ---------------------------------------------
>
>                 Key: CAMEL-7875
>                 URL: https://issues.apache.org/jira/browse/CAMEL-7875
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Jyrki Ruuskanen
>            Priority: Minor
>
> I haven't found a nice way to add beans to Camel context registry through Camel context
reference in plain Java. Some beans are only needed by a certain endpoint and it would make
sense to set the bean up with the endpoint in routebuilder configure method.
> If we added a reference to self in SimpleRegistry we could setup the Camel context by
DefaultCamelContext(new SimpleRegistry()) or OsgiDefaultCamelContext(bundleContext, new SimpleRegistry())
and easily access the registry from the routebuilder with SimpleRegistry registry = (SimpleRegistry)
getContext().lookupByName(SimpleRegistry.NAME);.
> Then we can set up beans in routebuilder configure and simply add them with registry.put.
And the same routebuilder could be used in plain Java, in OSGi or elsewhere.
> All that is needed is this change in SimpleRegistry:
> {code}
> public static final String NAME;
> static {
>    NAME = java.util.UUID.randomUUID().tostring();
> }
> public SimpleRegistry() {
>    put.(NAME, this);
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message