The Self-Conscious (Mule) Service
In the good old days of Mule 1.x, any component that wanted to be aware of its configured state could implement the UMODescriptor interface and get whatever information was needed. This interface is no longer available in Mule 2 but there is a org.mule.api.service.ServiceAware interface that can provide the same sort of information.
To investigate this interface, I constructed the following class:
public class ServiceAwareService implements ServiceAware { Service myService; public Service getService() { return myService; } public void setService(Service service) throws ConfigurationException { this.myService = service; } public String serviceDetails () { return myService.getModel().getName(); } }
I then crafted a simple Mule configuration file using the no-args entry point resolver:
<model name="noArgs"> <no-arguments-entry-point-resolver enableDiscovery="false" acceptVoidMethods="false"> <include-entry-point method="serviceDetails"/> </no-arguments-entry-point-resolver> <service name="My-Service-Aware-Service"> <inbound> <inbound-endpoint ref="forNoArgs"/> </inbound> <component class="com.ricston.tests.ServiceAwareService"/> </service> </model>
This Mule server will now return the name of the model if a MuleMessage is placed on the appropriate inbound endpoint. I found this to be rather interesting since it means that I could have a service that can report back on a number of useful titbits of information from within a live Mule server.
I could also ask it to do certain things but you do really need to think this through:
1 – I could invoke the pause() method to pause the service. This would work provided I have a control message that I can send the service. The problem is that I cannot send another message to resume the service since it is now paused.
2 – I can return the inbound, outbound and response router(s) configured. Not always useful as the service shouldn’t really know how the message will be/was routed.
3 – I can gain access to the model. This is useful in a few small set of cases; for instance, perhaps I want to change something about the model dynamically.
4 – I can also gain access to service statistics which would let me track what’s going on in the service at certain crucial points in time.

If you enjoyed this post, make sure you subscribe to my RSS feed!
Tags: control message, Service, ServiceAware
November 6th, 2009 at 10:13 AM
All of this is also possible via the Callable interface, wich is sort of the default interface for Mule components right?
November 6th, 2009 at 10:25 AM
Hello there,
The Callable interface is not a default interface at all; you don’t need to implement any interface in your components.
Furthermore, don’t forget that if you implement the Callable interface, any messages received by the component will be handled by the onCall () method which means that you miss out on the advantages of the entry-point resolvers. (See my other posts on this subject for more information)
However, if you do implement Callable, the answer to your question would be: Yes. You can extract this information from there too.
Thanks for reading
Antoine
February 15th, 2010 at 10:02 AM
[...] The Self-Consci … 11/02 [...]
February 25th, 2010 at 10:02 AM
[...] The Self-Consci … 11/02 [...]