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