1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.examples.loanbroker; |
12 | |
|
13 | |
import org.mule.examples.loanbroker.messages.CreditProfile; |
14 | |
import org.mule.examples.loanbroker.messages.Customer; |
15 | |
import org.mule.examples.loanbroker.messages.CustomerQuoteRequest; |
16 | |
import org.mule.examples.loanbroker.messages.LoanBrokerQuoteRequest; |
17 | |
import org.mule.examples.loanbroker.messages.LoanQuote; |
18 | |
|
19 | |
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger; |
20 | |
import org.apache.commons.logging.Log; |
21 | |
import org.apache.commons.logging.LogFactory; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | 0 | public class DefaultLoanBroker implements LoanBrokerService |
28 | |
{ |
29 | |
|
30 | |
|
31 | |
|
32 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
33 | |
|
34 | 0 | private final AtomicInteger quotes = new AtomicInteger(0); |
35 | 0 | private final AtomicInteger requests = new AtomicInteger(0); |
36 | 0 | private final AtomicInteger profiles = new AtomicInteger(0); |
37 | |
|
38 | |
public Object getLoanQuote(CustomerQuoteRequest request) throws LoanBrokerException |
39 | |
{ |
40 | 0 | int requests = incRequests(); |
41 | 0 | if (logger.isInfoEnabled()) |
42 | |
{ |
43 | 0 | String[] params = new String[] { String.valueOf(requests), |
44 | |
request.getCustomer().getName(), |
45 | |
String.valueOf(request.getCustomer().getSsn()), |
46 | |
String.valueOf(request.getLoanAmount()), |
47 | |
String.valueOf(request.getLoanDuration()) }; |
48 | |
|
49 | 0 | logger.info("\n***** " + LocaleMessage.receivedRequest(params)); |
50 | |
} |
51 | 0 | return request; |
52 | |
} |
53 | |
|
54 | |
public LoanBrokerQuoteRequest receiveLoanBrokerQuoteRequest(LoanBrokerQuoteRequest request) |
55 | |
{ |
56 | |
|
57 | 0 | return request; |
58 | |
} |
59 | |
|
60 | |
public Customer receiveCustomer(Customer customer) |
61 | |
{ |
62 | |
|
63 | 0 | return customer; |
64 | |
} |
65 | |
|
66 | |
public Object receiveCreditProfile(CreditProfile profile) |
67 | |
{ |
68 | 0 | int profiles = incProfiles(); |
69 | 0 | if (logger.isInfoEnabled()) |
70 | |
{ |
71 | 0 | String[] params = new String[] { String.valueOf(profiles), |
72 | |
String.valueOf(profile.getCreditScore()), |
73 | |
String.valueOf(profile.getCreditHistory()) }; |
74 | |
|
75 | 0 | logger.info("\n***** " + LocaleMessage.receivedProfile(params)); |
76 | |
} |
77 | 0 | return profile; |
78 | |
} |
79 | |
|
80 | |
public Object receiveQuote(LoanQuote quote) |
81 | |
{ |
82 | 0 | int quotes = incQuotes(); |
83 | 0 | if (logger.isInfoEnabled()) |
84 | |
{ |
85 | 0 | String[] params = new String[] { String.valueOf(quotes), |
86 | |
quote.toString() }; |
87 | 0 | logger.info("\n***** " + LocaleMessage.receivedQuote(params)); |
88 | |
} |
89 | 0 | return quote; |
90 | |
} |
91 | |
|
92 | |
protected int incQuotes() |
93 | |
{ |
94 | 0 | return quotes.incrementAndGet(); |
95 | |
} |
96 | |
|
97 | |
protected int incRequests() |
98 | |
{ |
99 | 0 | return requests.incrementAndGet(); |
100 | |
} |
101 | |
|
102 | |
protected int incProfiles() |
103 | |
{ |
104 | 0 | return profiles.incrementAndGet(); |
105 | |
} |
106 | |
} |