This closes #27 JGroups Close Channel

This commit is contained in:
Clebert Suconic 2015-06-15 00:52:26 -04:00
commit 9687c4003d
4 changed files with 32 additions and 0 deletions

View File

@ -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;

View File

@ -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();
}

View File

@ -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.
}
}

View File

@ -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();
}