Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.servicemix.samples.loanbroker;
 
 

Version:
$Revision: 666120 $
 
 public class JMSClient implements Runnable {
 
     private static ConnectionFactory factory;
     private static CountDownLatch latch;
     private static Requestor requestor;

    
main ...

Parameters:
args
Throws:
java.lang.Exception
 
     public static void main(String[] argsthrows Exception {
         ..println("Connecting to JMS server.");
          = new ActiveMQConnectionFactory("tcp://localhost:61616");
         Destination inQueue = new ActiveMQQueue("demo.org.servicemix.source");
         Destination outQueue = new ActiveMQQueue("demo.org.servicemix.output" + (int)(1000*Math.random()));
          = MultiplexingRequestor.newInstance(new JmsProducerConfig(), inQueueoutQueue); 
 
         if (args.length == 0) {
             new JMSClient().run();
         } else {
             int nb = Integer.parseInt(args[0]);
             int th = 30;
             if (args.length > 1) {
                 th = Integer.parseInt(args[1]);
             }
              = new CountDownLatch(nb);
             ExecutorService threadPool = Executors.newFixedThreadPool(th);
             for (int i = 0; i < nbi++) {
                 threadPool.submit(new JMSClient());
             }
             .await();
         }
         ..println("Closing.");
         .close();
         System.exit(0);
     }
 
     public void run() {
         try {
             ..println("Sending request.");
             double r = Math.random();
 
             String request =
                 "<getLoanQuoteRequest xmlns='urn:logicblaze:soa:loanbroker'>\n" +
                 "  <ssn>102-24532-53254</ssn>\n" +
                 "  <amount>" + r * 100000 + "</amount>\n" +
                 "  <duration>" + (intr * 48 + "</duration>\n" +
                 "  <score>" + (intr * 48 + "</score>\n" +
                 "  <length>" + (intr * 48 + "</length>\n" +
                 "</getLoanQuoteRequest>";
 
             TextMessage out = .getSession().createTextMessage(request);
 
             TextMessage in = (TextMessage.request(nullout); 
             if (in == null) {
                 ..println("Response timed out.");
             }
             else {
                 ..println("Response was: " + in.getText());
             }
         } catch (Exception e) {
             e.printStackTrace();
        } finally {
            if ( != null) {
                .countDown();
            }
        }
    }
New to GrepCode? Check out our FAQ X