NO-JIRA close connection factory in CLI

Fix warning seen in logs during test case runs, caused by CF not being closed.

Oct 10, 2018 8:53:18 PM org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl finalize
WARN: AMQ212008: I am closing a core ClientSessionFactory you left open. Please make sure you close all ClientSessionFactories explicitly before letting them go out of scope! 639,542,871
java.lang.Exception
	at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.<init>(ClientSessionFactoryImpl.java:171)
	at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:779)
	at org.apache.activemq.artemis.cli.commands.messages.DestAbstract.getManagementSession(DestAbstract.java:103)
	at org.apache.activemq.artemis.cli.commands.messages.DestAbstract.getQueueAttribute(DestAbstract.java:127)
	at org.apache.activemq.artemis.cli.commands.messages.DestAbstract.getQueueIdFromName(DestAbstract.java:116)
	at org.apache.activemq.artemis.cli.commands.messages.Producer.execute(Producer.java:75)
	at org.apache.activemq.artemis.cli.Artemis.internalExecute(Artemis.java:150)
	at org.apache.activemq.artemis.cli.Artemis.execute(Artemis.java:98)
	at org.apache.activemq.artemis.cli.Artemis.execute(Artemis.java:125)
	at org.apache.activemq.artemis.cli.Artemis.main(Artemis.java:81)
This commit is contained in:
Michael André Pearce 2018-10-10 22:11:21 +01:00 committed by Clebert Suconic
parent a65374fe28
commit 50f6bb5d07
3 changed files with 14 additions and 2 deletions

View File

@ -69,6 +69,10 @@ public class Browse extends DestAbstract {
} }
return received; return received;
} finally {
if (factory instanceof AutoCloseable) {
((AutoCloseable) factory).close();
}
} }
} }

View File

@ -55,8 +55,6 @@ public class Consumer extends DestAbstract {
System.out.println("Consumer:: filter = " + filter); System.out.println("Consumer:: filter = " + filter);
ConnectionFactory factory = createConnectionFactory();
SerialiserMessageListener listener = null; SerialiserMessageListener listener = null;
MessageSerializer messageSerializer = null; MessageSerializer messageSerializer = null;
if (file != null) { if (file != null) {
@ -83,6 +81,8 @@ public class Consumer extends DestAbstract {
if (messageSerializer != null) messageSerializer.start(); if (messageSerializer != null) messageSerializer.start();
ConnectionFactory factory = createConnectionFactory();
try (Connection connection = factory.createConnection()) { try (Connection connection = factory.createConnection()) {
// We read messages in a single thread when persisting to file. // We read messages in a single thread when persisting to file.
ConsumerThread[] threadsArray = new ConsumerThread[threads]; ConsumerThread[] threadsArray = new ConsumerThread[threads];
@ -118,6 +118,10 @@ public class Consumer extends DestAbstract {
if (messageSerializer != null) messageSerializer.stop(); if (messageSerializer != null) messageSerializer.stop();
return received; return received;
} finally {
if (factory instanceof AutoCloseable) {
((AutoCloseable) factory).close();
}
} }
} }

View File

@ -137,6 +137,10 @@ public class Producer extends DestAbstract {
} }
return messagesProduced; return messagesProduced;
} }
} finally {
if (factory instanceof AutoCloseable) {
((AutoCloseable) factory).close();
}
} }
} }