activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r518590 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/ main/java/org/apache/activemq/transport/peer/ main/java/org/apache/activemq/transport/vm/ main/java/org/apache/activemq/xbean/ main/resources/META-INF/ser...
Date Thu, 15 Mar 2007 11:39:05 GMT
Author: jstrachan
Date: Thu Mar 15 04:39:04 2007
New Revision: 518590

URL: http://svn.apache.org/viewvc?view=rev&rev=518590
Log:
added support for using a properties file to configure the broker to avoid the dependency
on Spring and xbean; for AMQ-1206

Added:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactoryHandler.java
  (with props)
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/PropertiesBrokerFactory.java
  (with props)
    activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/broker/properties
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java
  (with props)
    activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/broker.properties
  (with props)
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactory.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/DefaultBrokerFactory.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/peer/PeerTransportFactory.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactory.java?view=diff&rev=518590&r1=518589&r2=518590
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactory.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactory.java
Thu Mar 15 04:39:04 2007
@@ -34,10 +34,6 @@
 
     static final private FactoryFinder brokerFactoryHandlerFinder = new FactoryFinder("META-INF/services/org/apache/activemq/broker/");
 
-    public interface BrokerFactoryHandler {
-        public BrokerService createBroker(URI brokerURI) throws Exception;
-    }
-    
     public static BrokerFactoryHandler createBrokerFactoryHandler(String type) throws IOException
{
         try {
             return (BrokerFactoryHandler)brokerFactoryHandlerFinder.newInstance(type);
@@ -48,26 +44,50 @@
 
     /**
      * Creates a broker from a URI configuration
-     * @param brokerURI
-     * @throws Exception 
+     * @param brokerURI the URI scheme to configure the broker
+     * @throws Exception
      */
     public static BrokerService createBroker(URI brokerURI) throws Exception {
+        return createBroker(brokerURI, false);
+    }
+
+    /**
+     * Creates a broker from a URI configuration
+     * @param brokerURI the URI scheme to configure the broker
+     * @param startBroker whether or not the broker should have its {@link BrokerService#start()}
method called after construction
+     * @throws Exception
+     */
+    public static BrokerService createBroker(URI brokerURI, boolean startBroker) throws Exception
{
         if( brokerURI.getScheme() == null )
             throw new IllegalArgumentException("Invalid broker URI, no scheme specified:
"+brokerURI);
         
         BrokerFactoryHandler handler = createBrokerFactoryHandler(brokerURI.getScheme());
         BrokerService broker = handler.createBroker(brokerURI);
+        if (startBroker) {
+            broker.start();
+        }
         return broker;
     }
 
 
     /**
      * Creates a broker from a URI configuration
-     * @param brokerURI
+     * @param brokerURI the URI scheme to configure the broker
      * @throws Exception
      */
     public static BrokerService createBroker(String brokerURI) throws Exception {
         return createBroker(new URI(brokerURI));
+    }
+
+
+    /**
+     * Creates a broker from a URI configuration
+     * @param brokerURI the URI scheme to configure the broker
+     * @param startBroker whether or not the broker should have its {@link BrokerService#start()}
method called after construction
+     * @throws Exception
+     */
+    public static BrokerService createBroker(String brokerURI, boolean startBroker) throws
Exception {
+        return createBroker(new URI(brokerURI), startBroker);
     }
 
 

Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactoryHandler.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactoryHandler.java?view=auto&rev=518590
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactoryHandler.java
(added)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactoryHandler.java
Thu Mar 15 04:39:04 2007
@@ -0,0 +1,29 @@
+/**
+ *
+ * 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.activemq.broker;
+
+import java.net.URI;
+
+/**
+ * Represents the interface used to create a broker from a URI scheme.
+ *
+ * @version $Revision$
+*/
+public interface BrokerFactoryHandler {
+    public BrokerService createBroker(URI brokerURI) throws Exception;
+}

Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactoryHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactoryHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFactoryHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?view=diff&rev=518590&r1=518589&r2=518590
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Thu Mar 15 04:39:04 2007
@@ -155,7 +155,22 @@
     private int persistenceThreadPriority = Thread.MAX_PRIORITY;
     private boolean useLocalHostBrokerName = false;
     private CountDownLatch stoppedLatch = new CountDownLatch(1);
-    
+
+    static{
+        String localHostName = "localhost";
+        try{
+            localHostName=java.net.InetAddress.getLocalHost().getHostName();
+        }catch(UnknownHostException e){
+            log.error("Failed to resolve localhost");
+        }
+        LOCAL_HOST_NAME = localHostName;
+    }
+
+    @Override
+    public String toString() {
+        return "BrokerService[" + getBrokerName() + "]";
+    }
+
     /**
      * Adds a new transport connector for the given bind address
      *
@@ -1654,16 +1669,6 @@
             }
         }
     }    
-    
-    static{
-        String localHostName = "localhost";
-        try{
-            localHostName=java.net.InetAddress.getLocalHost().getHostName();
-        }catch(UnknownHostException e){
-            log.error("Failed to resolve localhost");
-        }
-        LOCAL_HOST_NAME = localHostName;
-    }
 
     
    

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/DefaultBrokerFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/DefaultBrokerFactory.java?view=diff&rev=518590&r1=518589&r2=518590
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/DefaultBrokerFactory.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/DefaultBrokerFactory.java
Thu Mar 15 04:39:04 2007
@@ -17,7 +17,7 @@
  */
 package org.apache.activemq.broker;
 
-import org.apache.activemq.broker.BrokerFactory.BrokerFactoryHandler;
+import org.apache.activemq.broker.BrokerFactoryHandler;
 import org.apache.activemq.util.IntrospectionSupport;
 import org.apache.activemq.util.URISupport;
 import org.apache.activemq.util.URISupport.CompositeData;
@@ -55,9 +55,6 @@
                 brokerService.addConnector(components[i]);
             }
         }
-        
-        // TODO we want folks to be able to add other connectors and start the broker afterwards
-        //brokerService.start();
         return brokerService;
     }
 

Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/PropertiesBrokerFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/PropertiesBrokerFactory.java?view=auto&rev=518590
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/PropertiesBrokerFactory.java
(added)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/PropertiesBrokerFactory.java
Thu Mar 15 04:39:04 2007
@@ -0,0 +1,102 @@
+/**
+ *
+ * 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.activemq.broker;
+
+import org.apache.activemq.util.IntrospectionSupport;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * A {@link BrokerFactoryHandler} which uses a properties file to
+ * configure the broker's various policies.
+ *
+ * @version $Revision$
+ */
+public class PropertiesBrokerFactory implements BrokerFactoryHandler {
+
+    public BrokerService createBroker(URI brokerURI) throws Exception {
+
+        Map properties = loadProperties(brokerURI);
+        BrokerService brokerService = createBrokerService(brokerURI, properties);
+
+        IntrospectionSupport.setProperties(brokerService, properties);
+        return brokerService;
+    }
+
+    /**
+     * Lets load the properties from some external URL or a relative file
+     */
+    protected Map loadProperties(URI brokerURI) throws IOException {
+        // lets load a URI
+        String remaining = brokerURI.getSchemeSpecificPart();
+        Properties properties = new Properties();
+        File file = new File(remaining);
+
+        InputStream inputStream = null;
+        if (file.exists()) {
+            inputStream = new FileInputStream(file);
+        }
+        else {
+            URL url = null;
+            try {
+                url = new URL(remaining);
+            }
+            catch (MalformedURLException e) {
+                // lets now see if we can find the name on the classpath
+                inputStream = findResourceOnClassPath(remaining);
+                if (inputStream == null) {
+                    throw new IOException("File does not exist: " + remaining + ", could
not be found on the classpath and is not a valid URL: " + e);
+                }
+            }
+            if (inputStream == null) {
+                inputStream = url.openStream();
+            }
+        }
+        properties.load(inputStream);
+
+        // should we append any system properties?
+        try {
+            Properties systemProperties = System.getProperties();
+            properties.putAll(systemProperties);
+        }
+        catch (Exception e) {
+            // ignore security exception
+        }
+        return properties;
+    }
+
+    protected InputStream findResourceOnClassPath(String remaining) {
+        InputStream answer = Thread.currentThread().getContextClassLoader().getResourceAsStream(remaining);
+        if (answer == null) {
+            answer = getClass().getClassLoader().getResourceAsStream(remaining);
+        }
+        return answer;
+    }
+
+    protected BrokerService createBrokerService(URI brokerURI, Map properties) {
+        return new BrokerService();
+    }
+}

Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/PropertiesBrokerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/PropertiesBrokerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/PropertiesBrokerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/peer/PeerTransportFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/peer/PeerTransportFactory.java?view=diff&rev=518590&r1=518589&r2=518590
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/peer/PeerTransportFactory.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/peer/PeerTransportFactory.java
Thu Mar 15 04:39:04 2007
@@ -25,7 +25,7 @@
 
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.TransportConnector;
-import org.apache.activemq.broker.BrokerFactory.BrokerFactoryHandler;
+import org.apache.activemq.broker.BrokerFactoryHandler;
 import org.apache.activemq.transport.Transport;
 import org.apache.activemq.transport.TransportFactory;
 import org.apache.activemq.transport.TransportServer;

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java?view=diff&rev=518590&r1=518589&r2=518590
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransportFactory.java
Thu Mar 15 04:39:04 2007
@@ -26,7 +26,7 @@
 import org.apache.activemq.broker.BrokerRegistry;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.TransportConnector;
-import org.apache.activemq.broker.BrokerFactory.BrokerFactoryHandler;
+import org.apache.activemq.broker.BrokerFactoryHandler;
 import org.apache.activemq.transport.MarshallingTransportFilter;
 import org.apache.activemq.transport.Transport;
 import org.apache.activemq.transport.TransportFactory;

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java?view=diff&rev=518590&r1=518589&r2=518590
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java
Thu Mar 15 04:39:04 2007
@@ -21,7 +21,7 @@
 import java.net.URI;
 
 import org.apache.activemq.broker.BrokerService;
-import org.apache.activemq.broker.BrokerFactory.BrokerFactoryHandler;
+import org.apache.activemq.broker.BrokerFactoryHandler;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;

Added: activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/broker/properties
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/broker/properties?view=auto&rev=518590
==============================================================================
--- activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/broker/properties
(added)
+++ activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/broker/properties
Thu Mar 15 04:39:04 2007
@@ -0,0 +1 @@
+class=org.apache.activemq.broker.PropertiesBrokerFactory

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java?view=auto&rev=518590
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java
(added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java
Thu Mar 15 04:39:04 2007
@@ -0,0 +1,42 @@
+/**
+ *
+ * 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.activemq.config;
+
+import junit.framework.TestCase;
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Revision$
+ */
+public class BrokerPropertiesTest extends TestCase {
+    private static final transient Log log = LogFactory.getLog(BrokerPropertiesTest.class);
+    
+    public void testPropertiesFile() throws Exception {
+        BrokerService broker = BrokerFactory.createBroker("properties:org/apache/activemq/config/broker.properties");
+
+        log.info("Created broker: " + broker);
+        assertNotNull(broker);
+
+        assertEquals("isUseJmx()", false, broker.isUseJmx());
+        assertEquals("isPersistent()", false, broker.isPersistent());
+        assertEquals("getBrokerName()", "Cheese", broker.getBrokerName());
+    }
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/broker.properties
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/broker.properties?view=auto&rev=518590
==============================================================================
--- activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/broker.properties
(added)
+++ activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/broker.properties
Thu Mar 15 04:39:04 2007
@@ -0,0 +1,3 @@
+useJmx = false
+persistent = false
+brokerName = Cheese
\ No newline at end of file

Propchange: activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/broker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/broker.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/config/broker.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message