transaction.README.html Maven / Gradle / Ivy
Show all versions of gemfire-examples Show documentation
vFabric™ GemFire®
Transactions
Java Caching API Programming Example
The Transactions example uses two peer distributed system members to run transactional operations on two colocated partitioned regions. You can choose to run both members as data hosts for the regions, or you can run one member as an empty data accessor, with a single member hosting all of the data. Operations that are run on non-local data are proxied.
The example is located in the GemFire installation under examples/dist/transactions
.
The members connect as peers in a distributed system. The example uses 27267 as the mcast port. You can change this in the gemfire.properties
file in the transactions directory.
You can run a transaction on its own or within a function.
To run the example:
- Open two shells.
- In each shell, configure your environment according to the instructions provided in examples/EnvSetup.html.
- In each shell, change the current working directory to
examples/dist/transaction
.
- Start the members and follow the on-screen instructions to run transactional operations.
Running the members
One or both members can be started as a data host:
java transaction.TransactionalPeer
You can start a member as an empty data accessor:
java transaction.TransactionalPeer empty
The VM hosting the transactional data logs the changes made by the transaction using the LoggingCacheListener
Sample run: first VM
$ java transaction.TransactionalPeer
Please start the other VM and press enter to populate regions
Populating region...
Entry Created in region customer key: CustId: 0 value:customer_0
Entry Created in region order key:OrderId: 0 value:order_0
Entry Created in region customer key: CustId: 3 value:customer_3
Entry Created in region order key:OrderId: 3 value:order_3
Entry Created in region customer key: CustId: 4 value:customer_4
Entry Created in region order key:OrderId: 4 value:order_4
Complete
Press 1 to run a transaction, 2 to run a transactional function
1
Starting a transaction...
for customer region updating CustId: 1
for order region updating OrderId: 92
transaction completed
Press 1 to run a transaction, 2 to run a transactional function
2
Executing Function
Invoking Function
Function invocation completed
Press 1 to run a transaction, 2 to run a transactional function
Sample run: second VM
$ java transaction.TransactionalPeer
Please start the other VM and press enter to populate regions
Entry Created in region customer key: CustId: 1 value:customer_1
Entry Created in region order key:OrderId: 1 value:order_1
Entry Created in region customer key: CustId: 2 value:customer_2
Entry Created in region order key:OrderId: 2 value:order_2
Entry Updated in region customer key: CustId: 1 value:updatedCustomer_524
Entry Created in region order key:OrderId: 92 value:newOrder_524
Starting a transaction...
for customer region updating CustId: 7
for order region updating OrderId: 32
Entry Created in region customer key: CustId: 7 value:updatedCustomer_7_274
Entry Created in region order key:OrderId: 32 value:newOrder_32_274
transaction completed
To end the example, press CTRL-C
in the shells, then enter exit
in shells to close them.