Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

Annotated Declarative Transactions and Remoting

Hi,

I know there was a thread on this topic previously but I have been unable to find the resolution.

I'm struggling to find the magic code/configuration to make annotated transactions work with a remoted service. Shay suggested I post an example, so I am attaching the code and config for my PU and client. The pu.xml that I am posting activates spring tx: support explicitly. I have also tried it without including this, and gotten the same results.

The behavior I expect from the attached example is for a 10 second transaction to occur every time I run the client. During those 10 seconds I would expect the instance count in the space to reflect the insertion of the new object, but I would not expect to be able to see the new object in query results. I would also expect to see an active transaction in the space browser. Instead I am seeing the new object inserted and visible immediately, and no sign of a long-running transaction.

I would greatly appreciate it if someone could explain what I have done incorrectly and how to correct my error.

Many thanks.

-Dan

Edited by: Dan Stone on Feb 22, 2009 3:23 AM h4. Attachments

[pu.xml|/upfiles/13759711707314856.xml]

[stuff|/upfiles/13759711706124956.txt]

[TranDemo.java|/upfiles/13759711701488656.java]

[TranDemoClient.java|/upfiles/13759711701410856.java]

[TranDemoInterface.java|/upfiles/13759711704969857.java]

[pu.xml|/upfiles/13759711709311957.xml]

[stuff|/upfiles/13759711701075157.txt]

[TranDemo.java|/upfiles/13759711701939557.java]

[TranDemoClient.java|/upfiles/13759711707845057.java]

[TranDemoInterface.java|/upfiles/1375971170559957.java]

[pu.xml|/upfiles/13759711701543557.xml]

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=2896]{quote}

asked 2009-02-22 03:19:34 -0600

subuta gravatar image

updated 2013-08-08 09:52:00 -0600

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2009-02-22 04:44:58 -0600

uri gravatar image
edit flag offensive delete link more

Comments

Hi Uri,

That's weird. I'll upload the files again.

I have been looking at the doc, and I wonder whether the problem is that the client is not initiating a transaction.

-Dan h4. Attachments

[pu.xml|/upfiles/13759711704179397.xml]

[stuff|/upfiles/1375971170474097.txt]

[TranDemo.java|/upfiles/13759711701728797.java]

[TranDemoClient.java|/upfiles/13759711707504997.java]

[TranDemoInterface.java|/upfiles/13759711705085997.java]

subuta gravatar imagesubuta ( 2009-02-22 07:20:47 -0600 )edit

Hi Uri,

That's weird. I'll upload the files again.

I have been looking at the doc, and I wonder whether the problem is that the client is not initiating a transaction.

-Dan h4. Attachments

[pu.xml|/upfiles/13759711712088817.xml]

[stuff|/upfiles/13759711713962417.txt]

[TranDemo.java|/upfiles/13759711718614817.java]

[TranDemoClient.java|/upfiles/13759711718280517.java]

[TranDemoInterface.java|/upfiles/13759711717946617.java]

[pu.xml|/upfiles/13759711714466417.xml]

subuta gravatar imagesubuta ( 2009-02-22 07:23:35 -0600 )edit

Hi Dan

Your configuration looks ok. The reason you're seeing the object is that
the space browser uses dirty reads, so in fact it shows uncommitted
objects in the object count.
This is implemented that way for performance reason and to avoid any
locking of the space by the UI.
To make sure you are getting the desired behavior, do the following in
the TranDemo class:
1. Write an object to the space
2. Wait for x seconds
3. Throw a deliberate RuntimeException
In the UI, you should see the object count return to 0.
Alternatively, you can return normally and see that the object stays in
the space. To demonstrate atomicity, you can write more than one object
to the space and verify that either all instances are written or none at
all.

You can do it by changing the signature and implementation of the
TranDemo class as follows:

@Transactional (propagation = Propagation.REQUIRED)
public void doWork(int numInstances, boolean throwException) {
    for (int i=0; i<numInstances; i++) {
        gigaSpace.write(new Object());
    }
    try {
        System.out.println("\nSleeping inside a transaction (I
hope)");
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        System.out.println("\nAwakened while killing time");
    }
    if (throwException) {
        throw new RuntimeException();
    }
}
Uri

Attachments

  1. pu.xml
uri gravatar imageuri ( 2009-02-22 09:49:36 -0600 )edit

Hi Uri,

Thanks for the explanation and the advice. I'm not sure, though, that we have bottomed this out quite yet:

I am still struggling to understand why I can't see the transaction in progress during the sleep.

If I set propagation to mandatory I don't get a runtime error as promised by Spring.

When I throw an exception from within the service method the row that was just inserted does not disappear.

Taken together these points suggest that there is no transactionality. Please let me know what you think.

BTW, here is a link the other post I referred to that discusses this same topic: /[/question/4047/remoting-services-and-transactions/]

Here is my code as modified it to throw the exception.

-Dan

import org.openspaces.core.context.GigaSpaceContext; import org.openspaces.core.GigaSpace; import org.openspaces.remoting.RemotingService; import org.springframework.transaction.annotation.*;

@RemotingService public class TranDemo implements TranDemoInterface {

@GigaSpaceContext
private GigaSpace gigaSpace;

@Transactional (propagation = Propagation.MANDATORY)
public void doWork() {
    gigaSpace.write(new Object());

    try {
        System.out.println("\nSleeping inside a transaction (I hope)");
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        System.out.println("\nAwakened while killing time");
    }
    throw (new RuntimeException());
}

} h4. Attachments

[pu.xml|/upfiles/13759711718784965.xml]

subuta gravatar imagesubuta ( 2009-02-22 11:45:57 -0600 )edit

Hi Uri,

One additional point that I forgot to mention with regard to the browser and dirty reads. My experience with it has been that it shows changes in instance counts during transactions as you said, but I think that the query feature will not show the contents of a new entry until transaction commits. When using annotations, though, I can see the contents of the row during the sleep period. This is another piece of evidence that suggests that there is no transaction.

-Dan h4. Attachments

[pu.xml|/upfiles/13759711717673085.xml]

subuta gravatar imagesubuta ( 2009-02-22 12:03:31 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2009-02-22 03:19:34 -0600

Seen: 56 times

Last updated: Feb 22 '09