You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by thelonesquirrely <th...@gmail.com> on 2011/04/15 19:52:30 UTC
Adding a startup listener via spring
Hello,
The problem I am having involves starting a thread _after_ the context has
fully started. The thread makes some calls to some routes, and if they
aren't started i get some exceptions.
To get around this now, I simply delay the start of the thread (Major hack)
- and everything goes well.
But I'd like to fix this up. I am using spring to configure my entire
project, and I don't see any XML that I can use to specify which bean to
call, or which method.
So the thing looks like this:
<camel:camelContext id="camelContext" />
and some bean:
<bean id="updater" class="some.class.that.impls.StartupListener" />
I'd like to be able to say something like this:
<camel:camelContext id="camelContext" >
<camel:startupListener ref="updater" />
</camel:camelContext>
But i don't see any way to do this? Am I missing something? I don't want to
have to toss out spring or write a wrapper class if at all possible...
Thanks for any advice you have!
--
View this message in context: http://camel.465427.n5.nabble.com/Adding-a-startup-listener-via-spring-tp4306163p4306163.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Adding a startup listener via spring
Posted by metatech <me...@gmail.com>.
Hi Claus,
For the record, I used the following solution.
In my camel-config.xml :
<osgi:reference id="myapp-1" filter="(camel.context.symbolicname=myapp-1)"
interface="org.apache.camel.CamelContext" timeout="60"/>
<osgi:reference id="myapp-2" filter="(camel.context.symbolicname=myapp-2)"
interface="org.apache.camel.CamelContext" timeout="60"/>
Note 1 : this solution does not require to use several values of
"start-levels" for each application, which would require to launch Karaf
command-line instructions for "hot deployed" applications (ie not features).
Note 2 : optional dependencies are not possible, all referenced camel
contexts must be installed and started. For optional dependencies, it is
necessary to use the programmatic equivalent with
"BundleContext.getServiceReferences".
Note 3 : the timeout attribute does not appear to be taken into account,
only the one specified in the bundle manifest header actually is, like this
:
Spring-Context: *;timeout:=60
with the following instruction in my pom.xml for maven-bundle-plugin :
<_include>src/main/resources/META-INF/MANIFEST-fragment.MF</_include>
Hope this helps,
Regards,
metatech
On Mon, Jan 9, 2012 at 9:30 AM, metatech <metatechbe@> wrote:
> Hi Claus,
>
> I tried the "depends-on" solution but unfortunately the camel context is
> started asynchronously after the Spring context is initialized.
> The behaviour is implemented in class OsgiSpringCamelContext, method
> onApplicationEvent.
> Do you think of any other reliable way to define dependencies between
> camel
> contexts ?
>
spring-dm has a option AFAIR where you can tell it to start synchronously.
Its an option you need to set in your bundles MANIFEST.MF file. Its
documented somewhere in the spring-dm docs.
I found some stuff here
http://static.springsource.org/osgi/docs/1.2.1/reference/html/app-deploy.html#app-deploy:required-libraries
See the create-asynchronously option
> Thanks,
>
> metatech
>
>
>
> Claus Ibsen-2 wrote
>>
>> In Spring XML you should be able to use the depends-on attribute to
>> say that your bean depends on Camel.
>>
>> <camelContext id="myCamel" ...>
>>
>> <bean id="foo" depends-on="myCamel" ...>
>>
>>
>>
>>
>
>
--
View this message in context: http://camel.465427.n5.nabble.com/Adding-a-startup-listener-via-spring-tp4306163p5148621.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Adding a startup listener via spring
Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Jan 9, 2012 at 9:30 AM, metatech <me...@gmail.com> wrote:
> Hi Claus,
>
> I tried the "depends-on" solution but unfortunately the camel context is
> started asynchronously after the Spring context is initialized.
> The behaviour is implemented in class OsgiSpringCamelContext, method
> onApplicationEvent.
> Do you think of any other reliable way to define dependencies between camel
> contexts ?
>
spring-dm has a option AFAIR where you can tell it to start synchronously.
Its an option you need to set in your bundles MANIFEST.MF file. Its
documented somewhere in the spring-dm docs.
I found some stuff here
http://static.springsource.org/osgi/docs/1.2.1/reference/html/app-deploy.html#app-deploy:required-libraries
See the create-asynchronously option
> Thanks,
>
> metatech
>
>
>
> Claus Ibsen-2 wrote
>>
>> In Spring XML you should be able to use the depends-on attribute to
>> say that your bean depends on Camel.
>>
>> <camelContext id="myCamel" ...>
>>
>> <bean id="foo" depends-on="myCamel" ...>
>>
>>
>>
>>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Adding-a-startup-listener-via-spring-tp4306163p5130769.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: Adding a startup listener via spring
Posted by metatech <me...@gmail.com>.
Hi Claus,
I tried the "depends-on" solution but unfortunately the camel context is
started asynchronously after the Spring context is initialized.
The behaviour is implemented in class OsgiSpringCamelContext, method
onApplicationEvent.
Do you think of any other reliable way to define dependencies between camel
contexts ?
Thanks,
metatech
Claus Ibsen-2 wrote
>
> In Spring XML you should be able to use the depends-on attribute to
> say that your bean depends on Camel.
>
> <camelContext id="myCamel" ...>
>
> <bean id="foo" depends-on="myCamel" ...>
>
>
>
>
--
View this message in context: http://camel.465427.n5.nabble.com/Adding-a-startup-listener-via-spring-tp4306163p5130769.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Adding a startup listener via spring
Posted by Claus Ibsen <cl...@gmail.com>.
In Spring XML you should be able to use the depends-on attribute to
say that your bean depends on Camel.
<camelContext id="myCamel" ...>
<bean id="foo" depends-on="myCamel" ...>
On Fri, Apr 15, 2011 at 8:15 PM, thelonesquirrely
<th...@gmail.com> wrote:
> Ok after thinking about this i def thought of a tolerable way...kinda a
> workaround but eh -
>
> if you have the same situation you can flip the dependency:
>
>
> <camel:camelContext id="camelContext" />
>
> and some bean:
> <bean id="updater" class="some.class.that.impls.StartupListener" >
> <property name="camelContext" ref="camelContext" />
> </bean>
>
> And then the java code to support this all?
>
> UpdateMgr:
> public class UpdateMgr implements StartupListener {
> …
> public void onCamelContextStarted (CamelContext context, boolean
> alreadyStarted) throws Exception {
> this.start ();
> }
> …
> public void setCamelContext (CamelContext context) {
> context.addStartupListener (this);
> }
> …
> }
>
> this seems reasonable, but please feel free to fry me alive if it isn't :)
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Adding-a-startup-listener-via-spring-tp4306163p4306258.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: Adding a startup listener via spring
Posted by thelonesquirrely <th...@gmail.com>.
Ok after thinking about this i def thought of a tolerable way...kinda a
workaround but eh -
if you have the same situation you can flip the dependency:
<camel:camelContext id="camelContext" />
and some bean:
<bean id="updater" class="some.class.that.impls.StartupListener" >
<property name="camelContext" ref="camelContext" />
</bean>
And then the java code to support this all?
UpdateMgr:
public class UpdateMgr implements StartupListener {
…
public void onCamelContextStarted (CamelContext context, boolean
alreadyStarted) throws Exception {
this.start ();
}
…
public void setCamelContext (CamelContext context) {
context.addStartupListener (this);
}
…
}
this seems reasonable, but please feel free to fry me alive if it isn't :)
--
View this message in context: http://camel.465427.n5.nabble.com/Adding-a-startup-listener-via-spring-tp4306163p4306258.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Consumer and Producer names in JMX
Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Apr 27, 2011 at 4:40 PM, <mi...@icw.de> wrote:
> Hi Claus,
>
> It's about the name that is shown in the JMX tree uner
> org.apache.camel/consumers/context/consumerName (see the code snppet)
>
> There is an endpoint uri attribute in the jmx objects, but it does not
> help navigate. One has to expand the jmx Consumer/Producer objects to find
> to which endpoint they belong.
>
Yeah I think we can improve that as it helps in the overview to faster
spot the desired consumer.
Fell free to create a JIRA ticket
> Regards,
> Mitko
>
>
>
>
> From:
> Claus Ibsen <cl...@gmail.com>
> To:
> dev@camel.apache.org
> Date:
> 27.04.2011 16:17
> Subject:
> Re: Consumer and Producer names in JMX
>
>
>
> They have an endpoint uri attribute.
>
>
> On Wed, Apr 27, 2011 at 4:11 PM, <mi...@icw.de> wrote:
>> Hello Camel devs,
>>
>> Currently the consumer and producer names in JMX have a name based on
>> their java instance [1]. Due to this it is not obvious what is the
>> endpoint of the consumers/producers.
>>
>> Would not it be better to use name based on endpoint URI of the
>> consumer/producer endpoints (combined with identityHashcode) instead?
>>
>>
>> [1] Copy/paste from the DefaultManagementNamingStrategy
>>
>> ...
>> String name = consumer.getClass().getSimpleName();
>> if (ObjectHelper.isEmpty(name)) {
>> name = "Consumer";
>> }
>> buffer.append(KEY_NAME + "=")
>> .append(name)
>> .append("(").append(ObjectHelper.getIdentityHashCode
>> (consumer)).append(")");
>>
>> ...
>>
>> Regards,
>> Mitko
>>
>>
>>
>>
>> InterComponentWare AG:
>> Vorstand: Peter Kirschbauer (Vors.), Jörg Stadler
>> Aufsichtsratsvors.: Prof. Dr. Christof Hettich
>> Firmensitz: 69190 Walldorf, Altrottstraße 31
>> AG Mannheim HRB 351761 / USt.-IdNr.: DE 198388516
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> CamelOne 2011: http://fusesource.com/camelone2011/
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>
>
>
>
>
>
>
> InterComponentWare AG:
> Vorstand: Peter Kirschbauer (Vors.), Jörg Stadler
> Aufsichtsratsvors.: Prof. Dr. Christof Hettich
> Firmensitz: 69190 Walldorf, Altrottstraße 31
> AG Mannheim HRB 351761 / USt.-IdNr.: DE 198388516
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: Consumer and Producer names in JMX
Posted by mi...@icw.de.
Hi Claus,
It's about the name that is shown in the JMX tree uner
org.apache.camel/consumers/context/consumerName (see the code snppet)
There is an endpoint uri attribute in the jmx objects, but it does not
help navigate. One has to expand the jmx Consumer/Producer objects to find
to which endpoint they belong.
Regards,
Mitko
From:
Claus Ibsen <cl...@gmail.com>
To:
dev@camel.apache.org
Date:
27.04.2011 16:17
Subject:
Re: Consumer and Producer names in JMX
They have an endpoint uri attribute.
On Wed, Apr 27, 2011 at 4:11 PM, <mi...@icw.de> wrote:
> Hello Camel devs,
>
> Currently the consumer and producer names in JMX have a name based on
> their java instance [1]. Due to this it is not obvious what is the
> endpoint of the consumers/producers.
>
> Would not it be better to use name based on endpoint URI of the
> consumer/producer endpoints (combined with identityHashcode) instead?
>
>
> [1] Copy/paste from the DefaultManagementNamingStrategy
>
> ...
> String name = consumer.getClass().getSimpleName();
> if (ObjectHelper.isEmpty(name)) {
> name = "Consumer";
> }
> buffer.append(KEY_NAME + "=")
> .append(name)
> .append("(").append(ObjectHelper.getIdentityHashCode
> (consumer)).append(")");
>
> ...
>
> Regards,
> Mitko
>
>
>
>
> InterComponentWare AG:
> Vorstand: Peter Kirschbauer (Vors.), Jörg Stadler
> Aufsichtsratsvors.: Prof. Dr. Christof Hettich
> Firmensitz: 69190 Walldorf, Altrottstraße 31
> AG Mannheim HRB 351761 / USt.-IdNr.: DE 198388516
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
InterComponentWare AG:
Vorstand: Peter Kirschbauer (Vors.), Jörg Stadler
Aufsichtsratsvors.: Prof. Dr. Christof Hettich
Firmensitz: 69190 Walldorf, Altrottstraße 31
AG Mannheim HRB 351761 / USt.-IdNr.: DE 198388516
Re: Consumer and Producer names in JMX
Posted by Claus Ibsen <cl...@gmail.com>.
They have an endpoint uri attribute.
On Wed, Apr 27, 2011 at 4:11 PM, <mi...@icw.de> wrote:
> Hello Camel devs,
>
> Currently the consumer and producer names in JMX have a name based on
> their java instance [1]. Due to this it is not obvious what is the
> endpoint of the consumers/producers.
>
> Would not it be better to use name based on endpoint URI of the
> consumer/producer endpoints (combined with identityHashcode) instead?
>
>
> [1] Copy/paste from the DefaultManagementNamingStrategy
>
> ...
> String name = consumer.getClass().getSimpleName();
> if (ObjectHelper.isEmpty(name)) {
> name = "Consumer";
> }
> buffer.append(KEY_NAME + "=")
> .append(name)
> .append("(").append(ObjectHelper.getIdentityHashCode
> (consumer)).append(")");
>
> ...
>
> Regards,
> Mitko
>
>
>
>
> InterComponentWare AG:
> Vorstand: Peter Kirschbauer (Vors.), Jörg Stadler
> Aufsichtsratsvors.: Prof. Dr. Christof Hettich
> Firmensitz: 69190 Walldorf, Altrottstraße 31
> AG Mannheim HRB 351761 / USt.-IdNr.: DE 198388516
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Consumer and Producer names in JMX
Posted by mi...@icw.de.
Hello Camel devs,
Currently the consumer and producer names in JMX have a name based on
their java instance [1]. Due to this it is not obvious what is the
endpoint of the consumers/producers.
Would not it be better to use name based on endpoint URI of the
consumer/producer endpoints (combined with identityHashcode) instead?
[1] Copy/paste from the DefaultManagementNamingStrategy
...
String name = consumer.getClass().getSimpleName();
if (ObjectHelper.isEmpty(name)) {
name = "Consumer";
}
buffer.append(KEY_NAME + "=")
.append(name)
.append("(").append(ObjectHelper.getIdentityHashCode
(consumer)).append(")");
...
Regards,
Mitko
��
InterComponentWare AG:
Vorstand: Peter Kirschbauer (Vors.), J�rg Stadler
Aufsichtsratsvors.: Prof. Dr. Christof Hettich
Firmensitz: 69190 Walldorf, Altrottstra�e 31
AG Mannheim HRB 351761 / USt.-IdNr.: DE 198388516