Author: ningjiang
Date: Fri Jun  6 03:00:37 2008
New Revision: 663875

URL: http://svn.apache.org/viewvc?rev=663875&view=rev
Log:
Add the snippet tags for wiki page

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/Constants.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
    
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java
    
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties

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=663875&r1=663874&r2=663875&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
 Fri Jun  6 03:00:37 2008
@@ -22,6 +22,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+//START SNIPPET: bank
 public class Bank implements Processor {
     private static final transient Log LOG = LogFactory.getLog(Bank.class);
     private String bankName;
@@ -32,12 +33,12 @@
 
     public void process(Exchange exchange) throws Exception {
         LOG.info("Receiving bank request");
-        String clientId = 
(String)exchange.getIn().getHeader(Constants.PROPERTY_CLIENT_ID);
+        String ssn = 
(String)exchange.getIn().getHeader(Constants.PROPERTY_SSN);
         double rate = Math.random() * 10;
-        LOG.info("The bank: " + bankName + " for client: " + clientId + " 's 
rate " + rate);
+        LOG.info("The bank: " + bankName + " for client: " + ssn + " 's rate " 
+ rate);
         exchange.getOut().setHeader(Constants.PROPERTY_RATE, new Double(rate));
         exchange.getOut().setHeader(Constants.PROPERTY_BANK, bankName);
-        exchange.getOut().setHeader(Constants.PROPERTY_CLIENT_ID, clientId);
+        exchange.getOut().setHeader(Constants.PROPERTY_SSN, ssn);
         // Sleep some time
         try {
             Thread.sleep((int) (Math.random() * 10) * 100);
@@ -47,3 +48,4 @@
     }
 
 }
+//END SNIPPET: bank
\ No newline at end of file

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=663875&r1=663874&r2=663875&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
 Fri Jun  6 03:00:37 2008
@@ -19,8 +19,10 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.processor.aggregate.AggregationStrategy;
 
+//START SNIPPET: aggregation
 public class BankResponseAggregationStrategy implements AggregationStrategy {
 
+    // Here we put the bank response together
     public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
         Integer old = (Integer) oldExchange.getProperty("aggregated");
         Double oldRate = (Double) 
oldExchange.getIn().getHeader(Constants.PROPERTY_RATE);
@@ -34,10 +36,11 @@
         } else {
             result = newExchange;
         }
+        // Set the property for the completeness condition
         result.setProperty("aggregated", old + 1);
-        // copy the bank response together
         return result;
 
     }
 
 }
+// END SNIPPET: aggregation
\ No newline at end of file

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=663875&r1=663874&r2=663875&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
 Fri Jun  6 03:00:37 2008
@@ -26,6 +26,7 @@
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.jms.JmsComponent;
 import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultProducerTemplate;
 
 public class Client extends RouteBuilder {
 
@@ -41,11 +42,15 @@
         ProducerTemplate template = context.createProducerTemplate();
 
         context.start();
+        // START SNIPPET: sending
+        // send out the request message
         for (int i = 0; i < 2; i++) {
             template.sendBodyAndHeader("test-jms:queue:loanRequestQueue",
                                        "Quote for the lowerst rate of loaning 
bank",
-                                       Constants.PROPERTY_CLIENT_ID, "Client" 
+ i);
+                                       Constants.PROPERTY_SSN, "Client" + i);
         }
+        // END SNIPPET: sending
+
         // Start the loan broker
         Thread.sleep(1000 * 60);
         context.stop();
@@ -53,18 +58,20 @@
     }
 
     /**
-     * Lets configure the Camel routing rules using Java code...
+     * Lets configure the Camel routing rules using Java code to pull the 
response message
      */
     public void configure() {
-        from("test-jms:queue:loanReply").process(new Processor() {
+        // START SNIPPET: pulling
+        from("test-jms:queue:loanReplyQueue").process(new Processor() {
 
             public void process(Exchange exchange) throws Exception {
-                // Print out the message
+                // Print out the response message
                 System.out.println(exchange.getIn().getBody());
 
             }
 
         });
+        // END SNIPPET: pulling
     }
 
 }

Modified: 
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Constants.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Constants.java?rev=663875&r1=663874&r2=663875&view=diff
==============================================================================
--- 
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Constants.java
 (original)
+++ 
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Constants.java
 Fri Jun  6 03:00:37 2008
@@ -18,8 +18,6 @@
 
 public interface Constants {
 
-    String LOANBROKER_NS = "http://servicemix.org/demos/loan-broker";;
-
     String LOANBROKER_SERVICE = "loan-broker";
     String CREDITAGENCY_SERVICE = "credit-agency";
     String LENDERGATEWAY_SERVICE = "lender-gateway";
@@ -31,7 +29,6 @@
     String PROPERTY_SCORE = "score";
     String PROPERTY_HISTORYLENGTH = "hlength";
     String PROPERTY_RECIPIENTS = "recipients";
-    String PROPERTY_CLIENT_ID = "client_Id";
     String PROPERTY_RATE = "rate";
     String PROPERTY_BANK = "bank";
 

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=663875&r1=663874&r2=663875&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
 Fri Jun  6 03:00:37 2008
@@ -21,17 +21,19 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+//START SNIPPET: creditAgency
 public class CreditAgency implements Processor {
     private static final transient Log LOG = 
LogFactory.getLog(CreditAgency.class);
 
     public void process(Exchange exchange) throws Exception {
         LOG.info("Receiving credit agency request");
-        String clientId = 
(String)exchange.getIn().getHeader(Constants.PROPERTY_CLIENT_ID);
+        String ssn = 
(String)exchange.getIn().getHeader(Constants.PROPERTY_SSN);
         int score = (int) (Math.random() * 600 + 300);
         int hlength = (int) (Math.random() * 19 + 1);
         exchange.getOut().setHeader(Constants.PROPERTY_SCORE, new 
Integer(score));
         exchange.getOut().setHeader(Constants.PROPERTY_HISTORYLENGTH, new 
Integer(hlength));
-        exchange.getOut().setHeader(Constants.PROPERTY_CLIENT_ID, clientId);
+        exchange.getOut().setHeader(Constants.PROPERTY_SSN, ssn);
     }
 
 }
+//END SNIPPET: creditAgency
\ No newline at end of file

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=663875&r1=663874&r2=663875&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
 Fri Jun  6 03:00:37 2008
@@ -40,41 +40,58 @@
      * A main() so we can easily run these routing rules in our IDE
      * @throws Exception
      */
+    // START SNIPPET: starting
     public static void main(String... args) throws Exception {
+
         CamelContext context = new DefaultCamelContext();
         JmsBroker broker = new JmsBroker();
         broker.start();
         // Set up the ActiveMQ JMS Components
         ConnectionFactory connectionFactory = new 
ActiveMQConnectionFactory("tcp://localhost:61616");
-        // Note we can explicity name the component
+
+        // Note we can explicitly name the component
         context.addComponent("test-jms", 
JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
 
         context.addRoutes(new LoanBroker());
+        // Start the loan broker
         context.start();
 
-        // Start the loan broker
         Thread.sleep(5 * 60 * 1000);
         context.stop();
         Thread.sleep(1000);
         broker.stop();
 
-
     }
+    // END SNIPPET: starting
 
     /**
      * Lets configure the Camel routing rules using Java code...
      */
     public void configure() {
-
+    // START SNIPPET: dsl
+        // Put the message from loanRequestQueue to the creditRequestQueue
         
from("test-jms:queue:loanRequestQueue").to("test-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");
+
+        // 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");
+
+        // Each bank process 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("test-jms:queue:bankReplyQueue").aggregator(header(Constants.PROPERTY_CLIENT_ID),
 new BankResponseAggregationStrategy())
-            .completedPredicate(header("aggregated").isEqualTo(3)).process(new 
Translator()).to("test-jms:queue:loanReply");
 
+        // Now we aggregating the response message by using the 
Constants.PROPERTY_SSN header
+        // The aggregation will completed when the three bank responses are 
received
+        from("test-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");
 
+    // END SNIPPET: dsl
     }
 }

Modified: 
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java?rev=663875&r1=663874&r2=663875&view=diff
==============================================================================
--- 
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java
 (original)
+++ 
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java
 Fri Jun  6 03:00:37 2008
@@ -19,14 +19,16 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 
+//START SNIPPET: translator
 public class Translator implements Processor {
 
     public void process(Exchange exchange) throws Exception {
         String bank = 
(String)exchange.getIn().getHeader(Constants.PROPERTY_BANK);
         Double rate = 
(Double)exchange.getIn().getHeader(Constants.PROPERTY_RATE);
-        String clientId = 
(String)exchange.getIn().getHeader(Constants.PROPERTY_CLIENT_ID);
-        exchange.getOut().setBody("Loan quotion for Client " + clientId
+        String ssn = 
(String)exchange.getIn().getHeader(Constants.PROPERTY_SSN);
+        exchange.getOut().setBody("Loan quotion for Client " + ssn
                                   + "The lowest rate of bank is " + bank + ", 
the rate is " + rate);
     }
 
 }
+//END SNIPPET: translator
\ No newline at end of file

Modified: 
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties?rev=663875&r1=663874&r2=663875&view=diff
==============================================================================
--- 
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties
 (original)
+++ 
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties
 Fri Jun  6 03:00:37 2008
@@ -20,6 +20,8 @@
 #
 log4j.rootLogger=WARN, out
 
+log4j.logger.org.apache.camel=INFO
+
 # uncomment the following line to turn on Camel debugging
 #log4j.logger.org.apache.camel=DEBUG
 


Reply via email to