[
https://issues.apache.org/jira/browse/CAMEL-17618?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17901926#comment-17901926
]
Gordon Freeman commented on CAMEL-17618:
----------------------------------------
Now I'm using the old version of camel - 2.25.4 and everything works there.
I'm updating my project to the latest version and ran into an error.
I can't tell the latest version in which this works, it would take me a long
time to check.
But even in the old version of camel it is written in Javadoc for *getEndpoint*
method:
{code:java}
* Resolves the given name to an {@link Endpoint} of the specified type.
* If the name has a singleton endpoint registered, then the singleton is
returned.
* Otherwise, a new {@link Endpoint} is created and registered in the
{@link org.apache.camel.spi.EndpointRegistry}.
{code}
It is not written that the method ever returns null. I still think you should
use the *CamelContext.hasEndpoint* method instead of {*}getEndpoint{*}.
{code:java}
RefEndpoint.doInit:
if (getCamelContext().getEndpoint(getEndpoint().getEndpointUri())
== null
||
getCamelContext().getEndpoint(getEndpoint().getEndpointUri()) != endpoint) {
getCamelContext().addEndpoint(getEndpoint().getEndpointUri(),
endpoint);
}
{code}
I think the current code works like this: the *getEndpoint* method creates a
new endpoint, then checks that it is not equal to our endpoint, after which the
*addEndpoint* method removes the newly created endpoint and replaces it with
ours. Thus, unnecessary work is performed, and we wastefully create and destroy
the endpoint. But no one notices this, except when *getEndpoint* fails to
create an endpoint and throws an exception.
> camel-ref: only add the endpoint into camelContext when not exist
> -----------------------------------------------------------------
>
> Key: CAMEL-17618
> URL: https://issues.apache.org/jira/browse/CAMEL-17618
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 3.15.0
> Reporter: Freeman Yue Fang
> Assignee: Freeman Yue Fang
> Priority: Minor
> Fix For: 3.11.6, 3.14.2, 3.16.0
>
>
> Currently camel-ref endpoint always adds the underlying endpoint like
> getCamelContext().addEndpoint(getEndpoint().getEndpointUri(), endpoint);
> We should check if it exists or not firstly like
> if (getCamelContext().getEndpoint(getEndpoint().getEndpointUri()) ==
> null) {
> getCamelContext().addEndpoint(getEndpoint().getEndpointUri(),
> endpoint);
> }
> Because if we re-add the same endpoint, this endpoint actually will be stopped
--
This message was sent by Atlassian Jira
(v8.20.10#820010)