camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: [CAMEL-7969] Container sees Context prematurely (with default name)
Date Wed, 29 Oct 2014 10:20:41 GMT
On Wed, Oct 29, 2014 at 11:00 AM, Thomas Diesler <> wrote:
> Folks,
> for the WildFly/Camel <> integration
I’m looking for the general notion of a CamelContextRegistry. This would be an SPI extension
point that allows retrieval of a registered CamelContext identified by some id. Ideally, the
registry would contain all CamelContexts regardless what API (i.e. spring, cdi, dsl) is used.
Instances of (or extending) DefaultCamelContext should be registered automatically.
> There is already a starting point for that - the Container <>.
It has however a number of issues (CAMEL-7968 <>
 CAMEL-7969 <>)
> One of my key questions would be about the identity of a CamelContext. The closest I
could find is the (mutable) ’name’ property. Because of its mutability and possible unavailability
after construction time, it is not a good identity. As a result, 3rd party code is being called
with a partially constructed CamelContext without defined name property. Uniqueness of CamelContext
name is also an issue, because not enforced.
> I’d like to propose to make the CamelContext name immutable. It can probably still
be initialed lazy, but only once. For compatibility reasons it could write a warning in the
2.x series and be properly enforced in 3.x. The existing  extensions (i.e. spring, cdi, osgi)
could properly construct the DefaultCamelContext with a given name.

The idea is that a camel context can be configured anyway you want -
using getter/setter etc, DI, and whatnot.

And then its start() method is invoked when its ready to be used, and
it can do its initialization needed, such as setting up naming. As
Camel allows end users to not define any name, and Camel auto assigns
a name, or end users can define a naming pattern, which is used to
define the name etc.

So its not intended to provide a name in the constructor.

> Calls to the Container API would need to get fixed such that 3rd party only sees fully
constructed instances. If this is not possible to do in a compatible way, one could deprecate
the Container API and make a CamelContextRegistry part of camel-core. 3rd party would then
be registering listeners with the registry, instead of providing a singleton Container as
it is now.
> What do you think?

If you want to keep a list of all known CamelContext in a JVM, then
keep using the Container SPI hook, and then in the manage method, you
add an EventNotifier to the CamelContext, then that event notifier
will emit an event when the CamelContext is starting / started. So if
you listen for the started event, you have the name the context was

There is a support class you can extend which is easier

You then register your event notifier on the camel context


> cheers
> —thomas

Claus Ibsen
Red Hat, Inc.
Twitter: davsclaus
Author of Camel in Action:

View raw message