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

Ask Your Question
0

How to perform take/takeMultiple operations transactionally from application outside of gigaspace?

We have two parts in our product one which runs as pu on gigaspaces and the other which runs as servlet application. The pu on gigaspace processes large amount of data and at the end of the processing it creates POJO type objects and puts them in on the space. The servlet application have thread/s which perform take/takeMultiple operation on gigaspace at certain interval of time. My question is how do we perform such operations transactionally from an application that is running outside of gigaspace. Untill now our code was using IJSpace interface was performing the operation as below;

import net.jini.core.transaction.Transaction;
import net.jini.core.transaction.TransactionFactory;
import net.jini.core.transaction.server.TransactionManager;
import org.openspaces.core.transaction.manager.DistributedJiniTransactionManager;
import org.openspaces.core.transaction.manager.DistributedJiniTxManagerConfigurer;
...
...
public void init(){
    IJSpace ijSpace = (IJSpace) new UrlSpaceConfigurer(spaceurl + "&FIFO&timeout=10000").space();
    TransactionManager _spaceTransactionManager = ((DistributedJiniTransactionManager) new DistributedJiniTxManagerConfigurer().transactionManager()).getTransactionManager();
    Transaction tx = TransactionFactory.create(_spaceTransactionManager, _transactionTimeoutSecs * 1000).transaction;
}

private void receiveMessage() throws Exception {
    try {
        while(msgsThisTxn < maxMsgPerTxn) {
            PojoObject pojo = null;
            try {
                pojo = (PojoObject) ijSpace.take(new PojoObject(),tx,10000);
            } catch (Exception e) {
                log.error("error occured aborting transaction");
                tx.abort();
            }
            handleMessage(pojo);
            tx.commit();
            msgsThisTxn ++;
        }
    } catch (Exception e) {
        log.error("error occured while handling the message. will try to abort transaction again");
        tx.abort();
    }
}

This worked as expected i.e. takingmaxMsgPerTxn objects from space in each transaction and committing or rolling back depending upon result of handleMessage() method. But now we are upgrading our code to use gigaspace interface but I do not understand how can I manage transactions in that situation as the take method of gigaspace interface do not take transaction as parameter. Our application already uses PlatformTransactionManager to do other processing in transaction so we are looking to update our code so that the take/takeMultiple operations are handled by spring's platformTransactionManager as-well. Can someone point me in the right direction as to how that can be achieved?

asked 2015-06-23 10:18:03 -0500

Setu Desai gravatar image

updated 2015-06-23 10:22:33 -0500

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

Setu

It's no so different; it's documented here:

http://docs.gigaspaces.com/xap101/tra...

You might want to review the whole page, but that section covers how to do it programmatically.

Hope this helps

John

answered 2015-06-23 11:43:14 -0500

jb gravatar image
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2015-06-23 10:18:03 -0500

Seen: 471 times

Last updated: Jun 23 '15