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

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

Fair enough. If there are that many read-only Registry implementations we 
obviously can't add a write method to Registry interface.

The thought of easier write access to CamelContext's registry came to me when a 
component in a route required a bean in the registry (jetty securityHandler, 
restlet restletRealm and others). The go-to object in Camel is CamelContext and 
I was surprised to learn there is no method for adding beans there.

OK, I thought, I'll just create the CamelContext with a SimpleRegistry and pass 
it to the RouteBuilders. This worked fine until I noticed that CamelTestSupport 
doesn't offer a way to create the context with a SimpleRegistry. Well, I 
dropped CamelTestSupport and nowadays create the tests as plain JUnit4 tests.

Still, instead of making every framework around CamelContext (such as 
CamelTestSupport) flexible enough to suit everyone CamelContext could host its 
own SimpleRegistry by default which would offer write access and which would be 
included in the lookups (not unlike CompositeRegistry). Its usage could be 
something like:

{code}
context.getEmbeddedRegistry().put("name", bean);
{code}

What do you think?

> 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
>            Assignee: Willem Jiang
>            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)

Reply via email to