1 18 package org.apache.activemq.broker; 19 20 import java.io.IOException ; 21 import java.net.URI ; 22 23 import org.apache.activemq.util.FactoryFinder; 24 import org.apache.activemq.util.IOExceptionSupport; 25 26 33 public class BrokerFactory { 34 35 static final private FactoryFinder brokerFactoryHandlerFinder = new FactoryFinder("META-INF/services/org/apache/activemq/broker/"); 36 37 public static BrokerFactoryHandler createBrokerFactoryHandler(String type) throws IOException { 38 try { 39 return (BrokerFactoryHandler)brokerFactoryHandlerFinder.newInstance(type); 40 } catch (Throwable e) { 41 throw IOExceptionSupport.create("Could load "+type+" factory:"+e, e); 42 } 43 } 44 45 50 public static BrokerService createBroker(URI brokerURI) throws Exception { 51 return createBroker(brokerURI, false); 52 } 53 54 60 public static BrokerService createBroker(URI brokerURI, boolean startBroker) throws Exception { 61 if( brokerURI.getScheme() == null ) 62 throw new IllegalArgumentException ("Invalid broker URI, no scheme specified: "+brokerURI); 63 64 BrokerFactoryHandler handler = createBrokerFactoryHandler(brokerURI.getScheme()); 65 BrokerService broker = handler.createBroker(brokerURI); 66 if (startBroker) { 67 broker.start(); 68 } 69 return broker; 70 } 71 72 73 78 public static BrokerService createBroker(String brokerURI) throws Exception { 79 return createBroker(new URI (brokerURI)); 80 } 81 82 83 89 public static BrokerService createBroker(String brokerURI, boolean startBroker) throws Exception { 90 return createBroker(new URI (brokerURI), startBroker); 91 } 92 93 94 } 95 | Popular Tags |