How do I implement a listener pattern over RMI using Spring?

Posted by predhme on Stack Overflow See other posts from Stack Overflow or by predhme
Published on 2010-04-21T17:35:50Z Indexed on 2010/04/21 20:13 UTC
Read the original article Hit count: 278

Filed under:
|
|

So here is a generalized version of our application desgin:

@Controller
public class MyController {

    @Autowired
    private MyServiceInterface myServiceInterface;

    @RequestMapping("/myURL")
    public @ResponseBody String doSomething() {
        MyListenerInterface listener = new MyListenerInterfaceImpl();

        myServiceInterface.doThenCallListener(listener);

        // do post stuff
    }
}

public interface MyListenerInterface {
    public void callA();
    public void callB();    
}

public class MyListenerInterfaceImpl implements MyListenerInterface {
    // ... omitted for clarity
}

public interface MyServiceInterface {
    public void doThenCallListener(MyListenerInterface listener);
}

public class MyServiceImpl {
    public void doThenCallListener(MyListenerInterface listener) {
        // do stuff
        listener.callA();
    }
}

Basically I have a controller that is being called via AJAX in which I am looking to return a response as a string. However, I need to make a call to the backend (MyServiceInterface). That guy is exposed through RMI by using Spring (man that was easy). But the service method as described requires a listener to be registered for invokation completion purposes.

So what I assume I need to achieve is transparently to the backend make it so that when the listener methods are called, really the call is going over RMI.

I would have thought Spring would have a simple way to wrap a POJO (not a service singleton) with RMI calls. I looked through their documentation but they had nothing besides exposing services via RMI. Could someone point me in the right direction?

© Stack Overflow or respective owner

Related posts about java

Related posts about rmi