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