KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > samples > loanbroker > AsyncLoanBroker


1 /*
2  * $Id: AsyncLoanBroker.java 4219 2006-12-09 10:15:14Z lajos $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.samples.loanbroker;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.samples.loanbroker.service.LoanBroker;
16
17 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
18
19 /**
20  * <code>LoanBroker</code> is the Service that starts the loan request process. The
21  * broker also receives the final quote.
22  */

23 public class AsyncLoanBroker implements LoanBroker
24 {
25     /**
26      * logger used by this class
27      */

28     protected static Log logger = LogFactory.getLog(AsyncLoanBroker.class);
29
30     private static final AtomicInteger quotes = new AtomicInteger(0);
31     private static final AtomicInteger requests = new AtomicInteger(0);
32
33     public AsyncLoanBroker()
34     {
35         super();
36     }
37
38     public BankQuoteRequest getLoanQuote(LoanRequest request)
39     {
40         logger.info("\nClient " + request.getCustomer().getName() + " with ssn= "
41                         + request.getCustomer().getSsn() + " requests a loan of amount= "
42                         + request.getLoanAmount() + " for " + request.getLoanDuration() + " months");
43         BankQuoteRequest bqr = new BankQuoteRequest();
44         bqr.setLoanRequest(request);
45         return bqr;
46     }
47
48     public Object JavaDoc receiveQuote(LoanQuote quote)
49     {
50         System.out.println("Quote " + incQuotes() + " received: " + quote);
51         return null;
52     }
53
54     public int incQuotes()
55     {
56         return quotes.incrementAndGet();
57     }
58
59     public int incRequests()
60     {
61         return requests.incrementAndGet();
62     }
63
64 }
65
Popular Tags