You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2015/09/09 12:46:54 UTC

svn commit: r1701974 - in /qpid/java/trunk: broker/src/main/java/org/apache/qpid/server/ client/src/main/java/org/apache/qpid/client/ client/src/main/java/org/apache/qpid/jndi/ common/src/main/java/org/apache/qpid/configuration/

Author: orudyy
Date: Wed Sep  9 10:46:54 2015
New Revision: 1701974

URL: http://svn.apache.org/r1701974
Log:
QPID-6719: Make sure qpid-client.properties and qpid-common.properties are loaded on initialization of classes AMQDestination, AMQConnection, AMQConnectionFactory and PropertiesFileInitialContextFactory

           work done by Lorenz Quack <qu...@gmail.com> and Alex Rudyy <or...@apache.org>

Modified:
    qpid/java/trunk/broker/src/main/java/org/apache/qpid/server/Main.java
    qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnection.java
    qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
    qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQDestination.java
    qpid/java/trunk/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java
    qpid/java/trunk/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
    qpid/java/trunk/common/src/main/java/org/apache/qpid/configuration/CommonProperties.java

Modified: qpid/java/trunk/broker/src/main/java/org/apache/qpid/server/Main.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker/src/main/java/org/apache/qpid/server/Main.java?rev=1701974&r1=1701973&r2=1701974&view=diff
==============================================================================
--- qpid/java/trunk/broker/src/main/java/org/apache/qpid/server/Main.java (original)
+++ qpid/java/trunk/broker/src/main/java/org/apache/qpid/server/Main.java Wed Sep  9 10:46:54 2015
@@ -33,6 +33,7 @@ import org.apache.commons.cli.OptionBuil
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
+import org.apache.qpid.configuration.CommonProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -110,6 +111,8 @@ public class Main
         OPTIONS.addOption(OPTION_MM_PASSWORD);
         OPTIONS.addOption(OPTION_CONFIGURATION_PROPERTY);
         OPTIONS.addOption(OPTION_INITIAL_SYSTEM_PROPERTIES);
+
+        CommonProperties.ensureIsLoaded();
     }
 
     protected CommandLine _commandLine;

Modified: qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnection.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnection.java?rev=1701974&r1=1701973&r2=1701974&view=diff
==============================================================================
--- qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnection.java (original)
+++ qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnection.java Wed Sep  9 10:46:54 2015
@@ -91,6 +91,11 @@ public class AMQConnection extends Close
 
     private static final Logger _logger = LoggerFactory.getLogger(AMQConnection.class);
 
+    static
+    {
+        ClientProperties.ensureIsLoaded();
+    }
+
     private static final AtomicLong CONN_NUMBER_GENERATOR = new AtomicLong();
     private static final long DEFAULT_CLOSE_TIMEOUT = Long.getLong(ClientProperties.QPID_CLOSE_TIMEOUT,
                                                                    ClientProperties.DEFAULT_CLOSE_TIMEOUT);

Modified: qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java?rev=1701974&r1=1701973&r2=1701974&view=diff
==============================================================================
--- qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java (original)
+++ qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java Wed Sep  9 10:46:54 2015
@@ -23,6 +23,7 @@ package org.apache.qpid.client;
 import static org.apache.qpid.client.AMQConnection.JNDI_ADDRESS_CONNECTION_URL;
 
 import org.apache.qpid.client.util.JMSExceptionHelper;
+import org.apache.qpid.configuration.ClientProperties;
 import org.apache.qpid.jms.ConnectionURL;
 import org.apache.qpid.jndi.ObjectFactory;
 import org.apache.qpid.url.URLSyntaxException;
@@ -57,6 +58,11 @@ public class AMQConnectionFactory implem
                                              javax.naming.spi.ObjectFactory, Referenceable, XATopicConnectionFactory,
                                              XAQueueConnectionFactory, XAConnectionFactory, Serializable
 {
+    static
+    {
+        ClientProperties.ensureIsLoaded();
+    }
+
     protected static final String NO_URL_CONFIGURED = "The connection factory wasn't created with a proper URL, the connection details are empty";
     private final static  ObjectFactory OBJECT_FACTORY = new ObjectFactory();
 

Modified: qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQDestination.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQDestination.java?rev=1701974&r1=1701973&r2=1701974&view=diff
==============================================================================
--- qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQDestination.java (original)
+++ qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQDestination.java Wed Sep  9 10:46:54 2015
@@ -57,6 +57,10 @@ public abstract class AMQDestination imp
     private static final Logger _logger = LoggerFactory.getLogger(AMQDestination.class);
     private static final long serialVersionUID = -3152767926421156400L;
 
+    static
+    {
+        ClientProperties.ensureIsLoaded();
+    }
 
     private String _exchangeName;
 

Modified: qpid/java/trunk/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java?rev=1701974&r1=1701973&r2=1701974&view=diff
==============================================================================
--- qpid/java/trunk/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java (original)
+++ qpid/java/trunk/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java Wed Sep  9 10:46:54 2015
@@ -47,6 +47,7 @@ import org.apache.qpid.client.AMQDestina
 import org.apache.qpid.client.AMQHeadersExchange;
 import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.configuration.ClientProperties;
 import org.apache.qpid.exchange.ExchangeDefaults;
 import org.apache.qpid.url.BindingURL;
 import org.apache.qpid.url.URLSyntaxException;
@@ -60,6 +61,11 @@ public class PropertiesFileInitialContex
 {
     private final Logger _logger = LoggerFactory.getLogger(PropertiesFileInitialContextFactory.class);
 
+    static
+    {
+        ClientProperties.ensureIsLoaded();
+    }
+
     private String CONNECTION_FACTORY_PREFIX = "connectionfactory.";
     private String DESTINATION_PREFIX = "destination.";
     private String QUEUE_PREFIX = "queue.";

Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java?rev=1701974&r1=1701973&r2=1701974&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java Wed Sep  9 10:46:54 2015
@@ -265,46 +265,56 @@ public class ClientProperties
      */
     public static final String QPID_USE_LEGACY_GETQUEUEDEPTH_BEHAVIOUR = "qpid.use_legacy_getqueuedepth_behavior";
 
+    private volatile static boolean _loaded;
+
     static
     {
-        // force load of common properties
-        Class<CommonProperties> commonPropertiesClass = CommonProperties.class;
+        ensureIsLoaded();
+    }
 
-        Properties props = new Properties();
-        String initialProperties = System.getProperty("qpid.client_properties_file");
-        URL initialPropertiesLocation = null;
-        try
+    public static synchronized void ensureIsLoaded()
+    {
+        if (!_loaded)
         {
-            if (initialProperties == null)
+            CommonProperties.ensureIsLoaded();
+
+            Properties props = new Properties();
+            String initialProperties = System.getProperty("qpid.client_properties_file");
+            URL initialPropertiesLocation = null;
+            try
             {
-                initialPropertiesLocation = ClientProperties.class.getClassLoader().getResource("qpid-client.properties");
+                if (initialProperties == null)
+                {
+                    initialPropertiesLocation = ClientProperties.class.getClassLoader().getResource("qpid-client.properties");
+                }
+                else
+                {
+                    initialPropertiesLocation = (new File(initialProperties)).toURI().toURL();
+                }
+
+                if (initialPropertiesLocation != null)
+                {
+                    props.load(initialPropertiesLocation.openStream());
+                }
             }
-            else
+            catch (MalformedURLException e)
             {
-                initialPropertiesLocation = (new File(initialProperties)).toURI().toURL();
+                LOGGER.warn("Could not open client properties file '" + initialProperties + "'.", e);
+            }
+            catch (IOException e)
+            {
+                LOGGER.warn("Could not open client properties file '" + initialPropertiesLocation + "'.", e);
             }
 
-            if (initialPropertiesLocation != null)
+            Set<String> propertyNames = new HashSet<>(props.stringPropertyNames());
+            propertyNames.removeAll(System.getProperties().stringPropertyNames());
+            for (String propName : propertyNames)
             {
-                props.load(initialPropertiesLocation.openStream());
+                System.setProperty(propName, props.getProperty(propName));
             }
-        }
-        catch (MalformedURLException e)
-        {
-            LOGGER.warn("Could not open client properties file '"+initialProperties+"'.", e);
-        }
-        catch (IOException e)
-        {
-            LOGGER.warn("Could not open client properties file '" + initialPropertiesLocation + "'.", e);
-        }
 
-        Set<String> propertyNames = new HashSet<>(props.stringPropertyNames());
-        propertyNames.removeAll(System.getProperties().stringPropertyNames());
-        for (String propName : propertyNames)
-        {
-            System.setProperty(propName, props.getProperty(propName));
+            _loaded = true;
         }
-
     }
 
     private ClientProperties()

Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/configuration/CommonProperties.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/configuration/CommonProperties.java?rev=1701974&r1=1701973&r2=1701974&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/configuration/CommonProperties.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/configuration/CommonProperties.java Wed Sep  9 10:46:54 2015
@@ -51,44 +51,54 @@ public class CommonProperties
     public static final String HANDSHAKE_TIMEOUT_PROP_NAME = "qpid.handshake_timeout";
     public static final int HANDSHAKE_TIMEOUT_DEFAULT = 2;
 
+    private volatile static boolean _loaded;
+
     static
     {
+        ensureIsLoaded();
+    }
 
-        Properties props = new Properties(QpidProperties.asProperties());
-        String initialProperties = System.getProperty("qpid.common_properties_file");
-        URL initialPropertiesLocation = null;
-        try
+    public static synchronized void ensureIsLoaded()
+    {
+        if (!_loaded)
         {
-            if (initialProperties == null)
+            Properties props = new Properties(QpidProperties.asProperties());
+            String initialProperties = System.getProperty("qpid.common_properties_file");
+            URL initialPropertiesLocation = null;
+            try
             {
-                initialPropertiesLocation = CommonProperties.class.getClassLoader().getResource("qpid-common.properties");
+                if (initialProperties == null)
+                {
+                    initialPropertiesLocation = CommonProperties.class.getClassLoader().getResource("qpid-common.properties");
+                }
+                else
+                {
+                    initialPropertiesLocation = (new File(initialProperties)).toURI().toURL();
+                }
+
+                if (initialPropertiesLocation != null)
+                {
+                    props.load(initialPropertiesLocation.openStream());
+                }
             }
-            else
+            catch (MalformedURLException e)
             {
-                initialPropertiesLocation = (new File(initialProperties)).toURI().toURL();
+                LOGGER.warn("Could not open common properties file '" + initialProperties + "'.", e);
+            }
+            catch (IOException e)
+            {
+                LOGGER.warn("Could not open common properties file '" + initialPropertiesLocation + "'.", e);
             }
 
-            if (initialPropertiesLocation != null)
+            Set<String> propertyNames = new HashSet<>(props.stringPropertyNames());
+            propertyNames.removeAll(System.getProperties().stringPropertyNames());
+            for (String propName : propertyNames)
             {
-                props.load(initialPropertiesLocation.openStream());
+                System.setProperty(propName, props.getProperty(propName));
             }
-        }
-        catch (MalformedURLException e)
-        {
-            LOGGER.warn("Could not open common properties file '"+initialProperties+"'.", e);
-        }
-        catch (IOException e)
-        {
-            LOGGER.warn("Could not open common properties file '" + initialPropertiesLocation + "'.", e);
-        }
 
-        Set<String> propertyNames = new HashSet<>(props.stringPropertyNames());
-        propertyNames.removeAll(System.getProperties().stringPropertyNames());
-        for (String propName : propertyNames)
-        {
-            System.setProperty(propName, props.getProperty(propName));
+            _loaded = true;
         }
-
     }
 
     private CommonProperties()



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org