2828import com .rabbitmq .perf .metrics .PerformanceMetrics ;
2929import io .micrometer .core .instrument .simple .SimpleMeterRegistry ;
3030import java .io .IOException ;
31+ import java .io .PrintStream ;
3132import java .net .URISyntaxException ;
3233import java .security .KeyManagementException ;
3334import java .security .NoSuchAlgorithmException ;
@@ -80,6 +81,7 @@ public class MulticastSet {
8081 private final ConnectionCreator connectionCreator ;
8182 private final ExpectedMetrics expectedMetrics ;
8283 private final InstanceSynchronization instanceSynchronization ;
84+ private final PrintStream out ;
8385
8486 public MulticastSet (
8587 PerformanceMetrics performanceMetrics ,
@@ -167,6 +169,7 @@ public MulticastSet(
167169 this .connectionCreator = new ConnectionCreator (this .factory , this .uris , connectionAllocation );
168170 this .expectedMetrics = expectedMetrics ;
169171 this .instanceSynchronization = instanceSynchronization ;
172+ this .out = params .getOut ();
170173 }
171174
172175 protected static int nbThreadsForConsumer (MulticastParams params ) {
@@ -233,10 +236,17 @@ public void run(boolean announceStartup)
233236 : params .getServersUpLimit (),
234237 uris ,
235238 factory )) {
236- ScheduledExecutorService heartbeatSenderExecutorService =
237- this .threadingHandler .scheduledExecutorService (
238- "perf-test-heartbeat-sender-" , this .params .getHeartbeatSenderThreads ());
239- factory .setHeartbeatExecutor (heartbeatSenderExecutorService );
239+ // heartbeat sender executor not necessary with Netty
240+ if (!params .netty ()) {
241+ ScheduledExecutorService heartbeatSenderExecutorService =
242+ this .threadingHandler .scheduledExecutorService (
243+ "perf-test-heartbeat-sender-" , this .params .getHeartbeatSenderThreads ());
244+ factory .setHeartbeatExecutor (heartbeatSenderExecutorService );
245+ if (heartbeatSenderExecutorService != null ) {
246+ shutdownService .wrap (heartbeatSenderExecutorService ::shutdownNow );
247+ }
248+ }
249+
240250 // use a single-threaded executor for the configuration connection
241251 // this way, a default one is not created and this one will shut down
242252 // when the run ends.
@@ -382,7 +392,7 @@ public void run(boolean announceStartup)
382392
383393 executeShutdownSequence .run ();
384394 } else {
385- System . out .println (
395+ out .println (
386396 "Could not connect to broker(s) in "
387397 + params .getServersStartUpTimeout ()
388398 + " second(s), exiting." );
@@ -475,7 +485,7 @@ private void createConsumers(
475485 int consumerIndex = 0 ;
476486 for (int i = 0 ; i < consumerConnections .length ; i ++) {
477487 if (announceStartup ) {
478- System . out .println ("id: " + testID + ", starting consumer #" + i );
488+ out .println ("id: " + testID + ", starting consumer #" + i );
479489 }
480490 ExecutorService executorService = consumersExecutorsFactory .apply (i );
481491 factory .setSharedExecutor (executorService );
@@ -484,7 +494,7 @@ private void createConsumers(
484494 consumerConnections [i ] = consumerConnection ;
485495 for (int j = 0 ; j < params .getConsumerChannelCount (); j ++) {
486496 if (announceStartup ) {
487- System . out .println ("id: " + testID + ", starting consumer #" + i + ", channel #" + j );
497+ out .println ("id: " + testID + ", starting consumer #" + i + ", channel #" + j );
488498 }
489499 Consumer consumer =
490500 params .createConsumer (
@@ -507,13 +517,13 @@ private void createProducers(
507517 int producerIndex = 0 ;
508518 for (int i = 0 ; i < producerConnections .length ; i ++) {
509519 if (announceStartup ) {
510- System . out .println ("id: " + testID + ", starting producer #" + i );
520+ out .println ("id: " + testID + ", starting producer #" + i );
511521 }
512522 Connection producerConnection = createConnection (PRODUCER_THREAD_PREFIX + i );
513523 producerConnections [i ] = producerConnection ;
514524 for (int j = 0 ; j < params .getProducerChannelCount (); j ++) {
515525 if (announceStartup ) {
516- System . out .println ("id: " + testID + ", starting producer #" + i + ", channel #" + j );
526+ out .println ("id: " + testID + ", starting producer #" + i + ", channel #" + j );
517527 }
518528 AgentState agentState = new AgentState ();
519529 agentState .runnable =
@@ -538,7 +548,7 @@ private void startConsumers(Runnable[] consumerRunnables) throws InterruptedExce
538548 runnable .run ();
539549 LOGGER .debug ("Consumer runnable started" );
540550 if (params .getConsumerSlowStart ()) {
541- System . out .println ("Delaying start by 1 second because -S/--slow-start was requested" );
551+ out .println ("Delaying start by 1 second because -S/--slow-start was requested" );
542552 Thread .sleep (1000 );
543553 }
544554 }
@@ -551,8 +561,7 @@ private void startConsumers(Runnable[] consumerRunnables) throws InterruptedExce
551561 for (Runnable runnable : consumerRunnables ) {
552562 runnable .run ();
553563 if (params .getConsumerSlowStart ()) {
554- System .out .println (
555- "Delaying start by 1 second because -S/--slow-start was requested" );
564+ out .println ("Delaying start by 1 second because -S/--slow-start was requested" );
556565 try {
557566 Thread .sleep (1000 );
558567 } catch (InterruptedException e ) {
0 commit comments