@@ -76,6 +76,8 @@ public class Mqtt5Canary {
7676
7777 static int operationFutureWaitTime = 30 ;
7878
79+ static byte [] payload_bytes ;
80+
7981 private static final int MAX_PAYLOAD_SIZE = 65535 ; // Use UINT64_MAX for the payload size
8082 private static final long MEMORY_CHECK_INTERVAL_SECONDS = 600 ; // 10 minutes
8183
@@ -433,15 +435,6 @@ public static void OperationStart(int clientIdx) {
433435 clientsData .get (clientIdx ).isWaitingForOperation = true ;
434436 // PrintLog("[OP] About to start client ID " + clientIdx);
435437 client .start ();
436- try {
437- clientsData .get (clientIdx ).connectedFuture .get (operationFutureWaitTime , TimeUnit .SECONDS );
438- } catch (Exception ex ) {
439- // PrintLog("[OP] Start had an exception! Exception: " + ex);
440- ex .printStackTrace ();
441- if (configFilePrinter != null ) {
442- ex .printStackTrace (configFilePrinter );
443- }
444- }
445438 // PrintLog("[OP] Started client ID " + clientIdx);
446439 clientsData .get (clientIdx ).isWaitingForOperation = false ;
447440 }
@@ -492,15 +485,9 @@ public static void OperationSubscribe(int clientIdx) {
492485 SubscribePacketBuilder subscribePacketBuilder = new SubscribePacketBuilder ();
493486 subscribePacketBuilder .withSubscription (clientsData .get (clientIdx ).clientId , QOS .AT_LEAST_ONCE );
494487 subscribePacketBuilder .withSubscription (clientsData .get (clientIdx ).sharedTopic , QOS .AT_LEAST_ONCE );
495- try {
496- client .subscribe (subscribePacketBuilder .build ());
497- } catch (Exception ex ) {
498- // PrintLog("[OP] Subscribe had an exception! Exception: " + ex);
499- ex .printStackTrace ();
500- if (configFilePrinter != null ) {
501- ex .printStackTrace (configFilePrinter );
502- }
503- }
488+
489+ client .subscribe (subscribePacketBuilder .build ());
490+
504491 clientsData .get (clientIdx ).subscribedToTopics = true ;
505492 // PrintLog("[OP] Subscribed client ID " + clientIdx);
506493 clientsData .get (clientIdx ).isWaitingForOperation = false ;
@@ -527,10 +514,6 @@ public static void OperationUnsubscribe(int clientIdx) {
527514 unsubscribePacketBuilder .withSubscription (clientsData .get (clientIdx ).sharedTopic );
528515 client .unsubscribe (unsubscribePacketBuilder .build ());
529516 // PrintLog("[OP] Unsubscribe had an exception! Exception: " + ex);
530- ex .printStackTrace ();
531- if (configFilePrinter != null ) {
532- ex .printStackTrace (configFilePrinter );
533- }
534517 clientsData .get (clientIdx ).subscribedToTopics = false ;
535518 // PrintLog("[OP] Unsubscribed client ID " + clientIdx);
536519 clientsData .get (clientIdx ).isWaitingForOperation = false ;
@@ -550,15 +533,7 @@ public static void OperationUnsubscribeBad(int clientIdx) {
550533 clientsData .get (clientIdx ).isWaitingForOperation = true ;
551534 // PrintLog("[OP] About to unsubscribe (bad) client ID " + clientIdx);
552535 UnsubscribePacketBuilder unsubscribePacketBuilder = new UnsubscribePacketBuilder ("Non_existent_topic_here" );
553- try {
554- client .unsubscribe (unsubscribePacketBuilder .build ());
555- } catch (Exception ex ) {
556- // PrintLog("[OP] Unsubscribe (bad) had an exception! Exception: " + ex);
557- ex .printStackTrace ();
558- if (configFilePrinter != null ) {
559- ex .printStackTrace (configFilePrinter );
560- }
561- }
536+ client .unsubscribe (unsubscribePacketBuilder .build ());
562537 // PrintLog("[OP] Unsubscribed (bad) client ID " + clientIdx);
563538 clientsData .get (clientIdx ).isWaitingForOperation = false ;
564539 }
@@ -578,12 +553,6 @@ public static void OperationPublish(int clientIdx, QOS qos, String topic) {
578553 clientsData .get (clientIdx ).isWaitingForOperation = true ;
579554 // PrintLog("[OP] About to publish client ID " + clientIdx + " with QoS " + qos + " with topic " + topic);
580555
581- int payload_size = random .nextInt (MAX_PAYLOAD_SIZE );
582- byte [] payload_bytes = new byte [payload_size ];
583- for (int i = 0 ; i < payload_size ; i ++) {
584- payload_bytes [i ] = (byte )random .nextInt (128 );
585- }
586-
587556 PublishPacketBuilder publishPacketBuilder = new PublishPacketBuilder (topic , qos , payload_bytes );
588557
589558 // Add user properties!
@@ -593,15 +562,9 @@ public static void OperationPublish(int clientIdx, QOS qos, String topic) {
593562 propertyList .add (new UserProperty ("red" , "blue" ));
594563 publishPacketBuilder .withUserProperties (propertyList );
595564
596- try {
597- client .publish (publishPacketBuilder .build ());
598- } catch (Exception ex ) {
599- // PrintLog("[OP] Publish with QoS " + qos + " with topic " + topic + " had an exception! Exception: " + ex);
600- ex .printStackTrace ();
601- if (configFilePrinter != null ) {
602- ex .printStackTrace (configFilePrinter );
603- }
604- }
565+
566+ client .publish (publishPacketBuilder .build ());
567+
605568 // PrintLog("[OP] Published client ID " + clientIdx + " with QoS " + qos + " with topic " + topic);
606569 clientsData .get (clientIdx ).isWaitingForOperation = false ;
607570 }
@@ -689,6 +652,12 @@ public static void main(String[] args) {
689652
690653 System .out .println ("Setting up Canary..." );
691654
655+ int payload_size = random .nextInt (MAX_PAYLOAD_SIZE );
656+ payload_bytes = new byte [payload_size ];
657+ for (int i = 0 ; i < payload_size ; i ++) {
658+ payload_bytes [i ] = (byte )random .nextInt (128 );
659+ }
660+
692661 // Setup
693662 // ====================
694663 parseCommandLine (args );
0 commit comments