Return-Path: X-Original-To: apmail-camel-dev-archive@www.apache.org Delivered-To: apmail-camel-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 10A971733E for ; Wed, 29 Oct 2014 10:21:29 +0000 (UTC) Received: (qmail 38648 invoked by uid 500); 29 Oct 2014 10:21:28 -0000 Delivered-To: apmail-camel-dev-archive@camel.apache.org Received: (qmail 38602 invoked by uid 500); 29 Oct 2014 10:21:28 -0000 Mailing-List: contact dev-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list dev@camel.apache.org Received: (qmail 38588 invoked by uid 99); 29 Oct 2014 10:21:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Oct 2014 10:21:28 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of claus.ibsen@gmail.com designates 209.85.223.170 as permitted sender) Received: from [209.85.223.170] (HELO mail-ie0-f170.google.com) (209.85.223.170) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Oct 2014 10:21:03 +0000 Received: by mail-ie0-f170.google.com with SMTP id tp5so2687455ieb.1 for ; Wed, 29 Oct 2014 03:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=MtV4eqfYeUfswjWDZsMliZQyGxEq+WH/CgLtr9Fak1c=; b=YY/57HSBC5W10CEF36+mwhvpIozdPlEv2Xfwi8Faygrtb9GyLOV4gYM6mgAq7c9k8Q g9Oq9SKvNWcKr7SzpXBQWOc4mgTv1mluMOWrbEdDi+N+PybphzI2SWdlfWFlkt8XKuwM xfLnArosEtQ/PUhgu+j80KVg5Pv9jTnhvDx/jo/VZOoX7rLEb6D3FvIf46UfGjnSahHt 2DAwEzzdtXkqf9j8NI20k6jpK4MqOGJVgei2zxhdzNRUUrPxJG1vPuI9tytvu0X0Z7y8 HswlirHcBXdcNONqNR/7EYsuRTNwQNoxTYU045AAsDGtEGcW12NdC4phAswR3SwxgGM1 77fw== X-Received: by 10.107.16.19 with SMTP id y19mr1024835ioi.77.1414578061637; Wed, 29 Oct 2014 03:21:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.126.136 with HTTP; Wed, 29 Oct 2014 03:20:41 -0700 (PDT) In-Reply-To: References: From: Claus Ibsen Date: Wed, 29 Oct 2014 11:20:41 +0100 Message-ID: Subject: Re: [CAMEL-7969] Container sees Context prematurely (with default name) To: dev Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Wed, Oct 29, 2014 at 11:00 AM, Thomas Diesler wrot= e: > Folks, > > for the WildFly/Camel integration I=E2=80=99m looking for the general notion of a CamelContextR= egistry. This would be an SPI extension point that allows retrieval of a re= gistered CamelContext identified by some id. Ideally, the registry would co= ntain all CamelContexts regardless what API (i.e. spring, cdi, dsl) is used= . Instances of (or extending) DefaultCamelContext should be registered auto= matically. > > 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. Th= e closest I could find is the (mutable) =E2=80=99name=E2=80=99 property. Be= cause of its mutability and possible unavailability after construction time= , it is not a good identity. As a result, 3rd party code is being called wi= th a partially constructed CamelContext without defined name property. Uniq= ueness of CamelContext name is also an issue, because not enforced. > > I=E2=80=99d like to propose to make the CamelContext name immutable. It c= an probably still be initialed lazy, but only once. For compatibility reaso= ns 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 constr= uct 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 on= ly sees fully constructed instances. If this is not possible to do in a com= patible way, one could deprecate the Container API and make a CamelContextR= egistry part of camel-core. 3rd party would then be registering listeners w= ith 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 given. http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/m= anagement/event/package-frame.html There is a support class you can extend which is easier http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/s= upport/EventNotifierSupport.html You then register your event notifier on the camel context context.getManagementStrategy().addEventNotifier(myNotifier); > cheers > =E2=80=94thomas --=20 Claus Ibsen ----------------- Red Hat, Inc. Email: cibsen@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen hawtio: http://hawt.io/ fabric8: http://fabric8.io/