You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2008/09/17 03:07:44 UTC
svn commit: r696121 - in
/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version:
Bank.java BankResponseAggregationStrategy.java Client.java
CreditAgency.java LoanBroker.java
Author: ningjiang
Date: Tue Sep 16 18:07:43 2008
New Revision: 696121
URL: http://svn.apache.org/viewvc?rev=696121&view=rev
Log:
CAMEL-910 some code improvements which base on the suggestion of Claus
Modified:
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java
Modified: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java?rev=696121&r1=696120&r2=696121&view=diff
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java (original)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java Tue Sep 16 18:07:43 2008
@@ -34,8 +34,8 @@
}
public void process(Exchange exchange) throws Exception {
- String ssn = (String)exchange.getIn().getHeader(Constants.PROPERTY_SSN);
- Integer historyLength = (Integer) exchange.getIn().getHeader(Constants.PROPERTY_HISTORYLENGTH);
+ String ssn = exchange.getIn().getHeader(Constants.PROPERTY_SSN, String.class);
+ Integer historyLength = exchange.getIn().getHeader(Constants.PROPERTY_HISTORYLENGTH, Integer.class);
double rate = primeRate + (double)(historyLength / 12) / 10 + (double)(Math.random() * 10) / 10;
LOG.info("The bank: " + bankName + " for client: " + ssn + " 's rate " + rate);
exchange.getOut().setHeader(Constants.PROPERTY_RATE, new Double(rate));
Modified: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java?rev=696121&r1=696120&r2=696121&view=diff
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java (original)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java Tue Sep 16 18:07:43 2008
@@ -27,9 +27,9 @@
// Here we put the bank response together
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
LOG.debug("Get the exchange to aggregate, older: " + oldExchange + " newer:" + newExchange);
- Integer old = (Integer) oldExchange.getProperty("aggregated");
- Double oldRate = (Double) oldExchange.getIn().getHeader(Constants.PROPERTY_RATE);
- Double newRate = (Double) newExchange.getIn().getHeader(Constants.PROPERTY_RATE);
+ Integer old = oldExchange.getProperty("aggregated", Integer.class);
+ Double oldRate = oldExchange.getIn().getHeader(Constants.PROPERTY_RATE, Double.class);
+ Double newRate = newExchange.getIn().getHeader(Constants.PROPERTY_RATE, Double.class);
Exchange result = null;
if (old == null) {
old = 1;
Modified: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java?rev=696121&r1=696120&r2=696121&view=diff
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java (original)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java Tue Sep 16 18:07:43 2008
@@ -35,7 +35,7 @@
// Set up the ActiveMQ JMS Components
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
// Note we can explicit name of the component
- context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
+ context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new Client());
@@ -45,7 +45,7 @@
// START SNIPPET: sending
// send out the request message
for (int i = 0; i < 2; i++) {
- template.sendBodyAndHeader("test-jms:queue:loanRequestQueue",
+ template.sendBodyAndHeader("jms:queue:loanRequestQueue",
"Quote for the lowerst rate of loaning bank",
Constants.PROPERTY_SSN, "Client" + i);
Thread.sleep(100);
@@ -63,7 +63,7 @@
*/
public void configure() {
// START SNIPPET: pulling
- from("test-jms:queue:loanReplyQueue").process(new Processor() {
+ from("jms:queue:loanReplyQueue").process(new Processor() {
public void process(Exchange exchange) throws Exception {
// Print out the response message
Modified: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java?rev=696121&r1=696120&r2=696121&view=diff
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java (original)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java Tue Sep 16 18:07:43 2008
@@ -27,7 +27,7 @@
public void process(Exchange exchange) throws Exception {
LOG.info("Receiving credit agency request");
- String ssn = (String)exchange.getIn().getHeader(Constants.PROPERTY_SSN);
+ String ssn = exchange.getIn().getHeader(Constants.PROPERTY_SSN, String.class);
int score = (int) (Math.random() * 600 + 300);
int hlength = (int) (Math.random() * 19 + 1);
exchange.getOut().setHeader(Constants.PROPERTY_SCORE, new Integer(score));
Modified: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java?rev=696121&r1=696120&r2=696121&view=diff
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java (original)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java Tue Sep 16 18:07:43 2008
@@ -55,7 +55,7 @@
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
// Note we can explicitly name the component
- context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
+ context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new LoanBroker());
// Start the loan broker
@@ -76,27 +76,27 @@
public void configure() {
// START SNIPPET: dsl
// Put the message from loanRequestQueue to the creditRequestQueue
- from("test-jms:queue:loanRequestQueue").to("test-jms:queue:creditRequestQueue");
+ from("jms:queue:loanRequestQueue").to("jms:queue:creditRequestQueue");
// Now we can let the CreditAgency process the request, then the message will be put into creditResponseQueue
- from("test-jms:queue:creditRequestQueue").process(new CreditAgency()).to("test-jms:queue:creditResponseQueue");
+ from("jms:queue:creditRequestQueue").process(new CreditAgency()).to("jms:queue:creditResponseQueue");
// Here we use the multicast pattern to send the message to three different bank queue
- from("test-jms:queue:creditResponseQueue").multicast().to("test-jms:queue:bank1", "test-jms:queue:bank2", "test-jms:queue:bank3");
+ from("jms:queue:creditResponseQueue").multicast().to("jms:queue:bank1", "jms:queue:bank2", "jms:queue:bank3");
// Each bank processor will process the message and put the response message into the bankReplyQueue
- from("test-jms:queue:bank1").process(new Bank("bank1")).to("test-jms:queue:bankReplyQueue");
- from("test-jms:queue:bank2").process(new Bank("bank2")).to("test-jms:queue:bankReplyQueue");
- from("test-jms:queue:bank3").process(new Bank("bank3")).to("test-jms:queue:bankReplyQueue");
+ from("jms:queue:bank1").process(new Bank("bank1")).to("jms:queue:bankReplyQueue");
+ from("jms:queue:bank2").process(new Bank("bank2")).to("jms:queue:bankReplyQueue");
+ from("jms:queue:bank3").process(new Bank("bank3")).to("jms:queue:bankReplyQueue");
// Now we aggregating the response message by using the Constants.PROPERTY_SSN header
// The aggregation will completed when all the three bank responses are received
- from("test-jms:queue:bankReplyQueue")
+ from("jms:queue:bankReplyQueue")
.aggregator(header(Constants.PROPERTY_SSN), new BankResponseAggregationStrategy())
.completedPredicate(header("aggregated").isEqualTo(3))
// Here we do some translation and put the message back to loanReplyQueue
- .process(new Translator()).to("test-jms:queue:loanReplyQueue");
+ .process(new Translator()).to("jms:queue:loanReplyQueue");
// END SNIPPET: dsl
}