[proposal for a new component] lightweight clustered messagi
ivelin.ivanov Jun 5, 2003 1:04 AM
Since clustered JMS with load balancing will not be available until 4.0,
I would like to propose a relatively low cost alternative for 3.x.
Here is a use case and some sample code for the new component.
register an MBean MessageBroadcaster.
Pass partition name as one MBean attribute
another MBean attribute DeliveryPolicy will control Pub/Sub vs P2P
All MBeans with the same service name and partition name will connect to each other
subscribers will call addListener(SomeListener)
this will subscribe the listeners to the local broadcaster service
notifiers will call notifyListeners() to the local (in VM) instance of the service
the local instance will notify all local listeners as well as
all other broadcasters in the partition, via RPC call
each of the partition nodes will in turn call all their local listeners
pseudo code:
jboss:service=DefaultPartition
DefaultPartition
Broadcast | Point to Point
class Toaster
{
addListener(ToasterListener tl)
{
}
removeListener(tl) {...}
startToasting()
{
... do smth ...
getEventDispatcher().toastingStarted( time );
}
endToasting() {... similarly ...}
ToasterListener getEventDispatcher()
{
ClusteredEventDispatcher = jmxServer.findMBean( ... dispatcher mbean name ... );
ClusteredEventDispatcher.getDispatcherProxy( ToasterListener.class );
}
}
interface ToasterListener()
{
toastingStarted(long timestamp);
toastingStopped(long timestamp);
}
class ClusteredEventDispatcher extends MBeanSupport
{
startService()
{
}
// callback for remote rpc calls
_dispatchEvent( Method methodToCall, args )
{
... find proxy for the method's defining class
... call notifyLocalListeners on proxy
}
// there is only one proxy created per listener interface
getDispatcher( Class someListener)
{
... create new proxy for listener interface or return the old one if already created
}
class EventListenerProxy implements InvokationHandler
{
Object invoke(Object proxy, Method method, Object[] args)
{
List listeners = getLocaListeners(Method.getDeclaringClass());
notifyLocalListeners(method, args);
notifyRemoteListeners();
}
notifyLocalListeners(method, args)
{
... iterate and call method reflectively ...
}
notifyRemoteListeners(method, args)
{
rpcCall("service:DefaultPartitionEventDispatcher", "_dispatchEvent", Method, args);
}
}
} // end of EventDispatcherFactory
Cheers,
Ivelin