@@ -897,18 +897,21 @@ public IMqttToken subscribe(String[] topicFilters, int[] qos, Object userContext
897897 this .comms .removeMessageListener (topicFilters [i ]);
898898 }
899899
900- StringBuffer subs = new StringBuffer ();
901- for (int i =0 ;i <topicFilters .length ;i ++) {
902- if (i >0 ) {
903- subs .append (", " );
900+ // Only Generate Log string if we are logging at FINE level
901+ if (log .isLoggable (Logger .FINE )){
902+ StringBuffer subs = new StringBuffer ();
903+ for (int i =0 ;i <topicFilters .length ;i ++) {
904+ if (i >0 ) {
905+ subs .append (", " );
906+ }
907+ subs .append ("topic=" ).append (topicFilters [i ]).append (" qos=" ).append (qos [i ]);
908+
909+ //Check if the topic filter is valid before subscribing
910+ MqttTopic .validate (topicFilters [i ], true /*allow wildcards*/ );
904911 }
905- subs .append ("topic=" ).append (topicFilters [i ]).append (" qos=" ).append (qos [i ]);
906-
907- //Check if the topic filter is valid before subscribing
908- MqttTopic .validate (topicFilters [i ], true /*allow wildcards*/ );
912+ //@TRACE 106=Subscribe topicFilter={0} userContext={1} callback={2}
913+ log .fine (CLASS_NAME ,methodName ,"106" ,new Object []{subs .toString (), userContext , callback });
909914 }
910- //@TRACE 106=Subscribe topicFilter={0} userContext={1} callback={2}
911- log .fine (CLASS_NAME ,methodName ,"106" ,new Object []{subs .toString (), userContext , callback });
912915
913916 MqttToken token = new MqttToken (getClientId ());
914917 token .setActionCallback (callback );
@@ -988,22 +991,30 @@ public IMqttToken unsubscribe(String[] topicFilters) throws MqttException {
988991 */
989992 public IMqttToken unsubscribe (String [] topicFilters , Object userContext , IMqttActionListener callback ) throws MqttException {
990993 final String methodName = "unsubscribe" ;
991- String subs = "" ;
992- for (int i =0 ;i <topicFilters .length ;i ++) {
993- if (i >0 ) {
994- subs +=", " ;
994+
995+ // Only Generate Log string if we are logging at FINE level
996+ if (log .isLoggable (Logger .FINE )){
997+ String subs = "" ;
998+ for (int i =0 ;i <topicFilters .length ;i ++) {
999+ if (i >0 ) {
1000+ subs +=", " ;
1001+ }
1002+ subs +=topicFilters [i ];
9951003 }
996- subs +=topicFilters [i ];
9971004
1005+ //@TRACE 107=Unsubscribe topic={0} userContext={1} callback={2}
1006+ log .fine (CLASS_NAME , methodName ,"107" ,new Object []{subs , userContext , callback });
1007+ }
1008+
1009+ for (int i =0 ;i <topicFilters .length ;i ++) {
9981010 // Check if the topic filter is valid before unsubscribing
9991011 // Although we already checked when subscribing, but invalid
10001012 // topic filter is meanless for unsubscribing, just prohibit it
10011013 // to reduce unnecessary control packet send to broker.
10021014 MqttTopic .validate (topicFilters [i ], true /*allow wildcards*/ );
10031015 }
10041016
1005- //@TRACE 107=Unsubscribe topic={0} userContext={1} callback={2}
1006- log .fine (CLASS_NAME , methodName ,"107" ,new Object []{subs , userContext , callback });
1017+
10071018
10081019 // remove message handlers from the list for this client
10091020 for (int i = 0 ; i < topicFilters .length ; ++i ) {
0 commit comments