Summary: OpenSpaces provides several implementations of Spring's
PlatformTransactionManager allowing you to use the GigaSpaces and Jini Transaction Manager.
OverviewSpring Framework provides a transaction manager abstraction using the PlatformTransactionManager interface with several different built-in implementations, such as JDBC Data Source and JTA. OpenSpaces provides several implementations of Spring's PlatformTransactionManager, allowing you to use the GigaSpaces and Jini Transaction Manager. By implementing Spring's PlatformTransactionManager, OpenSpaces users can utilize Spring's rich support for declarative transaction management. Declarative transaction management can be easily utilized using the GigaSpace simplified space API.
OpenSpaces supports several transaction managers, and changing a Transaction Manager to work with is just a matter of changing the Transaction Manager implementation.
Local Jini Transaction ManagerGigaSpaces' built-in, high-performance, single space Local Transaction Manager can be easily defined using OpenSpaces (and then utilized using GigaSpace).
Here is an example of how this can be defined in a Spring application context:
Namespace
<os-core:space id="space" url="/./space" /> <os-core:local-tx-manager id="transactionManager" space="space"/> <os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager"/> Plain XML <bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean"> <property name="url" value="/./space" /> </bean> <bean id="transactionManager" class="org.openspaces.core.transaction.manager.LocalJiniTransactionManager"> <property name="space" ref="space" /> </bean> <bean id="gigaSpace" class="org.openspaces.core.GigaSpaceFactoryBean"> <property name="space" ref="space" /> <property name="transactionManager" ref="transactionManager" /> </bean> Code IJSpace space = new UrlSpaceConfigurer("/./space").space(); PlatformTransactionManager ptm = new LocalJiniTxManagerConfigurer(space).transactionManager(); GigaSpace gigaSpace = new GigaSpaceConfigurer(space).transactionManager(ptm).gigaSpace(); When defining a local transaction manager, the Space bean is used as a transactional context and an IJSpace provider (the GigaSpaces Local Transaction Manager requires it). The LocalJiniTransactionManager is an implementation of the Spring PlatformTransactionManager, allowing Spring's transaction support to be used with OpenSpaces. Timeout ValuesThe local transaction manager allows to set the default timeout value for transactions. A timeout value is used when a transaction is not committed/rolled back (for example due to JVM exit) to control when the transaction will be discarded. By default the timeout value is 60 seconds and is set in seconds. Controlling the timeout value can be done using:
Namespace
<os-core:space id="space" url="/./space" /> <os-core:local-tx-manager id="transactionManager" space="space" default-timeout="1000"/> <os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager"/> Plain XML <bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean"> <property name="url" value="/./space" /> </bean> <bean id="transactionManager" class="org.openspaces.core.transaction.manager.LocalJiniTransactionManager"> <property name="space" ref="space" /> <property name="defaultTimeout" value="1000" /> </bean> <bean id="gigaSpace" class="org.openspaces.core.GigaSpaceFactoryBean"> <property name="space" ref="space" /> <property name="transactionManager" ref="transactionManager" /> </bean> Code IJSpace space = new UrlSpaceConfigurer("/./space").space(); PlatformTransactionManager ptm = new LocalJiniTxManagerConfigurer(space).defaultTimeout(1000).transactionManager(); GigaSpace gigaSpace = new GigaSpaceConfigurer(space).transactionManager(ptm).gigaSpace();
When using Jini based transactions, a timeout value can be set for both the commit and abort operations. This values can also be set on the transaction manager. Distributed Jini Transaction ManagerThe distributed Jini Transaction Manager starts an embedded distributed (mahalo) Jini Transaction Manager, which is then wrapped with an implementation of the Spring PlatformTransactionManager. This transaction manager is usually used in order to perform distributed transactions spanning multiple space instances. Below is an example of how it can be defined in a Spring application context:
Namespace
<os-core:space id="space" url="/./space" /> <os-core:distributed-tx-manager id="transactionManager" /> <os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager" /> Plain XML <bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean"> <property name="url" value="/./space" /> </bean> <bean id="transactionManager" class="org.openspaces.core.transaction.manager.DistributedJiniTransactionManager" /> <bean id="gigaSpace" class="org.openspaces.core.GigaSpaceFactoryBean"> <property name="space" ref="space" /> <property name="transactionManager" ref="transactionManager" /> </bean> Code IJSpace space = new UrlSpaceConfigurer("/./space").space(); PlatformTransactionManager ptm = new DistributedJiniTxManagerConfigurer().transactionManager(); GigaSpace gigaSpace = new GigaSpaceConfigurer(space).transactionManager(ptm).gigaSpace(); Timeout ValuesThe Jini distributed (mahalo) transaction manager allows to set the default timeout value for transactions. A timeout value is used when a transaction is not committed/rolled back (for example due to JVM exit) to control when the transaction will be discarded. By default the timeout value is 60 Sec and is set in seconds. Controlling the timeout value can be done using:
Namespace
<os-core:space id="space" url="/./space" /> <os-core:distributed-tx-manager id="transactionManager" default-timeout="1000"/> <os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager"/> Plain XML <bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean"> <property name="url" value="/./space" /> </bean> <bean id="transactionManager" class="org.openspaces.core.transaction.manager.DistributedJiniTransactionManager"> <property name="defaultTimeout" value="1000" /> </bean> <bean id="gigaSpace" class="org.openspaces.core.GigaSpaceFactoryBean"> <property name="space" ref="space" /> <property name="transactionManager" ref="transactionManager" /> </bean> Code IJSpace space = new UrlSpaceConfigurer("/./space").space(); PlatformTransactionManager ptm = new DistributedJiniTxManagerConfigurer().defaultTimeout(1000).transactionManager(); GigaSpace gigaSpace = new GigaSpaceConfigurer(space).transactionManager(ptm).gigaSpace();
When using Jini based transactions, a timeout value can be set for both the commit and abort operations. This values can also be set on the transaction manager. Lookup Jini Transaction ManagerThe lookup Jini Transaction Manager allows you to use the Jini lookup mechanism in order to lookup a Jini Transaction Manager, which is then wrapped with an implementation of the Spring PlatformTransactionManager. This transaction manager is usually used in order to obtain a remote Jini Mahalo transaction manager for distributed transactions spanning multiple spaces. Below is an example of how it can be defined in a Spring application context:
Namespace
<os-core:space id="space" url="/./space" /> <os-core:jini-tx-manager id="transactionManager" lookup-timeout="5000" /> <os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager" /> Plain XML <bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean"> <property name="url" value="/./space" /> </bean> <bean id="transactionManager" class="org.openspaces.core.transaction.manager.LookupJiniTransactionManager"> <property name="lookupTimeout" value="5000" /> </bean> <bean id="gigaSpace" class="org.openspaces.core.GigaSpaceFactoryBean"> <property name="space" ref="space" /> <property name="transactionManager" ref="transactionManager" /> </bean> Code IJSpace space = new UrlSpaceConfigurer("/./space").space(); PlatformTransactionManager ptm = new LookupJiniTxManagerConfigurer().lookupTimeout(5000).transactionManager(); GigaSpace gigaSpace = new GigaSpaceConfigurer(space).transactionManager(ptm).gigaSpace(); Timeout ValuesThe Jini lookup transaction manager allows to set the default timeout value for transactions. A timeout value is used when a transaction is not committed/rolled back (for example due to JVM exit) to control when the transaction will be discarded. By default the timeout value is 60 Sec and is set in seconds. Controlling the timeout value can be done using:
Namespace
<os-core:space id="space" url="/./space" /> <os-core:jini-tx-manager id="transactionManager" default-timeout="1000"/> <os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager"/> Plain XML <bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean"> <property name="url" value="/./space" /> </bean> <bean id="transactionManager" class="org.openspaces.core.transaction.manager.LookupJiniTransactionManager"> <property name="defaultTimeout" value="1000" /> </bean> <bean id="gigaSpace" class="org.openspaces.core.GigaSpaceFactoryBean"> <property name="space" ref="space" /> <property name="transactionManager" ref="transactionManager" /> </bean> Code IJSpace space = new UrlSpaceConfigurer("/./space").space(); PlatformTransactionManager ptm = new LookupJiniTxManagerConfigurer().defaultTimeout(1000).transactionManager(); GigaSpace gigaSpace = new GigaSpaceConfigurer(space).transactionManager(ptm).gigaSpace();
When using Jini based transactions, a timeout value can be set for both the commit and abort operations. This values can also be set on the transaction manager. Renewing TransactionsBoth Local and Jini transactions allow you to configure automatic renewing of ongoing transactions. This feature is very handy when wanting to configure a long transaction timeout, and have it expire earlier in case of a complete failure (for example, JVM crash). Expiring the transaction is important so Entries held under a transaction lock are released as soon as possible. Here is an example of how this can be configured:
Namespace
<os-core:space id="space" url="/./space" /> <os-core:local-tx-manager id="transactionManager" space="space"> <os-core:renew pool-size="2" duration="1000" round-trip-time="500" /> </os-core:local-tx-manager> <os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager"/> Plain XML <bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean"> <property name="url" value="/./space" /> </bean> <bean id="transactionManager" class="org.openspaces.core.transaction.manager.LocalJiniTransactionManager"> <property name="space" ref="space" /> <property name="leaseRenewalConfig"> <bean class="org.openspaces.core.transaction.manager.TransactionLeaseRenewalConfig"> <property name="poolSize" value="2" /> <proeprty name="renewRTT" value="500" /> <property name="renewDuration" value="1000" /> </bean> </property> </bean> <bean id="gigaSpace" class="org.openspaces.core.GigaSpaceFactoryBean"> <property name="space" ref="space" /> <property name="transactionManager" ref="transactionManager" /> </bean> Code IJSpace space = new UrlSpaceConfigurer("/./space").space(); TransactionLeaseRenewalConfig config = new TransactionLeaseRenewalConfig(); config.setPoolSize(2); config.setRenewDuration(1000); config.setRenewRTT(500); PlatformTransactionManager ptm = new LocalJiniTxManagerConfigurer(space).leaseRenewalConfig(config).transactionManager(); GigaSpace gigaSpace = new GigaSpaceConfigurer(space).transactionManager(ptm).gigaSpace(); The above configuration creates a Local Transaction Manager with a pool of 2 transaction (lease) renewal managers (a single manager can handle multiple transactions, more managers allow for better concurrency). Each transaction is renewed every 1 second (1000 milliseconds) with an expected round trip time of 500 milliseconds. This means that a transaction with a timeout of 10 seconds is renewed 10 times (approximately) and if the JVM crashes, the transaction expires within a second (at most). XA/JTA SupportGigaSpaces can be used within a XA transaction using JTA. OpenSpaces allows you to work with Spring's JTATransactionManager and provides support for declarative transaction management. Here is an example of how OpenSpaces JTA support can be used (using JOTM):
Namespace
<os-core:space id="space" url="/./space" /> <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" /> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="userTransaction" ref="jotm" /> </bean> <os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager" /> Plain XML <bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean"> <property name="url" value="/./space" /> </bean> <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" /> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="userTransaction" ref="jotm" /> </bean> <bean id="gigaSpace" class="org.openspaces.core.GigaSpaceFactoryBean"> <property name="space" ref="space" /> <property name="transactionManager" ref="transactionManager" /> </bean> Code UserTransaction userTransaction = ... //get UserTransaction via JDNI / instantiation PlatformTransactionManager ptm = new JtaTransactionManager(userTransaction); IJSpace space = new UrlSpaceConfigurer("/./space").space(); GigaSpace gigaSpace = new GigaSpaceConfigurer(space).transactionManager(ptm).gig
A Note about Programmatic Transaction ManagementIf you don't want to leverage Spring's declarative transaction management, or have an application that is not configured by Spring, you can start, commit and rollback transactions explicitly from within your code by using Spring's transaction API. GigaSpace gigaSpace = ...//get reference to a GigaSpace instance PlatformTransactionManager ptm = ... //get reference to a GigaSpaces PlatformTransactionManager instance DefaultTransactionDefinition definition = new DefaultTransactionDefinition(); //configure the definition... TransactionStatus status = ptm.getTransaction(definition); try { //do things with gigaSpace... } catch (MyException e) { ptm.rollback(status); throw e; } ptm.commit(status); You can also use Spring's TransactionTemplate if you prefer. This is documented in full in the Spring reference guide. |
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |