`CalculatorBean.java`
`01 package trail.mdb; 02 03 import javax.ejb.*; 04 import javax.jms.*; 05 import java.sql.Timestamp; 06 import java.util.StringTokenizer; 07 08 @MessageDriven(activationConfig = 09 { 10 @ActivationConfigProperty(propertyName="destinationType", 11 propertyValue="javax.jms.Queue"), 12 @ActivationConfigProperty(propertyName="destination", 13 propertyValue="queue/mdb") 14 }) 15 public class CalculatorBean implements MessageListener { 16 17 public void onMessage (Message msg) { 18 try { 19 TextMessage tmsg = (TextMessage) msg; 20 Timestamp sent = 21 new Timestamp(tmsg.getLongProperty("sent")); 22 StringTokenizer st = 23 new StringTokenizer(tmsg.getText(), ","); 24 25 int start = Integer.parseInt(st.nextToken()); 26 int end = Integer.parseInt(st.nextToken()); 27 double growthrate = Double.parseDouble(st.nextToken()); 28 double saving = Double.parseDouble(st.nextToken()); 29 30 // Pause to simulate a long running task 31 Thread.sleep(1000); 32 33 double result = 34 calculate (start, end, growthrate, saving); 35 RecordManager.addRecord (sent, result); 36 37 System.out.println ("The onMessage() is called"); 38 39 } catch (Exception e) { 40 e.printStackTrace (); 41 } 42 } 43 44 private double calculate (int start, int end, double growthrate, double saving) { 45 double tmp = Math.pow(1. + growthrate / 12., 12. * (end - start) + 1); 46 return saving * 12. * (tmp - 1) / growthrate; 47 } 48 49 }`