Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/spring/Main.java


1   /** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.activemq.spring;
19  
20  import org.activemq.broker.BrokerContainer;
21  import org.activemq.broker.BrokerContext;
22  import org.activemq.util.IdGenerator;
23  import org.springframework.core.io.ClassPathResource;
24  import org.springframework.core.io.FileSystemResource;
25  
26  import javax.jms.JMSException;
27  
28  /**
29   * A simple command line tool which runs a JMS Message Broker on the command line
30   * using a Spring XML deployment descriptor
31   *
32   * @version $Revision$
33   */
34  public class Main {
35  
36      /**
37       * run the Message Broker as a standalone application
38       *
39       * @param args
40       */
41      public static void main(String args[]) {
42          try {
43              String version = "";
44              Package p = Package.getPackage("org.activemq");
45              if (p != null) {
46                  version = ": " + p.getImplementationVersion();
47              }
48              System.out.println("ActiveMQ Message Broker (http://activemq.org/) " + version);
49              System.out.println();
50  
51              SpringBrokerContainerFactory factory = new SpringBrokerContainerFactory();
52              String file = null;
53              if (args.length <= 0) {
54                  System.out.println("Loading Mesaage Broker from activemq.xml on the CLASSPATH");
55                  factory.setResource(new ClassPathResource("activemq.xml"));
56              }
57              else {
58                  file = args[0];
59  
60                  if (file.equals("-?") || file.equals("?") || file.equals("--help") || file.equals("-h")) {
61                      System.out.println("Usage: Main [xmlConfigFile]");
62                      System.out.println("If an XML config file is not specified then activemq.xml is used from the CLASSPAHT");
63                      return;
64                  }
65  
66                  System.out.println("Loading Message Broker from file: " + file);
67                  factory.setResource(new FileSystemResource(file));
68              }
69  
70              IdGenerator idgen = new IdGenerator();
71              BrokerContainer container = factory.createBrokerContainer(idgen.generateId(), BrokerContext.getInstance());
72              container.start();
73  
74              // lets wait until we're killed.
75              Object lock = new Object();
76              synchronized (lock) {
77                  lock.wait();
78              }
79          }
80          catch (JMSException e) {
81              System.out.println("Caught: " + e);
82              e.printStackTrace();
83              Exception le = e.getLinkedException();
84              System.out.println("Reason: " + le);
85              if (le != null) {
86                  le.printStackTrace();
87              }
88          }
89          catch (Exception e) {
90              System.out.println("Caught: " + e);
91              e.printStackTrace();
92          }
93      }
94  }