Differences between revisions 1 and 2
Revision 1 as of 2005-08-03 13:06:17
Size: 2155
Editor: robortluo
Comment:
Revision 2 as of 2009-09-20 22:01:34
Size: 2155
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Problem

You want to access a remote service by RMI or web service transparently.

Idea

Obviously there should be a remoting implementation instead of normal local implementation of your service. However, we still need to write code to do real thing. Why reinvent wheels? There is a package named spring-remoting in spring framework, it handle this problem well, and the solution has been proved. Let's make it hivemind way!

Solution

First, a service point to provide service like usual:

    <service-point id="FinanceService" interface="mypackage.FinanceService"/>

Then, a remote implementation:

    <service-point id="rmiFinanceInterceptor" 
        interface="org.aopalliance.intercept.MethodInterceptor">
        <invoke-factory>
            <construct class="org.springframework.remoting.rmi.RmiClientInterceptor">
                <set property="serviceUrl" value="rmi://myserver:1399/financeService"/>
                <set-object property="serviceInterface"
                   value="class:mypackage.FinanceService"/>
            </construct>
        </invoke-factory>    
    </service-point>
    <implementation service-id="mypackage.FinanceService">
       <invoke-factory service-id="hivemind.lib.PlaceholderFactory"/>
       <interceptor service-id="hivemind.lib.MethodInterceptorFactory">
           <impl object="service:rmiFinanceInterceptor"/>
       </interceptor>
    </implementation>

That's it! The magic here is the hivemind.lib.MethodInterceptorFactory service, it opens the door to spring interceptors. In this way, we can even use spring transaction package to declare hivemind transactional service!

How about go further

Make a ServiceImplementationFactory (let's name it RMI!RemotingServiceFactory) to declare the service easier and cleaner, so we can do:

    <implementation service-id="mypackage.FinanceService">
        <invoke-factory service-id="hivemind.contrib.RMIRemotingServiceFactory">
            <remote url="rmi://myserver:1399/financeService"/>
        </invoke-factory>
    </implementation>

UsingSpringRemoting (last edited 2009-09-20 22:01:34 by localhost)