O'Reilly - Java Message Service
O'Reilly - Java Message Service
O'Reilly - Java Message Service
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
}<br />
return;<br />
session.commit();<br />
}<br />
else if ( rollbackOnly ){<br />
inRollback = true;<br />
session.rollback( );<br />
}<br />
else<br />
session.commit( );<br />
}<br />
if ( rollbackOnly )<br />
return; // Ignore all other messages while in rollback mode<br />
...<br />
// If price reduction is greater than 10 percent, buy<br />
if (newPrice == 0 || oldPrice / newPrice > 1.1){<br />
System.out.println ("\nBuying " + count + " " + itemDesc);<br />
...<br />
publisher.publish(<br />
buyTopic,<br />
textMsg,<br />
javax.jms.DeliveryMode.PERSISTENT,<br />
javax.jms.<strong>Message</strong>.DEFAULT_PRIORITY,<br />
1800000);<br />
} else {<br />
System.out.println ("\nBad Deal. Not buying");<br />
rollbackOnly = true;<br />
}<br />
First we will examine what makes the rollback happen:<br />
// If price reduction is greater than 10 percent, buy<br />
if (newPrice == 0 || oldPrice / newPrice > 1.1){<br />
...<br />
} else {<br />
System.out.println ("\nBad Deal. Not buying");<br />
rollbackOnly = true;<br />
}<br />
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
The rollbackOnly variable is a boolean used by the application to signal that a rollback<br />
needs to occur. If you are familiar with the EJB transaction model, this is similar to calling<br />
the setRollbackOnly( ) method on an EJB entity bean. The messages in the transaction are<br />
either all commited, or they are all rolled back. Setting the rollback-only flag indicates a<br />
deferred rollback. The processing of any message in the group can set the rollbackOnly<br />
flag. Since the "Buy Order" messages are all part of the same transaction, they will be<br />
retained by the JMS provider and will go no further. When the "END_SEQUENCE" message<br />
arrives, the rollbackOnly flag is examined:<br />
if ( sequence.equalsIgnoreCase("END_SEQUENCE") )<br />
{<br />
if ( redelivered && inRollback ){ // at the end, start fresh<br />
inRollback = false;<br />
rollbackOnly = false;<br />
session.commit();<br />
}<br />
else if ( rollbackOnly ){<br />
inRollback = true;<br />
session.rollback( );<br />
}<br />
else<br />
session.commit( );<br />
}<br />
return;<br />
100