11/*******************************************************************************
2- * Copyright (c) 2009, 2015 IBM Corp.
2+ * Copyright (c) 2009, 2019 IBM Corp.
33 *
44 * All rights reserved. This program and the accompanying materials
55 * are made available under the terms of the Eclipse Public License v1.0
7676 *
7777 * @see IMqttClient
7878 */
79- public class MqttLegacyBlockingClient implements IMqttClient {
79+ public class MqttClient implements IMqttClient {
8080
8181 protected MqttAsyncClient aClient = null ; // Delegate implementation to MqttAsyncClient
8282 protected long timeToWait = -1 ; // How long each method should wait for action to complete
@@ -168,7 +168,7 @@ public class MqttLegacyBlockingClient implements IMqttClient {
168168 * @throws MqttException
169169 * if any other problem was encountered
170170 */
171- public MqttLegacyBlockingClient (String serverURI , String clientId ) throws MqttException {
171+ public MqttClient (String serverURI , String clientId ) throws MqttException {
172172 this (serverURI , clientId , new MqttDefaultFilePersistence ());
173173 }
174174
@@ -275,7 +275,7 @@ public MqttLegacyBlockingClient(String serverURI, String clientId) throws MqttEx
275275 * @throws MqttException
276276 * if any other problem was encountered
277277 */
278- public MqttLegacyBlockingClient (String serverURI , String clientId , MqttClientPersistence persistence )
278+ public MqttClient (String serverURI , String clientId , MqttClientPersistence persistence )
279279 throws MqttException {
280280 aClient = new MqttAsyncClient (serverURI , clientId , persistence );
281281 }
@@ -386,7 +386,7 @@ public MqttLegacyBlockingClient(String serverURI, String clientId, MqttClientPer
386386 * @throws MqttException
387387 * if any other problem was encountered
388388 */
389- public MqttLegacyBlockingClient (String serverURI , String clientId , MqttClientPersistence persistence ,
389+ public MqttClient (String serverURI , String clientId , MqttClientPersistence persistence ,
390390 ScheduledExecutorService executorService ) throws MqttException {
391391 aClient = new MqttAsyncClient (serverURI , clientId , persistence , null , executorService );
392392 }
@@ -516,13 +516,26 @@ public void subscribe(MqttSubscription[] subscriptions) throws MqttException {
516516 int [] grantedQos = tok .getGrantedQos ();
517517 for (int i = 0 ; i < grantedQos .length ; ++i ) {
518518 subscriptions [i ].setQos (grantedQos [i ]);
519- ;
520519 }
521520 if (grantedQos .length == 1 && subscriptions [0 ].getQos () == 0x80 ) {
522521 throw new MqttException (MqttClientException .REASON_CODE_SUBSCRIBE_FAILED );
523522 }
524523 }
525524
525+ @ Override
526+ public void subscribe (String [] topicFilters , int [] qos ) throws MqttException {
527+ if (topicFilters .length != qos .length ) {
528+ throw new MqttException (MqttClientException .REASON_CODE_UNEXPECTED_ERROR );
529+ }
530+
531+ MqttSubscription [] subscriptions = new MqttSubscription [topicFilters .length ];
532+ for (int i = 0 ; i < topicFilters .length ; ++i ) {
533+ subscriptions [i ] = new MqttSubscription (topicFilters [i ], qos [i ]);
534+ }
535+
536+ this .subscribe (subscriptions );
537+ }
538+
526539 /*
527540 * (non-Javadoc)
528541 *
@@ -533,11 +546,6 @@ public void subscribe(String topicFilter, IMqttMessageListener messageListener)
533546 this .subscribe (new String [] { topicFilter }, new int [] { 1 }, new IMqttMessageListener [] { messageListener });
534547 }
535548
536- @ Override
537- public void subscribe (String [] topicFilters , IMqttMessageListener messageListener ) throws MqttException {
538- this .subscribe (topicFilters , new IMqttMessageListener [] { messageListener });
539- }
540-
541549 /*
542550 * (non-Javadoc)
543551 *
@@ -562,10 +570,6 @@ public void subscribe(String topicFilter, int qos, IMqttMessageListener messageL
562570 this .subscribe (new String [] { topicFilter }, new int [] { qos }, new IMqttMessageListener [] { messageListener });
563571 }
564572
565- @ Override
566- public void subscribe (String [] topicFilters , int [] qos ) throws MqttException {
567- this .subscribe (topicFilters , qos , new IMqttMessageListener [] {});
568- }
569573
570574 public void subscribe (String [] topicFilters , int [] qos , IMqttMessageListener [] messageListeners )
571575 throws MqttException {
@@ -673,7 +677,7 @@ public void setTimeToWait(long timeToWaitInMillis) throws IllegalArgumentExcepti
673677 * Return the maximum time to wait for an action to complete.
674678 *
675679 * @return the time to wait
676- * @see MqttLegacyBlockingClient #setTimeToWait(long)
680+ * @see MqttClient #setTimeToWait(long)
677681 */
678682 public long getTimeToWait () {
679683 return this .timeToWait ;
0 commit comments