This is an automated email from the ASF dual-hosted git repository.

michaelpearce pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new 6c0f9f8  ARTEMIS-2221 avoid unnecessary Bindings instance creation
     new 10f5b18  This closes #2469
6c0f9f8 is described below

commit 6c0f9f8d3d6a1cfc888c6cb922c30a611df73b45
Author: Justin Bertram <jbert...@apache.org>
AuthorDate: Tue Dec 18 11:48:12 2018 -0600

    ARTEMIS-2221 avoid unnecessary Bindings instance creation
    
    When trying to get the bindings for an address the getBindingsForAddress
    method will create a Bindings instance if there are no bindings for the
    address. This is unnecessary in most circumstances so use the
    lookupBindingsForAddress method instead and check for null.
---
 .../core/protocol/openwire/OpenWireConnection.java | 20 ++++++-----
 .../management/impl/ActiveMQServerControlImpl.java |  4 +--
 .../core/management/impl/AddressControlImpl.java   | 42 +++++++++++++---------
 .../core/postoffice/impl/PostOfficeImpl.java       | 14 ++++----
 .../artemis/core/server/impl/QueueImpl.java        |  8 ++---
 .../artemis/core/server/impl/ScaleDownHandler.java | 16 +++++----
 6 files changed, 60 insertions(+), 44 deletions(-)

diff --git 
a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java
 
b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java
index ef5568f..33cac24 100644
--- 
a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java
+++ 
b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java
@@ -1033,17 +1033,19 @@ public class OpenWireConnection extends 
AbstractRemotingConnection implements Se
 
 
       } else {
-         Bindings bindings = server.getPostOffice().getBindingsForAddress(new 
SimpleString(dest.getPhysicalName()));
+         Bindings bindings = 
server.getPostOffice().lookupBindingsForAddress(new 
SimpleString(dest.getPhysicalName()));
 
-         for (Binding binding : bindings.getBindings()) {
-            Queue b = (Queue) binding.getBindable();
-            if (b.getConsumerCount() > 0) {
-               throw new Exception("Destination still has an active 
subscription: " + dest.getPhysicalName());
-            }
-            if (b.isDurable()) {
-               throw new Exception("Destination still has durable 
subscription: " + dest.getPhysicalName());
+         if (bindings != null) {
+            for (Binding binding : bindings.getBindings()) {
+               Queue b = (Queue) binding.getBindable();
+               if (b.getConsumerCount() > 0) {
+                  throw new Exception("Destination still has an active 
subscription: " + dest.getPhysicalName());
+               }
+               if (b.isDurable()) {
+                  throw new Exception("Destination still has durable 
subscription: " + dest.getPhysicalName());
+               }
+               b.deleteQueue();
             }
-            b.deleteQueue();
          }
       }
 
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
index ec0098e..302da89 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
@@ -1069,8 +1069,8 @@ public class ActiveMQServerControlImpl extends 
AbstractControl implements Active
 
       clearIO();
       try {
-         final Bindings bindings = 
server.getPostOffice().getBindingsForAddress(new SimpleString(address));
-         return 
bindings.getBindings().stream().map(Binding::toManagementString).collect(Collectors.joining(","));
+         final Bindings bindings = 
server.getPostOffice().lookupBindingsForAddress(new SimpleString(address));
+         return bindings == null ? "" : 
bindings.getBindings().stream().map(Binding::toManagementString).collect(Collectors.joining(","));
       } finally {
          blockOnIO();
       }
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
index 5ef91c3..e71aab1 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
@@ -123,14 +123,18 @@ public class AddressControlImpl extends AbstractControl 
implements AddressContro
    public String[] getQueueNames() throws Exception {
       clearIO();
       try {
-         Bindings bindings = 
server.getPostOffice().getBindingsForAddress(addressInfo.getName());
-         List<String> queueNames = new ArrayList<>();
-         for (Binding binding : bindings.getBindings()) {
-            if (binding instanceof QueueBinding) {
-               queueNames.add(binding.getUniqueName().toString());
+         Bindings bindings = 
postOffice.lookupBindingsForAddress(addressInfo.getName());
+         if (bindings != null) {
+            List<String> queueNames = new ArrayList<>();
+            for (Binding binding : bindings.getBindings()) {
+               if (binding instanceof QueueBinding) {
+                  queueNames.add(binding.getUniqueName().toString());
+               }
             }
+            return queueNames.toArray(new String[queueNames.size()]);
+         } else {
+            return new String[0];
          }
-         return queueNames.toArray(new String[queueNames.size()]);
       } catch (Throwable t) {
          throw new IllegalStateException(t.getMessage());
       } finally {
@@ -142,13 +146,17 @@ public class AddressControlImpl extends AbstractControl 
implements AddressContro
    public String[] getBindingNames() throws Exception {
       clearIO();
       try {
-         Bindings bindings = 
server.getPostOffice().getBindingsForAddress(addressInfo.getName());
-         String[] bindingNames = new String[bindings.getBindings().size()];
-         int i = 0;
-         for (Binding binding : bindings.getBindings()) {
-            bindingNames[i++] = binding.getUniqueName().toString();
+         Bindings bindings = 
postOffice.lookupBindingsForAddress(addressInfo.getName());
+         if (bindings != null) {
+            String[] bindingNames = new String[bindings.getBindings().size()];
+            int i = 0;
+            for (Binding binding : bindings.getBindings()) {
+               bindingNames[i++] = binding.getUniqueName().toString();
+            }
+            return bindingNames;
+         } else {
+            return new String[0];
          }
-         return bindingNames;
       } catch (Throwable t) {
          throw new IllegalStateException(t.getMessage());
       } finally {
@@ -227,10 +235,12 @@ public class AddressControlImpl extends AbstractControl 
implements AddressContro
       clearIO();
       long totalMsgs = 0;
       try {
-         Bindings bindings = 
server.getPostOffice().getBindingsForAddress(addressInfo.getName());
-         for (Binding binding : bindings.getBindings()) {
-            if (binding instanceof QueueBinding) {
-               totalMsgs += ((QueueBinding) 
binding).getQueue().getMessageCount();
+         Bindings bindings = 
postOffice.lookupBindingsForAddress(addressInfo.getName());
+         if (bindings != null) {
+            for (Binding binding : bindings.getBindings()) {
+               if (binding instanceof QueueBinding) {
+                  totalMsgs += ((QueueBinding) 
binding).getQueue().getMessageCount();
+               }
             }
          }
          return totalMsgs;
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java
index 8b82ee8..493dd64 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java
@@ -639,12 +639,14 @@ public class PostOfficeImpl implements PostOffice, 
NotificationListener, Binding
 
    @Override
    public List<Queue> listQueuesForAddress(SimpleString address) throws 
Exception {
-      Bindings bindingsForAddress = getBindingsForAddress(address);
+      Bindings bindingsForAddress = lookupBindingsForAddress(address);
       List<Queue> queues = new ArrayList<>();
-      for (Binding b : bindingsForAddress.getBindings()) {
-         if (b instanceof QueueBinding) {
-            Queue q = ((QueueBinding) b).getQueue();
-            queues.add(q);
+      if (bindingsForAddress != null) {
+         for (Binding b : bindingsForAddress.getBindings()) {
+            if (b instanceof QueueBinding) {
+               Queue q = ((QueueBinding) b).getQueue();
+               queues.add(q);
+            }
          }
       }
       return queues;
@@ -779,7 +781,7 @@ public class PostOfficeImpl implements PostOffice, 
NotificationListener, Binding
 
    @Override
    public boolean isAddressBound(final SimpleString address) throws Exception {
-      Bindings bindings = getBindingsForAddress(address);
+      Bindings bindings = lookupBindingsForAddress(address);
       return bindings != null && !bindings.getBindings().isEmpty();
    }
 
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
index 51fbe49..521ece3 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
@@ -2999,9 +2999,9 @@ public class QueueImpl extends CriticalComponentImpl 
implements Queue {
       SimpleString expiryAddress = 
addressSettingsRepository.getMatch(address.toString()).getExpiryAddress();
 
       if (expiryAddress != null) {
-         Bindings bindingList = 
postOffice.getBindingsForAddress(expiryAddress);
+         Bindings bindingList = 
postOffice.lookupBindingsForAddress(expiryAddress);
 
-         if (bindingList.getBindings().isEmpty()) {
+         if (bindingList == null || bindingList.getBindings().isEmpty()) {
             
ActiveMQServerLogger.LOGGER.errorExpiringReferencesNoBindings(expiryAddress);
             acknowledge(tx, ref, AckReason.EXPIRED, null);
          } else {
@@ -3027,9 +3027,9 @@ public class QueueImpl extends CriticalComponentImpl 
implements Queue {
                                         final MessageReference ref,
                                         final SimpleString deadLetterAddress) 
throws Exception {
       if (deadLetterAddress != null) {
-         Bindings bindingList = 
postOffice.getBindingsForAddress(deadLetterAddress);
+         Bindings bindingList = 
postOffice.lookupBindingsForAddress(deadLetterAddress);
 
-         if (bindingList.getBindings().isEmpty()) {
+         if (bindingList == null || bindingList.getBindings().isEmpty()) {
             ActiveMQServerLogger.LOGGER.messageExceededMaxDelivery(ref, 
deadLetterAddress);
             ref.acknowledge(tx, AckReason.KILLED, null);
          } else {
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ScaleDownHandler.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ScaleDownHandler.java
index 7585165..db51dcc 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ScaleDownHandler.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ScaleDownHandler.java
@@ -115,16 +115,18 @@ public class ScaleDownHandler {
          // perform a loop per address
          for (SimpleString address : postOffice.getAddresses()) {
             logger.debug("Scaling down address " + address);
-            Bindings bindings = postOffice.getBindingsForAddress(address);
+            Bindings bindings = postOffice.lookupBindingsForAddress(address);
 
             // It will get a list of queues on this address, ordered by the 
number of messages
             Set<Queue> queues = new TreeSet<>(new 
OrderQueueByNumberOfReferencesComparator());
-            for (Binding binding : bindings.getBindings()) {
-               if (binding instanceof LocalQueueBinding) {
-                  Queue queue = ((LocalQueueBinding) binding).getQueue();
-                  // as part of scale down we will cancel any scheduled 
message and pass it to theWhile we scan for the queues we will also cancel any 
scheduled messages and deliver them right away
-                  queue.deliverScheduledMessages();
-                  queues.add(queue);
+            if (bindings != null) {
+               for (Binding binding : bindings.getBindings()) {
+                  if (binding instanceof LocalQueueBinding) {
+                     Queue queue = ((LocalQueueBinding) binding).getQueue();
+                     // as part of scale down we will cancel any scheduled 
message and pass it to theWhile we scan for the queues we will also cancel any 
scheduled messages and deliver them right away
+                     queue.deliverScheduledMessages();
+                     queues.add(queue);
+                  }
                }
             }
 

Reply via email to