From 3710b3aa3c81d3628b3ba4d209cd06d393becf65 Mon Sep 17 00:00:00 2001 From: "John D. Ament" Date: Sun, 14 Jun 2015 19:59:28 -0400 Subject: [PATCH] ARTEMIS-103 Changed JGroupsBroadcastEndpoint to not close its JChannel since its externally managed. Added javadocs to impacted areas to clarify that the JChannel is not closed by these implementations. --- .../api/core/ChannelBroadcastEndpointFactory.java | 5 +++++ .../artemis/api/core/JGroupsBroadcastEndpoint.java | 9 +++++++++ .../api/core/JGroupsChannelBroadcastEndpoint.java | 11 +++++++++++ ...ConnectionFactoryWithJGroupsSerializationTest.java | 7 +++++++ 4 files changed, 32 insertions(+) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/ChannelBroadcastEndpointFactory.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/ChannelBroadcastEndpointFactory.java index a5cfee06ce..69f22deca6 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/ChannelBroadcastEndpointFactory.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/ChannelBroadcastEndpointFactory.java @@ -18,6 +18,11 @@ package org.apache.activemq.artemis.api.core; import org.jgroups.JChannel; +/** + * An implementation of BroadcastEndpointFactory that uses an externally managed JChannel for JGroups clustering. + * + * Note - the underlying JChannel is not closed in this implementation. + */ public class ChannelBroadcastEndpointFactory implements BroadcastEndpointFactory { private final JChannel channel; diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JGroupsBroadcastEndpoint.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JGroupsBroadcastEndpoint.java index d1af49282e..86930956a7 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JGroupsBroadcastEndpoint.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JGroupsBroadcastEndpoint.java @@ -126,6 +126,15 @@ public abstract class JGroupsBroadcastEndpoint implements BroadcastEndpoint channel.removeReceiver(receiver); clientOpened = false; } + internalCloseChannel(); + } + + /** + * Closes the channel used in this JGroups Broadcast. + * Can be overridden by implementations that use an externally managed channel. + */ + protected synchronized void internalCloseChannel() + { channel.close(); } diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JGroupsChannelBroadcastEndpoint.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JGroupsChannelBroadcastEndpoint.java index 5f517d3cd0..cb85b8d418 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JGroupsChannelBroadcastEndpoint.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JGroupsChannelBroadcastEndpoint.java @@ -18,6 +18,11 @@ package org.apache.activemq.artemis.api.core; import org.jgroups.JChannel; +/** + * An implementation of JGroupsBroadcastEndpoint that uses an externally managed JChannel for its operations. + * + * Note - this implementation does not close the JChannel, since its externally created. + */ public class JGroupsChannelBroadcastEndpoint extends JGroupsBroadcastEndpoint { private final JChannel jChannel; @@ -33,4 +38,10 @@ public class JGroupsChannelBroadcastEndpoint extends JGroupsBroadcastEndpoint { return jChannel; } + + @Override + protected synchronized void internalCloseChannel() + { + // no-op, this version takes an externally managed channel. + } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java index be8452f255..4b58ee1ba6 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java @@ -25,6 +25,7 @@ import java.io.Serializable; import javax.jms.Queue; +import org.apache.activemq.artemis.api.core.BroadcastEndpoint; import org.apache.activemq.artemis.api.core.BroadcastEndpointFactory; import org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory; import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration; @@ -171,8 +172,14 @@ public class ConnectionFactoryWithJGroupsSerializationTest extends JMSTestBase @After public void tearDown() throws Exception { + // small hack, the channel here is cached, so checking that it's not closed by any endpoint + BroadcastEndpoint broadcastEndpoint = jmsServer.getActiveMQServer().getConfiguration() + .getDiscoveryGroupConfigurations().get("dg1") + .getBroadcastEndpointFactory().createBroadcastEndpoint(); + broadcastEndpoint.close(true); if (channel != null) { + assertFalse(channel.isClosed()); channel.close(); }