org.mule.extras.spring.events
Class MuleEventMulticaster

java.lang.Object
  extended byorg.mule.extras.spring.events.MuleEventMulticaster

public class MuleEventMulticaster
extends java.lang.Object

MuleEventMulticaster is an implementation of a Spring ApplicationeventMulticaster. This implementation allows Mule event to be sent and received through the Spring ApplicationContext. This allows any Spring bean to receive and send events from any transport that Mule supports such as Jms, Http, Tcp, Pop3, Smtp, File, etc. All a bean needs to do to receive and send events is to implement MuleEventListener. Beans can also have subscriptions to certain events by implementing MuleSubscriptionEventListener, where the bean can provide a list of endpoints on which to receive events i.e. <bean id="myListener" class="com.foo.MyListener"> <property name="subscriptions"> <list> <value>jms://customer.support</value> <value>pop3://support:123456@mail.mycompany.com</value> </list> </property> </bean>

Enpoints are specified as a Mule Url which is used to register a listener for the subscription In the pervious version of the MuleEventMulticaster it was possible to specify wildcard endpoints. This is still possible but you need to tell the multicaster which specific endpoints to listen on and then your subscription listeners can use wildcards. To register the specific endpoints on the Evnet Multicaster you use the subscriptions property.

<bean id="applicationEventMulticaster" class="org.mule.extras.spring.events.MuleEventMulticaster"> <property name="subscriptions"> <list> <value>jms://orders.queue</value> <value>jms://another.orders.queue</value> </list> </property> </bean>

<bean id="myListener" class="com.foo.MyListener"> <property name="subscriptions"> <list> <value>jms://*.orders.*.</value> </list> </property> </bean>

Version:
$Revision: 1.4 $
Author:
Ross Mason
See Also:
MuleEventListener, MuleSubscriptionEventListener, ApplicationEventMulticaster

Field Summary
static java.lang.String EVENT_MULTICASTER_DESCRIPTOR_NAME
           
protected static Log logger
          logger used by this class
 
Constructor Summary
MuleEventMulticaster()
           
 
Method Summary
 void addApplicationListener(ApplicationListener listener)
          Adds a listener to the the Multicaster.
protected  UMOFilter createFilter(java.lang.String pattern)
           
protected  void dispatchEvent(UMOEventContext eventContext, MuleApplicationEvent applicationEvent)
          Will dispatch an application event through Mule
protected  UMODescriptor getDefaultDescriptor()
           
 java.util.Map getEndpointMappings()
          Any logical endpointUri mappings to register with mule.
 java.lang.Class getSubscriptionFilter()
          the type of filter used to filter subscriptions
 java.lang.String[] getSubscriptions()
          A list of endpoints the eventMulticaster will receive events on Note that if this eventMulticaster has a Mule Descriptor associated with it, these endpoints are ignored and the ones on the Mule Descriptor are used.
protected  void initMule()
           
 boolean isAsynchronous()
          Determines whether events will be processed asynchronously
 void multicastEvent(ApplicationEvent e)
          Method is used to dispatch events to listeners registered with the EventManager or dispatches events to Mule depending on the type and state of the event received.
 void onMuleEvent(UMOEventContext context)
          This is the callback method used by Mule to give Mule events to this Multicaster
protected  void registerConnectors()
           
protected  void registerEndpointMappings()
           
protected  void registerMulticasterDescriptor()
           
protected  void registerTransformers()
           
 void removeAllListeners()
          Removes all the listeners from the multicaster
 void removeApplicationListener(ApplicationListener listener)
          Removes a listener from the multicaster
 void setApplicationContext(ApplicationContext applicationContext)
          Set the current Spring application context
 void setAsynchronous(boolean asynchronous)
          Determines whether events will be processed asynchronously
 void setEndpointMappings(java.util.Map endpointMappings)
          Any logical endpointUri mappings to register with mule.
 void setSubscriptionFilter(java.lang.Class subscriptionFilter)
          sets the type of filter used to filter subscriptions
 void setSubscriptions(java.lang.String[] subscriptions)
          A list of endpoints the eventMulticaster will receive events on Note that if this eventMulticaster has a Mule Descriptor associated with it, these endpoints are ignored and the ones on the Mule Descriptor are used.
protected  void setSubscriptionsOnDescriptor(MuleDescriptor descriptor)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EVENT_MULTICASTER_DESCRIPTOR_NAME

public static final java.lang.String EVENT_MULTICASTER_DESCRIPTOR_NAME
See Also:
Constant Field Values

logger

protected static transient Log logger
logger used by this class

Constructor Detail

MuleEventMulticaster

public MuleEventMulticaster()
Method Detail

addApplicationListener

public void addApplicationListener(ApplicationListener listener)
Adds a listener to the the Multicaster. If asynchronous is sset to true, an AsynchronousMessageListener is used to wrap the listener. This listener will be initialised with a threadpool. The configuration for the threadpool can be set on this multicaster of can be inherited from the MuleManager configuration, which good for most cases.

Parameters:
listener - the ApplicationListener to register with this Multicaster
See Also:
AsynchronousEventListener, ThreadingProfile

removeApplicationListener

public void removeApplicationListener(ApplicationListener listener)
Removes a listener from the multicaster

Parameters:
listener - the listener to remove

removeAllListeners

public void removeAllListeners()
Removes all the listeners from the multicaster


multicastEvent

public void multicastEvent(ApplicationEvent e)
Method is used to dispatch events to listeners registered with the EventManager or dispatches events to Mule depending on the type and state of the event received. If the event is not a Mule event it will be dispatched to any listeners registered that are NOT MuleEventListeners. If the event is a Mule event and there is no source event attached to it, it is assumed that the event was dispatched by an object in the context using context.publishEvent() and will be dispatched by Mule. If the event does have za source event attached to it, it is assumed that the event was dispatched by Mule and will be delivered to any listeners subscribed to the event.

Parameters:
e - the application event received by the context

isAsynchronous

public boolean isAsynchronous()
Determines whether events will be processed asynchronously

Returns:
tru if asynchronous. The default is false

setAsynchronous

public void setAsynchronous(boolean asynchronous)
Determines whether events will be processed asynchronously

Parameters:
asynchronous - true if aysnchronous

onMuleEvent

public void onMuleEvent(UMOEventContext context)
                 throws TransformerException,
                        MalformedEndpointException
This is the callback method used by Mule to give Mule events to this Multicaster

Parameters:
context - the context received by Mule
Throws:
TransformerException
MalformedEndpointException

dispatchEvent

protected void dispatchEvent(UMOEventContext eventContext,
                             MuleApplicationEvent applicationEvent)
                      throws ApplicationEventException
Will dispatch an application event through Mule

Parameters:
eventContext - the event received before dispatching
applicationEvent - the Spring event to be dispatched
Throws:
ApplicationEventException - if the event cannot be dispatched i.e. if the underlying transport throws an exception

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)
                           throws BeansException
Set the current Spring application context

Parameters:
applicationContext -
Throws:
BeansException

initMule

protected void initMule()

registerMulticasterDescriptor

protected void registerMulticasterDescriptor()
                                      throws UMOException
Throws:
UMOException

setSubscriptionsOnDescriptor

protected void setSubscriptionsOnDescriptor(MuleDescriptor descriptor)
                                     throws UMOException
Throws:
UMOException

registerEndpointMappings

protected void registerEndpointMappings()
                                 throws InitialisationException
Throws:
InitialisationException

registerConnectors

protected void registerConnectors()
                           throws UMOException
Throws:
UMOException

registerTransformers

protected void registerTransformers()
                             throws UMOException
Throws:
UMOException

getDefaultDescriptor

protected UMODescriptor getDefaultDescriptor()
                                      throws UMOException
Throws:
UMOException

createFilter

protected UMOFilter createFilter(java.lang.String pattern)

getSubscriptionFilter

public java.lang.Class getSubscriptionFilter()
the type of filter used to filter subscriptions

Returns:
the class of the filter to use. The default is WildcardFilter
See Also:
WildcardFilter

setSubscriptionFilter

public void setSubscriptionFilter(java.lang.Class subscriptionFilter)
sets the type of filter used to filter subscriptions

Parameters:
subscriptionFilter - the class of the filter to use.

getEndpointMappings

public java.util.Map getEndpointMappings()
Any logical endpointUri mappings to register with mule. These allow for friendly names to be used in place of urls i.e. email-orders -> smtp://orders:password@restaurant.com

Returns:
endpointMappings a map of logical names and endpoiut url strings

setEndpointMappings

public void setEndpointMappings(java.util.Map endpointMappings)
Any logical endpointUri mappings to register with mule. These allow for friendly names to be used in place of urls i.e. email-orders -> smtp://orders:password@restaurant.com

Parameters:
endpointMappings - a map of logical names and endpoiut url strings

getSubscriptions

public java.lang.String[] getSubscriptions()
A list of endpoints the eventMulticaster will receive events on Note that if this eventMulticaster has a Mule Descriptor associated with it, these endpoints are ignored and the ones on the Mule Descriptor are used. These are here for convenience, the event multicaster will use these to create a default MuleDescriptor for itself at runtime

Returns:
endpoints List being listened on

setSubscriptions

public void setSubscriptions(java.lang.String[] subscriptions)
A list of endpoints the eventMulticaster will receive events on Note that if this eventMulticaster has a Mule Descriptor associated with it, these endpoints are ignored and the ones on the Mule Descriptor are used. These are here for convenience, the event multicaster will use these to create a default MuleDescriptor for itself at runtime

Parameters:
subscriptions - a list of enpoints to listen on


Copyright © 2003-2005 SymphonySoft Limited. All Rights Reserved.