package org.eclipse.paho.mqttv5.client;

import java.util.concurrent.ScheduledExecutorService;
import org.eclipse.paho.mqttv5.client.persist.MqttDefaultFilePersistence;
import org.eclipse.paho.mqttv5.client.util.Debug;
import org.eclipse.paho.mqttv5.common.MqttException;
import org.eclipse.paho.mqttv5.common.MqttMessage;
import org.eclipse.paho.mqttv5.common.MqttSubscription;
import org.eclipse.paho.mqttv5.common.packet.MqttProperties;

/* JADX INFO: loaded from: classes2.dex */
public class MqttClient implements IMqttClient {
    protected MqttAsyncClient aClient;
    protected long timeToWait;

    public MqttClient(String str, String str2) throws MqttException {
        this(str, str2, new MqttDefaultFilePersistence());
    }

    public MqttClient(String str, String str2, MqttClientPersistence mqttClientPersistence) throws MqttException {
        this.aClient = null;
        this.timeToWait = -1L;
        this.aClient = new MqttAsyncClient(str, str2, mqttClientPersistence);
    }

    public MqttClient(String str, String str2, MqttClientPersistence mqttClientPersistence, ScheduledExecutorService scheduledExecutorService) throws MqttException {
        this.aClient = null;
        this.timeToWait = -1L;
        this.aClient = new MqttAsyncClient(str, str2, mqttClientPersistence, null, scheduledExecutorService);
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void connect() throws MqttException {
        connect(new MqttConnectionOptions());
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void connect(MqttConnectionOptions mqttConnectionOptions) throws MqttException {
        this.aClient.connect(mqttConnectionOptions, null, null).waitForCompletion(getTimeToWait());
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public IMqttToken connectWithResult(MqttConnectionOptions mqttConnectionOptions) throws MqttException {
        IMqttToken iMqttTokenConnect = this.aClient.connect(mqttConnectionOptions, null, null);
        iMqttTokenConnect.waitForCompletion(getTimeToWait());
        return iMqttTokenConnect;
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void disconnect() throws MqttException {
        this.aClient.disconnect().waitForCompletion();
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void disconnect(long j) throws MqttException {
        this.aClient.disconnect(j, null, null, 0, new MqttProperties()).waitForCompletion();
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void disconnectForcibly() throws MqttException {
        this.aClient.disconnectForcibly();
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void disconnectForcibly(long j) throws MqttException {
        this.aClient.disconnectForcibly(j);
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void disconnectForcibly(long j, long j2) throws MqttException {
        this.aClient.disconnectForcibly(j, j2, 0, new MqttProperties());
    }

    public void disconnectForcibly(long j, long j2, boolean z) throws MqttException {
        this.aClient.disconnectForcibly(j, j2, z);
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public IMqttToken subscribe(String str, int i) throws MqttException {
        return subscribe(new String[]{str}, new int[]{i});
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public IMqttToken subscribe(String[] strArr, int[] iArr) throws MqttException {
        if (strArr.length != iArr.length) {
            throw new MqttException(6);
        }
        MqttSubscription[] mqttSubscriptionArr = new MqttSubscription[strArr.length];
        for (int i = 0; i < strArr.length; i++) {
            mqttSubscriptionArr[i] = new MqttSubscription(strArr[i], iArr[i]);
        }
        return subscribe(mqttSubscriptionArr);
    }

    public IMqttToken subscribe(MqttSubscription[] mqttSubscriptionArr) throws MqttException {
        return subscribe(mqttSubscriptionArr, (IMqttMessageListener[]) null);
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public IMqttToken subscribe(String str, int i, IMqttMessageListener iMqttMessageListener) throws MqttException {
        return subscribe(new String[]{str}, new int[]{i}, new IMqttMessageListener[]{iMqttMessageListener});
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public IMqttToken subscribe(String[] strArr, int[] iArr, IMqttMessageListener[] iMqttMessageListenerArr) throws MqttException {
        return subscribe(strArr, iArr, iMqttMessageListenerArr);
    }

    public IMqttToken subscribe(MqttSubscription[] mqttSubscriptionArr, IMqttMessageListener[] iMqttMessageListenerArr) throws Exception {
        IMqttToken iMqttTokenSubscribe = this.aClient.subscribe(mqttSubscriptionArr, (Object) null, (MqttActionListener) null, iMqttMessageListenerArr, new MqttProperties());
        iMqttTokenSubscribe.waitForCompletion(getTimeToWait());
        return iMqttTokenSubscribe;
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void unsubscribe(String str) throws MqttException {
        unsubscribe(new String[]{str});
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void unsubscribe(String[] strArr) throws MqttException {
        this.aClient.unsubscribe(strArr, null, null, new MqttProperties()).waitForCompletion(getTimeToWait());
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void publish(String str, byte[] bArr, int i, boolean z) throws MqttException {
        MqttMessage mqttMessage = new MqttMessage(bArr);
        mqttMessage.setQos(i);
        mqttMessage.setRetained(z);
        publish(str, mqttMessage);
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void publish(String str, MqttMessage mqttMessage) throws MqttException {
        this.aClient.publish(str, mqttMessage, (Object) null, (MqttActionListener) null).waitForCompletion(getTimeToWait());
    }

    public void setTimeToWait(long j) throws IllegalArgumentException {
        if (j < -1) {
            throw new IllegalArgumentException();
        }
        this.timeToWait = j;
    }

    public long getTimeToWait() {
        return this.timeToWait;
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void close() throws MqttException {
        this.aClient.close(false);
    }

    public void close(boolean z) throws MqttException {
        this.aClient.close(z);
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public String getClientId() {
        return this.aClient.getClientId();
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public IMqttToken[] getPendingTokens() {
        return this.aClient.getPendingTokens();
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public String getServerURI() {
        return this.aClient.getServerURI();
    }

    public String getCurrentServerURI() {
        return this.aClient.getCurrentServerURI();
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public MqttTopic getTopic(String str) {
        return this.aClient.getTopic(str);
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public boolean isConnected() {
        return this.aClient.isConnected();
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void setCallback(MqttCallback mqttCallback) {
        this.aClient.setCallback(mqttCallback);
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void setManualAcks(boolean z) {
        this.aClient.setManualAcks(z);
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void messageArrivedComplete(int i, int i2) throws MqttException {
        this.aClient.messageArrivedComplete(i, i2);
    }

    @Override // org.eclipse.paho.mqttv5.client.IMqttClient
    public void reconnect() throws MqttException {
        this.aClient.reconnect();
    }

    public Debug getDebug() {
        return this.aClient.getDebug();
    }
}
