本文整理汇总了Java中org.eclipse.paho.client.mqttv3.MqttPersistenceException类的典型用法代码示例。如果您正苦于以下问题:Java MqttPersistenceException类的具体用法?Java MqttPersistenceException怎么用?Java MqttPersistenceException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MqttPersistenceException类属于org.eclipse.paho.client.mqttv3包,在下文中一共展示了MqttPersistenceException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pushMqttStateOffline
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
/**
* This marks the Indego device as offline.
*
* @param mqttClient the connection to use
* @throws MqttPersistenceException
* @throws MqttException
*/
private void pushMqttStateOffline (MqttClient mqttClient) throws MqttPersistenceException, MqttException
{
LOG.info("Pushing offline state to MQTT");
publish(mqttClient, MQTT_TOPIC_ONLINE, false, true);
publish(mqttClient, MQTT_TOPIC_STATE_CODE, 0, RETAINMENT);
publish(mqttClient, MQTT_TOPIC_STATE_MESSAGE, "", RETAINMENT);
publish(mqttClient, MQTT_TOPIC_ERROR_CODE, 0, RETAINMENT);
publish(mqttClient, MQTT_TOPIC_STATE_LEVEL, -2, RETAINMENT);
publish(mqttClient, MQTT_TOPIC_MOWED_PERCENTAGE, 0, RETAINMENT);
publish(mqttClient, MQTT_TOPIC_MAP_SVG_CACHE_TS, 0, RETAINMENT);
publish(mqttClient, MQTT_TOPIC_MAP_UPDATE_AVAILABLE, false, RETAINMENT);
publish(mqttClient, MQTT_TOPIC_MOWED_TS, 0, RETAINMENT);
publish(mqttClient, MQTT_TOPIC_RUNTIME_TOTAL_OPERATE_MINS, 0, RETAINMENT);
publish(mqttClient, MQTT_TOPIC_RUNTIME_TOTAL_CHARGE_MINS, 0, RETAINMENT);
publish(mqttClient, MQTT_TOPIC_RUNTIME_SESSION_OPERATE_MINS, 0, RETAINMENT);
publish(mqttClient, MQTT_TOPIC_RUNTIME_SESSION_CHARGE_MINS, 0, RETAINMENT);
}
示例2: sendKeepAlive
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
/**
* 发送一个心跳包,保持长连接
* @return MqttDeliveryToken specified token you can choose to wait for completion
*/
private synchronized MqttDeliveryToken sendKeepAlive()
throws MqttConnectivityException, MqttPersistenceException, MqttException {
if(!isConnected())
throw new MqttConnectivityException();
if(mKeepAliveTopic == null) {
mKeepAliveTopic = mClient.getTopic(TOPIC);
}
Log.i(DEBUG_TAG,"Sending Keepalive to " + MQTT_BROKER);
MqttMessage message = new MqttMessage(MQTT_KEEP_ALIVE_MESSAGE.getBytes());
message.setQos(MQTT_KEEP_ALIVE_QOS);
/**发送一个心跳包给服务器,然后回调到:messageArrived 方法中*/
return mKeepAliveTopic.publish(message);
}
示例3: get
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
public MqttPersistable get(String key) throws MqttPersistenceException {
checkIsOpen();
MqttPersistable result;
try {
File file = new File(clientDir, key + MESSAGE_FILE_EXTENSION);
FileInputStream fis = new FileInputStream(file);
int size = fis.available();
byte[] data = new byte[size];
int read = 0;
while (read < size) {
read += fis.read(data, read, size - read);
}
fis.close();
result = new MqttPersistentData(key, data, 0, data.length, null, 0, 0);
} catch (IOException ex) {
throw new MqttPersistenceException(ex);
}
return result;
}
示例4: restoreBackups
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
/**
* Identifies any backup files in the specified directory and restores them
* to their original file. This will overwrite any existing file of the same
* name. This is safe as a stray backup file will only exist if a problem
* occured whilst writing to the original file.
*
* @param dir The directory in which to scan and restore backups
*/
private void restoreBackups(File dir) throws MqttPersistenceException {
File[] files = dir.listFiles(new FileFilter() {
public boolean accept(File f) {
return f.getName().endsWith(MESSAGE_BACKUP_FILE_EXTENSION);
}
});
if (files == null) {
throw new MqttPersistenceException();
}
for (int i = 0; i < files.length; i++) {
File originalFile = new File(dir, files[i].getName().substring(0, files[i].getName().length() - MESSAGE_BACKUP_FILE_EXTENSION.length()));
boolean result = files[i].renameTo(originalFile);
if (!result) {
originalFile.delete();
files[i].renameTo(originalFile);
}
}
}
示例5: sendKeepAlive
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
/**
* Sends a Keep Alive message to the specified topic
* @see MQTT_KEEP_ALIVE_MESSAGE
* @see MQTT_KEEP_ALIVE_TOPIC_FORMAT
* @return MqttDeliveryToken specified token you can choose to wait for completion
*/
private synchronized MqttDeliveryToken sendKeepAlive()
throws MqttConnectivityException, MqttPersistenceException, MqttException {
if(!isConnected())
throw new MqttConnectivityException();
if(mKeepAliveTopic == null) {
mKeepAliveTopic = mClient.getTopic(
String.format(Locale.US, MQTT_KEEP_ALIVE_TOPIC_FORAMT,mDeviceId));
}
Log.i(DEBUG_TAG,"Sending Keepalive to " + MQTT_BROKER);
MqttMessage message = new MqttMessage(MQTT_KEEP_ALIVE_MESSAGE);
message.setQos(MQTT_KEEP_ALIVE_QOS);
return mKeepAliveTopic.publish(message);
}
示例6: get
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
public MqttPersistable get(String key) throws MqttPersistenceException {
checkIsOpen();
MqttPersistable result;
try {
File file = new File(clientDir, key+MESSAGE_FILE_EXTENSION);
FileInputStream fis = new FileInputStream(file);
int size = fis.available();
byte[] data = new byte[size];
int read = 0;
while (read<size) {
read += fis.read(data,read,size-read);
}
fis.close();
result = new MqttPersistentData(key, data, 0, data.length, null, 0, 0);
}
catch(IOException ex) {
throw new MqttPersistenceException(ex);
}
return result;
}
示例7: restoreBackups
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
/**
* Identifies any backup files in the specified directory and restores them
* to their original file. This will overwrite any existing file of the same
* name. This is safe as a stray backup file will only exist if a problem
* occured whilst writing to the original file.
* @param dir The directory in which to scan and restore backups
*/
private void restoreBackups(File dir) throws MqttPersistenceException {
File[] files = dir.listFiles(new FileFilter() {
public boolean accept(File f) {
return f.getName().endsWith(MESSAGE_BACKUP_FILE_EXTENSION);
}
});
if (files == null) {
throw new MqttPersistenceException();
}
for (int i=0;i<files.length;i++) {
File originalFile = new File(dir,files[i].getName().substring(0,files[i].getName().length()-MESSAGE_BACKUP_FILE_EXTENSION.length()));
boolean result = files[i].renameTo(originalFile);
if (!result) {
originalFile.delete();
files[i].renameTo(originalFile);
}
}
}
示例8: connect
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
/**
* Start the connect processing
* @throws MqttPersistenceException
*/
public void connect() throws MqttPersistenceException {
MqttToken token = new MqttToken(client.getClientId());
token.setActionCallback(this);
token.setUserContext(this);
persistence.open(client.getClientId(), client.getServerURI());
if (options.isCleanSession()) {
persistence.clear();
}
if (options.getMqttVersion() == MqttConnectOptions.MQTT_VERSION_DEFAULT) {
options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);
}
try {
comms.connect(options, token);
}
catch (MqttException e) {
onFailure(token, e);
}
}
示例9: undo
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
/**
* This removes the MqttSend message from the outbound queue and persistence.
* @param message
* @throws MqttPersistenceException
*/
protected void undo(MqttPublish message) throws MqttPersistenceException {
final String methodName = "undo";
synchronized (queueLock) {
//@TRACE 618=key={0} QoS={1}
log.fine(CLASS_NAME,methodName,"618", new Object[]{new Integer(message.getMessageId()), new Integer(message.getMessage().getQos())});
if (message.getMessage().getQos() == 1) {
outboundQoS1.remove(new Integer(message.getMessageId()));
} else {
outboundQoS2.remove(new Integer(message.getMessageId()));
}
pendingMessages.removeElement(message);
persistence.remove(getSendPersistenceKey(message));
tokenStore.removeToken(message);
checkQuiesceLock();
}
}
示例10: get
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
public MqttPersistable get(String key) throws MqttPersistenceException {
checkIsOpen();
MqttPersistable result;
try {
FileConnection file = (FileConnection) Connector.open(clientDir.getURL() + key + MESSAGE_FILE_EXTENSION);
DataInputStream fis = file.openDataInputStream();
int size = fis.available();
byte[] data = new byte[size];
int read = 0;
while (read<size) {
read += fis.read(data,read,size-read);
}
fis.close();
result = new MqttPersistentData(key, data, 0, data.length, null, 0, 0);
}
catch(IOException ex) {
throw new MqttPersistenceException(ex);
}
return result;
}
示例11: disconnectClient
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
/**
* disconnectClient stops any connectionLost processing that is happening
* and disconnects the TCP/IP socket connection.
* @throws MqttException
*/
public boolean disconnectClient() throws MqttException {
synchronized( connLock ) {
connLockNotified = true;
connLock.notify();
}
try {
wmqttClient.disconnect();
} catch( MqttPersistenceException mqpe ) {
// Persistence is not used
}
connected = false;
return true;
}
示例12: publish
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
private void publish() throws MqttException, MqttPersistenceException {
for (final String otherClient : otherClients) {
final String topic2Mqtt = pubTopic2Mqtt + otherClient + PUBPOSTFIX;
LOG.info("{} publishing \"{}\" to topic {}", clientId, message, topic2Mqtt);
mqttAsyncClient.publish(topic2Mqtt, (LocalDateTime.now() + message).getBytes(), 1, false);
}
final String topic2Kafka = KAFKABASETOPIC.replace("{p}", clientId);
LOG.info("{} publishing \"{}\" to topic {}", clientId, message, topic2Kafka);
mqttAsyncClient.publish(topic2Kafka, (LocalDateTime.now() + message).getBytes(), 1, false);
}
示例13: publish
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
/**
* Publishes a single topic on the MQTT broker
*
* @param mqttClient the broker connection
* @param topic the topic to publish (relative to configured topic root)
* @param data the data to publish
* @param retained if the data should be retained
* @throws MqttPersistenceException
* @throws MqttException
*/
private void publish (MqttClient mqttClient, String topic, String data, boolean retained) throws MqttPersistenceException, MqttException
{
if ( LOG.isDebugEnabled() ) {
LOG.debug(String.format("Publishing '%s' to topic '%s' (retained = %s)", data, topic, retained));
}
MqttMessage msg = new MqttMessage(data.getBytes());
msg.setQos(configuration.getMqttQos());
msg.setRetained(retained);
mqttClient.publish(configuration.getMqttTopicRoot() + topic, msg);
}
示例14: handleCommand
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
private void handleCommand(String command)
throws SparkplugException, MqttPersistenceException, MqttException, IOException {
String [] tokens = command.split(" ");
if (tokens.length > 0) {
String cmd = tokens[0];
if (cmd.equals("")) {
return;
}
if (cmd.equals("?") || cmd.toLowerCase().equals("help")) {
// Help with commands
System.out.println("\nCOMMANDS");
System.out.println(" - rebirth: Publishes a rebirth command to the Edge Node");
System.out.println(" usage: rebirth");
return;
} else if (cmd.toLowerCase().equals("rebirth")) {
// Issue a rebirth
client.publish(NAMESPACE + "/" + groupId + "/NCMD/" + edgeNode,
new SparkplugBPayloadEncoder().getBytes(new SparkplugBPayloadBuilder()
.addMetric(new MetricBuilder("Node Control/Rebirth", MetricDataType.Boolean, true)
.createMetric())
.createPayload()),
0, false);
return;
}
}
System.out.println("\nInvalid command: " + command);
}
示例15: publishClientStatus
import org.eclipse.paho.client.mqttv3.MqttPersistenceException; //导入依赖的package包/类
private void publishClientStatus(Boolean state) throws MqttException,
MqttPersistenceException {
if (!nullOrEmpty(publishClientInfoTopic)) {
client.publish(publishClientInfoTopic, state.toString()
.getBytes(), 0, RETAINED);
}
}