当前位置: 首页>>代码示例>>Java>>正文


Java MqttPersistenceException类代码示例

本文整理汇总了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);
}
 
开发者ID:zazaz-de,项目名称:iot-device-bosch-indego-controller,代码行数:26,代码来源:MqttIndegoAdapter.java

示例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);
}
 
开发者ID:LiuJunb,项目名称:HelloMQTT,代码行数:21,代码来源:MQService.java

示例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;
}
 
开发者ID:longkerdandy,项目名称:chii2mqtt,代码行数:20,代码来源:MqttDefaultFilePersistence.java

示例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);
        }
    }
}
 
开发者ID:longkerdandy,项目名称:chii2mqtt,代码行数:28,代码来源:MqttDefaultFilePersistence.java

示例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);
}
 
开发者ID:JesseFarebro,项目名称:android-mqtt,代码行数:24,代码来源:MqttService.java

示例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;
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:21,代码来源:MqttDefaultFilePersistence.java

示例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);
		}
	}
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:27,代码来源:MqttDefaultFilePersistence.java

示例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);
  }
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:27,代码来源:ConnectActionListener.java

示例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();
	}
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:23,代码来源:ClientState.java

示例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;
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:21,代码来源:MqttDefaultMicroFilePersistence.java

示例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;
  }
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:22,代码来源:WmqttMgr.java

示例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);
}
 
开发者ID:dcsolutions,项目名称:kalinka,代码行数:11,代码来源:MqttClient.java

示例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);
}
 
开发者ID:zazaz-de,项目名称:iot-device-bosch-indego-controller,代码行数:22,代码来源:MqttIndegoAdapter.java

示例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);
}
 
开发者ID:Cirrus-Link,项目名称:Sparkplug,代码行数:31,代码来源:SparkplugExample.java

示例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);
	}
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:8,代码来源:MqttMain.java


注:本文中的org.eclipse.paho.client.mqttv3.MqttPersistenceException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。