You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Guillaume Nodet (Jira)" <ji...@apache.org> on 2019/09/05 18:06:00 UTC

[jira] [Commented] (CAMEL-13948) Unpredictable registry lookup

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

Guillaume Nodet commented on CAMEL-13948:
-----------------------------------------

Right, unpredictable results is really a bad idea.

I think when an object is bound in the registry, we should first walk through each of the instance's parent classes and interfaces and unbind any object with the same name + class/interface, then bind the object.

> Unpredictable registry lookup
> -----------------------------
>
>                 Key: CAMEL-13948
>                 URL: https://issues.apache.org/jira/browse/CAMEL-13948
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Luca Burgazzoli
>            Priority: Major
>             Fix For: 3.0.0, 3.0.0.RC2
>
>
> The camel registry support binding multiple classes to the same entry via the bind method:
> {code:java}
>     void bind(String id, Class<?> type, Object bean)
> {code}
> The underlying implementation is roughly:
> {code:java}
>     void bind(String id, Class<?> type, Object bean) {
>         computeIfAbsent(id, k -> new LinkedHashMap<>()).put(type, bean);
>     }
> {code}
> So assuming I have a class MyLogComponent which extends LogComponent and I do the following binding:
> {code:java}
>     Component a = new LogComponent()
>     Component b = new MyLogComponent()
>     registry.bind("log", LogComponent.class, a )
>     registry.bind("log", MyLogComponent.class, b)
> {code}
> then lookupByNameAndType may return different values depending on the type used for looking up the beans:
> {code:java}
>     registry.lookupByNameAndType("log", LogComponent.class)  ==> a
>     registry.lookupByNameAndType("log", MyLogComponent.class)   ==> b
>     registry.lookupByNameAndType("log", DefaultComponent.class)  ==> a or b (depends on the order)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.2#803003)