[infinispan-dev] MyRpcDispatcher

Brian Stansberry brian.stansberry at redhat.com
Fri Apr 9 18:45:17 EDT 2010


On 04/09/2010 02:59 PM, Paul Ferraro wrote:
> I've modified Bela's existing sample code to address the issues Brian
> and I discussed below.

Thanks!

Here's a summary of the changes:
>
> * Refactored pieces into separate classes with nicer names
> * ScopedRpcDispatcher registers its scope with a ScopedUpHandler
> * Added ScopeUpHandler deregistration on ScopedRpcDispatcher.stop().
> * ScopedUpHandler accepts an optional default handler, which will be
> triggered for non-message events or messages with no scope header
> * ScopedUpHandler returns NoHandlerForScope object if message is
> received for an unknown scope (e.g. its handler was not yet registered
> or was already deregistered)
> * Automatically adds RspFilter to RequestOptions that rejects
> NoHandlerForScope responses, decorating any existing filter, if
> necessary.
> * Added ScopedMessageDispatcher analogue
>
> So, usage would look like:
>

The following is problematic because it requires passing around refs to 
'h' through independent libraries that don't expose an appropriate API.

> Channel c = new JChannel(...);
>
> ScopedUpHandler h = new ScopedUpHandlerImpl();
>
> ScopedRpcDispatcher d1 = new ScopedRpcDispatcher((short)1, h, c, null, null, target1);

^^^ done by whatever service (e.g. web session manager) that wants to 
send use Infinispan and send RPCs over the same Channel

> ScopedRpcDispatcher d2 = new ScopedRpcDispatcher((short)2, h, c, null, null, target2);
>

^^^^ done by Infinispan, which has an API to pass in a ref to a Channel 
but there's no API to pass in a ScopedUpHandler.

> // This must be set after all rpc dispatchers are created
> c.setUpHandler(h);

^^^ done by whatever service (e.g. web session manager) that wants to 
send RPCs over the same Channel

> c.connect(...);

^^^^ done by Infinispan

>

It's cleaner if it can be:

Channel c = new JChannel(...);
ScopedUpHandler h = new ScopedUpHandlerImpl();
c.setUpHandler(h);
ScopedRpcDispatcher d1 = new ScopedRpcDispatcher((short)1, c, null, 
null, target1); // note no "h" param

^^^ done by whatever service (e.g. web session manager) that wants to 
send RPCs over the same Channel

ScopedRpcDispatcher d2 = new ScopedRpcDispatcher((short)2, c, null, 
null, target2);
c.connect(...);

^^^^ done by Infinispan, which has an API to pass in a ref to a Channel

The problem is MessageDispatcher calls channel.setUpHandler() in its 
constructor.

>
> This will also work in conjunction with a standard rpc dispatcher:
>
> Channel c = new JChannel(...);
>
> RpcDispatcher d = new RpcDispatcher(c, null, null, target);
> ScopedUpHandler h = new ScopedUpHandlerImpl(d.getProtocolAdapter());
>
> ScopedRpcDispatcher d1 = new ScopedRpcDispatcher((short)1, h, c, null, null, target1);
> ScopedRpcDispatcher d2 = new ScopedRpcDispatcher((short)2, h, c, null, null, target2);
>
> c.setUpHandler(h);
> c.connect(...);
>
>
> I've attached the changes in the form of a patch to JGRP-1177.
> Comments are welcome.
>
> Paul
>



-- 
Brian Stansberry
Lead, AS Clustering
JBoss by Red Hat



More information about the infinispan-dev mailing list