Announcement Announcement Module
Collapse
No announcement yet.
How can I use spring server side transactions over RMI? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I use spring server side transactions over RMI?

    Hi,

    I have following situation:
    I have Alfresco JCR as a server, and Jackrabbit JCR Api exposed over RMI to the client. (Alfresco is using spring+hibernate.) I need to implement transactions in client side. Or actually it's the server side where the transaction should really be, and I just need to start and commit it from client.

    There's some sample code from client side:
    ClientRepositoryFactory factory = new ClientRepositoryFactory();
    Repository repository = factory.getRepository(rmiUrl);
    SimpleCredentials credentials = new SimpleCredentials("admin", "admin".toCharArray());
    Session session = repository.login(credentials);

    /* this all needs to happen inside SAME transaction in server side: */
    RemoteTransactionService.beginTransaction(); // this kind of call could propably do the job
    Node rootNode = session.getRootNode(); // this results in some operations in server over rmi
    rootNode.doSomething(); // this results in some operations in server over rmi
    rootNode.doSomethingElse(); // this results in some operations in server over rmi
    RemoteTransactionService.commitTransaction(); // this kind of call could propably do the job
    So I kind of do *not* need distributed transactions, I believe, but a way to tell the server that 'all the operations made in these rmi calls need to happen in the same transaction there in the server'.

    I tested exporting begin/commit operations to the client over RMI just like in above sample code, but this does not work because rmi calls happen in different threads in server side, and the server side transaction (and hibernate session) is bound to thread.

    --
    Antti Salonen
    Team Leader / Quosis Ltd

  • #2
    I think it is better if you create a local and stateless service that coordinates the transaction. The service has method(s) for changing the state of your system, and every 'unit of work' has to be passed in a single call. To add remoting you wrap this local service in a new service that can be used for remoting and knows how to deal with remoting problems (using DTO`s for example to reduce the number of networks calls).

    You can expose this remote service to the client, and the client can call methods on it. But the service is responsible for transactionmanagement, not the client. This service makes it also clear to client which 'function' can be used: if isn`t in the service, it doesn`t exist. So you have complexe control on what is called by the client. It also makes the client less dependant on the internals of the server (try to imagine what happens if the internals of the server are refactored and your Node.doSomething() is renamed to Foo.doBar())

    What you are trying to do is to distribute your objects. Martin Fowlers first law of object distribution is: "don`t" :P
    Why? There is a big difference between local objects and distributed objects and you shouldn`t treat them the same.
    Last edited by Alarmnummer; Dec 20th, 2005, 06:10 AM.

    Comment

    Working...
    X