當前位置: 首頁>>代碼示例>>Java>>正文


Java MqttConnectOptions.getWillMessage方法代碼示例

本文整理匯總了Java中org.eclipse.paho.client.mqttv3.MqttConnectOptions.getWillMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java MqttConnectOptions.getWillMessage方法的具體用法?Java MqttConnectOptions.getWillMessage怎麽用?Java MqttConnectOptions.getWillMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.paho.client.mqttv3.MqttConnectOptions的用法示例。


在下文中一共展示了MqttConnectOptions.getWillMessage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getValues

import org.eclipse.paho.client.mqttv3.MqttConnectOptions; //導入方法依賴的package包/類
private ContentValues getValues(Connection connection){
    MqttConnectOptions conOpts = connection.getConnectionOptions();
    MqttMessage lastWill = conOpts.getWillMessage();
    ContentValues values = new ContentValues();

    //put the column values object
    values.put(COLUMN_CLIENT_HANDLE, connection.handle());
    values.put(COLUMN_HOST, connection.getHostName());
    values.put(COLUMN_port, connection.getPort());
    values.put(COLUMN_client_ID, connection.getId());
    values.put(COLUMN_ssl, connection.isSSL());

    values.put(COLUMN_KEEP_ALIVE, conOpts.getKeepAliveInterval());
    values.put(COLUMN_TIME_OUT, conOpts.getConnectionTimeout());
    values.put(COLUMN_USER_NAME, conOpts.getUserName());
    values.put(COLUMN_TOPIC, conOpts.getWillDestination());

    //uses "condition ? trueValue: falseValue" for in line converting of values
    char[] password = conOpts.getPassword();
    values.put(COLUMN_CLEAN_SESSION, conOpts.isCleanSession() ? 1 : 0); //convert boolean to int and then put in values
    values.put(COLUMN_PASSWORD, password != null ? String.valueOf(password) : null); //convert char[] to String
    values.put(COLUMN_MESSAGE, lastWill != null ? new String(lastWill.getPayload()) : null); // convert byte[] to string
    values.put(COLUMN_QOS, lastWill != null ? lastWill.getQos() : 0);

    if (lastWill == null) {
        values.put(COLUMN_RETAINED, 0);
    }
    else {
        values.put(COLUMN_RETAINED, lastWill.isRetained() ? 1 : 0); //convert from boolean to int
    }
    return values;
}
 
開發者ID:Cirrus-Link,項目名稱:Sparkplug,代碼行數:33,代碼來源:Persistence.java


注:本文中的org.eclipse.paho.client.mqttv3.MqttConnectOptions.getWillMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。