qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgodf...@apache.org
Subject svn commit: r1642935 - in /qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias: HostNameAliasImpl.java PatternMatchingAliasImpl.java
Date Tue, 02 Dec 2014 16:28:25 GMT
Author: rgodfrey
Date: Tue Dec  2 16:28:25 2014
New Revision: 1642935

URL: http://svn.apache.org/r1642935
Log:
QPID-6161 : Address comments from ~kwall

Modified:
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/HostNameAliasImpl.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/PatternMatchingAliasImpl.java

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/HostNameAliasImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/HostNameAliasImpl.java?rev=1642935&r1=1642934&r2=1642935&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/HostNameAliasImpl.java
(original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/HostNameAliasImpl.java
Tue Dec  2 16:28:25 2014
@@ -35,6 +35,8 @@ import java.util.concurrent.atomic.Atomi
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import org.apache.log4j.Logger;
+
 import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.HostNameAlias;
 import org.apache.qpid.server.model.ManagedObjectFactoryConstructor;
@@ -47,6 +49,8 @@ public class HostNameAliasImpl
         implements HostNameAlias<HostNameAliasImpl>
 {
 
+    private static final Logger LOG = Logger.getLogger(HostNameAliasImpl.class);
+
     private final Set<InetAddress> _localAddresses = new CopyOnWriteArraySet<>();
     private final Set<String> _localAddressNames = new CopyOnWriteArraySet<>();
     private final Lock _addressLock = new ReentrantLock();
@@ -62,7 +66,12 @@ public class HostNameAliasImpl
     protected void onOpen()
     {
         super.onOpen();
-        Thread thread = new Thread(new NetworkAddressResolver(), "Network Address Resolver");
+        String bindingAddress = ((AmqpPort) getPort()).getBindingAddress();
+        Thread thread = new Thread(new NetworkAddressResolver(),
+                                   "Network Address Resolver (Port: "
+                                   + (useAllAddresses(bindingAddress) ? "" : bindingAddress)
+                                   + ":" + getPort().getPort() +")");
+        thread.setDaemon(true);
         thread.start();
     }
 
@@ -138,7 +147,7 @@ public class HostNameAliasImpl
             try
             {
                 Collection<InetAddress> inetAddresses;
-                if(bindingAddress == null || bindingAddress.trim().equals("") || bindingAddress.trim().equals("*"))
+                if(useAllAddresses(bindingAddress))
                 {
                     inetAddresses = getAllInetAddresses();
                 }
@@ -168,7 +177,8 @@ public class HostNameAliasImpl
             }
             catch (SocketException | UnknownHostException e)
             {
-                // ignore
+                LOG.error("Unable to correctly calculate host name aliases for port " + getPort().getName()
+                         + ". This may lead to connection failures.", e);
             }
             finally
             {
@@ -190,4 +200,9 @@ public class HostNameAliasImpl
             return addresses;
         }
     }
+
+    private boolean useAllAddresses(final String bindingAddress)
+    {
+        return bindingAddress == null || bindingAddress.trim().equals("") || bindingAddress.trim().equals("*");
+    }
 }

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/PatternMatchingAliasImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/PatternMatchingAliasImpl.java?rev=1642935&r1=1642934&r2=1642935&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/PatternMatchingAliasImpl.java
(original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/PatternMatchingAliasImpl.java
Tue Dec  2 16:28:25 2014
@@ -21,11 +21,16 @@
 package org.apache.qpid.server.virtualhostalias;
 
 import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.server.model.ManagedAttributeField;
 import org.apache.qpid.server.model.ManagedObjectFactoryConstructor;
-import org.apache.qpid.server.model.Port;
 import org.apache.qpid.server.model.PatternMatchingAlias;
+import org.apache.qpid.server.model.Port;
 
 public final class PatternMatchingAliasImpl
         extends AbstractFixedVirtualHostNodeAlias<PatternMatchingAliasImpl>
@@ -47,6 +52,34 @@ public final class PatternMatchingAliasI
     }
 
     @Override
+    public void onValidate()
+    {
+        super.onValidate();
+        validatePattern(getPattern());
+
+    }
+
+    @Override
+    protected void validateChange(final ConfiguredObject<?> proxyForValidation, final
Set<String> changedAttributes)
+    {
+        super.validateChange(proxyForValidation, changedAttributes);
+        validatePattern(((PatternMatchingAlias)proxyForValidation).getPattern());
+    }
+
+    private void validatePattern(final String pattern)
+    {
+        try
+        {
+            Pattern p = Pattern.compile(pattern);
+        }
+        catch (PatternSyntaxException e)
+        {
+            throw new IllegalConfigurationException("'"+pattern+"' is not a valid Java regex
pattern", e);
+        }
+
+    }
+
+    @Override
     public String getPattern()
     {
         return _pattern;



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


Mime
View raw message