Recently, there was a great question on one of the Mule mailing lists about where to store runtime data that can be used across the app. If you need to store runtime data that is available across your Mule application, you can store the data as objects in the Mule Registry. You can get a handle to the Registry from anywhere that you have access to the MuleContext, as in most Mule entities. For example, you could store the object as follows:
muleContext.getRegistry().registerObject(<span class="code-quote">"foo"</span>, new MyFoo());
You could then update the object from somewhere else:
Foo foo = (Foo) muleContext.getRegistry().lookupObject(<span class="code-quote">"foo"</span>); foo.setBarVal(25); // Replace the previous object muleContext.getRegistry().registerObject(<span class="code-quote">"foo"</span>, foo);
This approach is useful for storing objects such as routers that are needed by multiple components across your application.
I’ve added this info to the Mule User Guide for easy reference in the future. Thanks to Travis and Andrew for the info.