File: DefaultLoanBroker.java

package info (click to toggle)
mule 2.0.1-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 29,004 kB
  • ctags: 27,445
  • sloc: java: 154,840; xml: 32,157; sh: 941; jsp: 171; makefile: 30
file content (106 lines) | stat: -rw-r--r-- 3,374 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * $Id: DefaultLoanBroker.java 10789 2008-02-12 20:04:43Z dfeist $
 * --------------------------------------------------------------------------------------
 * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 *
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */

package org.mule.example.loanbroker;

import org.mule.example.loanbroker.messages.CreditProfile;
import org.mule.example.loanbroker.messages.Customer;
import org.mule.example.loanbroker.messages.CustomerQuoteRequest;
import org.mule.example.loanbroker.messages.LoanBrokerQuoteRequest;
import org.mule.example.loanbroker.messages.LoanQuote;

import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * <code>LoanBroker</code> is the Service that starts the loan request process. The
 * broker also receives the final quote.
 */
public class DefaultLoanBroker implements LoanBrokerService
{
    /**
     * logger used by this class
     */
    protected final Log logger = LogFactory.getLog(getClass());
    
    private final AtomicInteger quotes = new AtomicInteger(0);
    private final AtomicInteger requests = new AtomicInteger(0);
    private final AtomicInteger profiles = new AtomicInteger(0);

    public Object getLoanQuote(CustomerQuoteRequest request) throws LoanBrokerException
    {
        int requests = incRequests();
        if (logger.isInfoEnabled())
        {
            String[] params = new String[] { String.valueOf(requests), 
                request.getCustomer().getName(), 
                String.valueOf(request.getCustomer().getSsn()), 
                String.valueOf(request.getLoanAmount()),
                String.valueOf(request.getLoanDuration()) };

            logger.info("\n***** " + LocaleMessage.receivedRequest(params));
        }
        return request;
    }

    public LoanBrokerQuoteRequest receiveLoanBrokerQuoteRequest(LoanBrokerQuoteRequest request)
    {
        // Just pass through
        return request;
    }

    public Customer receiveCustomer(Customer customer)
    {
        // Just pass through
        return customer;
    }

    public Object receiveCreditProfile(CreditProfile profile)
    {
        int profiles = incProfiles();
        if (logger.isInfoEnabled())
        {
            String[] params = new String[] { String.valueOf(profiles), 
                String.valueOf(profile.getCreditScore()),
                String.valueOf(profile.getCreditHistory()) };

            logger.info("\n***** " + LocaleMessage.receivedProfile(params));
        }
        return profile;
    }

    public Object receiveQuote(LoanQuote quote)
    {
        int quotes = incQuotes();
        if (logger.isInfoEnabled())
        {
            String[] params = new String[] { String.valueOf(quotes), 
                quote.toString() };
            logger.info("\n***** " + LocaleMessage.receivedQuote(params));
        }
        return quote;
    }

    protected int incQuotes()
    {
        return quotes.incrementAndGet();
    }

    protected int incRequests()
    {
        return requests.incrementAndGet();
    }

    protected int incProfiles()
    {
        return profiles.incrementAndGet();
    }
}