From 3bcea4e78e4d98e4e7a7c8aefd6378c6716e84cb Mon Sep 17 00:00:00 2001 From: brusdev Date: Thu, 21 May 2020 21:56:17 +0200 Subject: [PATCH] ARTEMIS-2774 Remove the divert transformer on divert destroying --- .../apache/activemq/artemis/core/server/ServiceRegistry.java | 2 ++ .../artemis/core/server/impl/ActiveMQServerImpl.java | 4 ++++ .../artemis/core/server/impl/ServiceRegistryImpl.java | 5 +++++ .../artemis/tests/integration/divert/DivertTest.java | 3 +++ 4 files changed, 14 insertions(+) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServiceRegistry.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServiceRegistry.java index 487bb6298a..32d2fcc0b7 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServiceRegistry.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServiceRegistry.java @@ -98,6 +98,8 @@ public interface ServiceRegistry { void addDivertTransformer(String name, Transformer transformer); + void removeDivertTransformer(String name); + /** * Get an instance of org.apache.activemq.artemis.core.server.transformer.Transformer for a bridge * diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index 003e6e1de9..1f3413bfc9 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -2595,6 +2595,10 @@ public class ActiveMQServerImpl implements ActiveMQServer { } postOffice.removeBinding(name, null, true); + + if (((DivertBinding)binding).getDivert().getTransformer() != null) { + getServiceRegistry().removeDivertTransformer(name.toString()); + } } @Override diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServiceRegistryImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServiceRegistryImpl.java index 7161a68ba2..601c90c04d 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServiceRegistryImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServiceRegistryImpl.java @@ -156,6 +156,11 @@ public class ServiceRegistryImpl implements ServiceRegistry { divertTransformers.put(name, transformer); } + @Override + public void removeDivertTransformer(String name) { + divertTransformers.remove(name); + } + @Override public Transformer getDivertTransformer(String name, TransformerConfiguration transformerConfiguration) { Transformer transformer = divertTransformers.get(name); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/divert/DivertTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/divert/DivertTest.java index fb5dd81f2d..3ee1049902 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/divert/DivertTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/divert/DivertTest.java @@ -1461,5 +1461,8 @@ public class DivertTest extends ActiveMQTestBase { } assertNotNull(divert); assertEquals(transformer, divert.getTransformer()); + + server.destroyDivert(SimpleString.toSimpleString(DIVERT)); + assertNull(serviceRegistry.getDivertTransformer(DIVERT, null)); } }