[mule-dev] How to dynamically add addtional config to started MuleContext without stop

17 views
Skip to first unread message

lf wen

unread,
Nov 24, 2011, 6:34:01 AM11/24/11
to d...@mule.codehaus.org
Hello all,

I'm using Mule3.1.2 and now I need to do the following:

I build a MuleContext like this:

ConfigurationBuilder builder = new SpringXmlConfigurationBuilder("mule-config-init.xml");
MuleContext muleContext = new DefaultMuleContextFactory().createMuleContext(builder);
muleContext.start();

and then I want to build another MuleContext in this similar way(of course we have other ways) yes using
a different configuration file. Also I want to "mix" this two MuleContext together without
shuting down the MuleContext that's already started which means I want to I have a single MuleContext
contains both the configuration content, so the "Element"(mainly endpoint using vm transport) in this
two configuration file can communicate with each other.

I've read the documentation abount DeployableMuleXmlContextListener and MuleXmlBuilderContextListener
but I can't get any conclusion(DeployableMuleXmlContextListener isn't work as documented).


Wish your response

Many thanks!

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Pablo Kraan

unread,
Nov 24, 2011, 8:26:52 AM11/24/11
to d...@mule.codehaus.org
Not sure if is useful in your case, but you can pass multiple configuration files to the SpringXmlConfigurationBuilder constructor, so you will end with a single mule context without having to manually do the merge

Pablo

lf wen

unread,
Nov 25, 2011, 4:25:17 AM11/25/11
to d...@mule.codehaus.org
Hi, Pablo

thanks for your reply.

I do write my test program as you described and get a single MuleContext with mutiple configuration. However, I my case, I need to dynamiclly add configs(after some GUI operation) to the running mule context without stop it. Go after your way, I wirte my second test program as following:

ConfigurationBuilder builder = new SpringXmlConfigurationBuilder("mule-config1.xml");


MuleContext muleContext = new DefaultMuleContextFactory().createMuleContext(builder);

muleContext.start();

ConfigurationBuilder builder = new SpringXmlConfigurationBuilder("mule-config2.xml");
builder.configure(muleContext);
System.out.println("successfully add new config to mule context...");

and then I get exceptions like this: (DynamicAddEndpoint.java is my test class name) at line: ++builder.configure(muleContext);++
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
java.lang.IllegalStateException: Already in lifecycle phase 'start', cannot fire the same phase twice
at org.mule.lifecycle.AbstractLifecycleManager.checkPhase(AbstractLifecycleManager.java:106)
at org.mule.lifecycle.MuleContextLifecycleManager.fireLifecycle(MuleContextLifecycleManager.java:63)
at org.mule.config.spring.SpringXmlConfigurationBuilder.applyLifecycle(SpringXmlConfigurationBuilder.java:125)
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:48)
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)
at test2.DynamicAddEndpoint.addMuleConfig(DynamicAddEndpoint.java:124)
at test2.DynamicAddEndpoint.main(DynamicAddEndpoint.java:38)
Exception in thread "main" org.mule.api.config.ConfigurationException: Already in lifecycle phase 'start', cannot fire the same phase twice (java.lang.IllegalStateException)
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:54)
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)
at test2.DynamicAddEndpoint.addMuleConfig(DynamicAddEndpoint.java:124)
at test2.DynamicAddEndpoint.main(DynamicAddEndpoint.java:38)
Caused by: java.lang.IllegalStateException: Already in lifecycle phase 'start', cannot fire the same phase twice
at org.mule.lifecycle.AbstractLifecycleManager.checkPhase(AbstractLifecycleManager.java:106)
at org.mule.lifecycle.MuleContextLifecycleManager.fireLifecycle(MuleContextLifecycleManager.java:63)
at org.mule.config.spring.SpringXmlConfigurationBuilder.applyLifecycle(SpringXmlConfigurationBuilder.java:125)
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:48)
... 3 more

this seems much like the excetion stack while I test the DeployableMuleXmlContextListener which also tells me
{Already in lifecycle phase 'start', cannot fire the same phase twice}

……

Pablo Kraan

unread,
Nov 25, 2011, 5:27:50 AM11/25/11
to d...@mule.codehaus.org
As far as I know, you cannot modify the context once is started.

You have two requirements: merging multiple contexts into one and adding new configs to the context dynamically.
Maybe you can provide more detail one your scenario, but if you relax the first requirement, then you can have multiple mule 3 apps running inside the same mule instance. Mule 3 apps can be created and deployed dynamically with out the need to stop the mule instance (just need to copy the new app.zip into the apps folder).

Pablo

lf wen

unread,
Nov 27, 2011, 9:29:22 AM11/27/11
to d...@mule.codehaus.org
Hello, Pablo

thanks again

I my case, what I want is concretely like this: I'm now trying to build an app, it alows people to manually desgin the message flow, some what looks like Mule Studio do,
but very rough. People can desgin the message processing flow and save it. Then my program will transfer this "save xml" to the mule format and give it a unique id. At the beginning of this transfer, I will add an endpoint to this flow which looks like this: http://ip:8080/serivces/http/flowId, the flowId in it is response to the unique id I mentioned above. What's more, people can start and stop this flow after they build it. At present, I achieve this by starting a MuleContext every time people start a flow(use mulecontex.start/stop). I know this will cause at least one problem: not enough ports for every inbound endpoint, because in difference mule context, I cant't share one port for two inbound endpoint and I need to set different inbound port for different flow in different mule config file. For example, we can easily write follwing configs in a mule-config.xml:
<flow name="f1">
<http:inbound-endpoint address="http://localhost:8090/flow1"></http:inbound-endpoint>
<component class="com.test.Component1" />
</flow>

<flow name="f2">
<http:inbound-endpoint address="http://localhost:8090/flow2"></http:inbound-endpoint>
<component class="com.test.Component2" />
</flow>
and when we request different url, we can get different response as we expected.

but when it's divided into two mule configuration file each contains one seprate flow like this:
++mule-config1.xml++
<flow name="f1">
<http:inbound-endpoint address="http://localhost:8090/flow1"></http:inbound-endpoint>
<component class="com.test.Component1" />
</flow>
++mule-config2.xml++
<flow name="f2">
<http:inbound-endpoint address="http://localhost:8090/flow2"></http:inbound-endpoint>
<component class="com.test.Component2" />
</flow>

Then, after we start both of them, we can only ask for one flow and another will tell us something error like this:
+++Cannot bind to address "http://localhost:8090/flow2" No component registered on that endpoint+++

maybe sometimes we can see both of them works well, but it's very occasionally and of course this's not what we want.

So, I want to merge them together. After people start flow1, the mule context starts, and when people start flow2, we can dynamically add flow2's config to the running mule context without stopping it. Then the inbound endpoints in this two configs can share the same port.

Reply all
Reply to author
Forward
0 new messages