/*******************************************************************************
* Copyright (c) 2009, 2016 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Dave Locke - initial API and implementation and/or initial documentation
* Ian Craggs - MQTT 3.1.1 support
* Ian Craggs - per subscription message handlers (bug 466579)
* Ian Craggs - ack control (bug 472172)
* James Sutton - Bug 459142 - WebSocket support for the Java client.
* James Sutton - Automatic Reconnect & Offline Buffering.
*/
package org.eclipse.paho.client.mqttv3;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Hashtable;
import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;
import org.eclipse.paho.client.mqttv3.internal.ClientComms;
import org.eclipse.paho.client.mqttv3.internal.ConnectActionListener;
import org.eclipse.paho.client.mqttv3.internal.DisconnectedMessageBuffer;
import org.eclipse.paho.client.mqttv3.internal.ExceptionHelper;
import org.eclipse.paho.client.mqttv3.internal.NetworkModule;
import org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule;
import org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule;
import org.eclipse.paho.client.mqttv3.internal.security.SSLSocketFactoryFactory;
import org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketNetworkModule;
import org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketSecureNetworkModule;
import org.eclipse.paho.client.mqttv3.internal.wire.MqttDisconnect;
import org.eclipse.paho.client.mqttv3.internal.wire.MqttPublish;
import org.eclipse.paho.client.mqttv3.internal.wire.MqttSubscribe;
import org.eclipse.paho.client.mqttv3.internal.wire.MqttUnsubscribe;
import org.eclipse.paho.client.mqttv3.logging.Logger;
import org.eclipse.paho.client.mqttv3.logging.LoggerFactory;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
import org.eclipse.paho.client.mqttv3.util.Debug;
/**
* Lightweight client for talking to an MQTT server using non-blocking methods
* that allow an operation to run in the background.
*
* <p>
* This class implements the non-blocking {@link IMqttAsyncClient} client
* interface allowing applications to initiate MQTT actions and then carry on
* working while the MQTT action completes on a background thread. This
* implementation is compatible with all Java SE runtimes from 1.7 and up.
* </p>
* <p>
* An application can connect to an MQTT server using:
* </p>
* <ul>
* <li>A plain TCP socket
* <li>A secure SSL/TLS socket
* </ul>
*
* <p>
* To enable messages to be delivered even across network and client restarts
* messages need to be safely stored until the message has been delivered at the
* requested quality of service. A pluggable persistence mechanism is provided
* to store the messages.
* </p>
* <p>
* By default {@link MqttDefaultFilePersistence} is used to store messages to a
* file. If persistence is set to null then messages are stored in memory and
* hence can be lost if the client, Java runtime or device shuts down.
* </p>
* <p>
* If connecting with {@link MqttConnectOptions#setCleanSession(boolean)} set to
* true it is safe to use memory persistence as all state is cleared when a
* client disconnects. If connecting with cleanSession set to false in order to
* provide reliable message delivery then a persistent message store such as the
* default one should be used.
* </p>
* <p>
* The message store interface is pluggable. Different stores can be used by
* implementing the {@link MqttClientPersistence} interface and passing it to
* the clients constructor.
* </p>
*
* @see IMqttAsyncClient
*/
public class MqttAsyncClient implements IMqttAsyncClient {
private static final String CLASS_NAME = MqttAsyncClient.class.getName();
private static final Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT, CLASS_NAME);
private static final String CLIENT_ID_PREFIX = "paho";
private static final long QUIESCE_TIMEOUT = 30000; // ms
private static final long DISCONNECT_TIMEOUT = 10000; // ms
private static final char MIN_HIGH_SURROGATE = '\uD800';
private static final char MAX_HIGH_SURROGATE = '\uDBFF';
private String clientId;
private String serverURI;
protected ClientComms comms;
private Hashtable topics;
private MqttClientPersistence persistence;
private MqttCallback mqttCallback;
private MqttConnectOptions connOpts;
private Object userContext;
private Timer reconnectTimer; // Automatic reconnect timer
private static int reconnectDelay = 1000; // Reconnect delay, starts at 1
// second
private boolean reconnecting = false;
private static Object clientLock = new Object(); // Simple lock
private ScheduledExecutorService executorService;
/**
* Create an MqttAsyncClient that is used to communicate with an MQTT
* server.
* <p>
* The address of a server can be specified on the constructor.
* Alternatively a list containing one or more servers can be specified
* using the {@link MqttConnectOptions#setServerURIs(String[])
* setServerURIs} method on MqttConnectOptions.
*
* <p>
* The <code>serverURI</code> parameter is typically used with the the
* <code>clientId</code> parameter to form a key. The key is used to store
* and reference messages while they are being delivered. Hence the
* serverURI specified on the constructor must still be specified even if a
* list of servers is specified on an MqttConnectOptions object. The
* serverURI on the constructor must remain the same across restarts of the
* client for delivery of messages to be maintained from a given client to a
* given server or set of servers.
*
* <p>
* The address of the server to connect to is specified as a URI. Two types
* of connection are supported <code>tcp://</code> for a TCP connection and
* <code>ssl://</code> for a TCP connection secured by SSL/TLS. For example:
* </p>
* <ul>
* <li><code>tcp://localhost:1883</code></li>
* <li><code>ssl://localhost:8883</code></li>
* </ul>
* <p>
* If the port is not specified, it will default to 1883 for
* <code>tcp://</code>" URIs, and 8883 for <code>ssl://</code> URIs.
* </p>
*
* <p>
* A client identifier <code>clientId</code> must be specified and be less
* that 65535 characters. It must be unique across all clients connecting to
* the same server. The clientId is used by the server to store data related
* to the client, hence it is important that the clientId remain the same
* when connecting to a server if durable subscriptions or reliable
* messaging are required.
* <p>
* A convenience method is provided to generate a random client id that
* should satisfy this criteria - {@link #generateClientId()}. As the client
* identifier is used by the server to identify a client when it reconnects,
* the client must use the same identifier between connections if durable
* subscriptions or reliable delivery of messages is required.
* </p>
* <p>
* In Java SE, SSL can be configured in one of several ways, which the
* client will use in the following order:
* </p>
* <ul>
* <li><strong>Supplying an <code>SSLSocketFactory</code></strong> -
* applications can use
* {@link MqttConnectOptions#setSocketFactory(SocketFactory)} to supply a
* factory with
没有合适的资源?快使用搜索试试~ 我知道了~
org.eclipse.paho.client.mqttv3-1.2.0-sources.zip
共111个文件
java:88个
properties:18个
html:4个
需积分: 50 13 下载量 93 浏览量
2020-05-12
16:15:17
上传
评论
收藏 206KB ZIP 举报
温馨提示
mqtt java版本的源码,版本号1.2.0,有兴趣的可以下载,mqtt广泛用于物联网,智能家居,大家快来下载吧 引入Android studio步骤: 1.讲jar更改为zip解压 2.创建library moudle,以org.eclipse.paho.client.mqttv3作为包名 3.将解压后的代码放到对应目录 4.在moudle的main目录下创建resources目录(New > Folder > Java Resources Folder) 5.将nls的资源文件copy至resources即可
资源推荐
资源详情
资源评论
收起资源包目录
org.eclipse.paho.client.mqttv3-1.2.0-sources.zip (111个子文件)
package.html 8KB
package.html 1017B
package.html 467B
package.html 48B
MqttAsyncClient.java 56KB
ClientState.java 56KB
SSLSocketFactoryFactory.java 46KB
IMqttClient.java 45KB
IMqttAsyncClient.java 41KB
MqttClient.java 30KB
ClientComms.java 29KB
Logger.java 25KB
MqttConnectOptions.java 22KB
CommsCallback.java 16KB
MqttWireMessage.java 11KB
Token.java 11KB
MqttTopic.java 10KB
JSR47Logger.java 10KB
MqttDefaultFilePersistence.java 9KB
MqttException.java 8KB
MqttMessage.java 8KB
CommsTokenStore.java 8KB
WebSocketFrame.java 8KB
ConnectActionListener.java 7KB
WebSocketHandshake.java 7KB
CommsReceiver.java 7KB
IMqttToken.java 6KB
CommsSender.java 6KB
Debug.java 6KB
LoggerFactory.java 6KB
TCPNetworkModule.java 5KB
MqttPublish.java 5KB
Strings.java 5KB
MqttInputStream.java 5KB
MqttConnect.java 5KB
MqttClientPersistence.java 5KB
DisconnectedMessageBuffer.java 4KB
MqttPersistable.java 4KB
WebSocketReceiver.java 4KB
SSLNetworkModule.java 4KB
MqttSubscribe.java 4KB
WebSocketNetworkModule.java 3KB
SimpleBase64Encoder.java 3KB
WebSocketSecureNetworkModule.java 3KB
MqttCallback.java 3KB
MqttUnsubscribe.java 3KB
ScheduledExecutorPingSender.java 3KB
FileLock.java 3KB
MqttOutputStream.java 3KB
MemoryPersistence.java 3KB
SimpleLogFormatter.java 3KB
MqttPersistentData.java 3KB
DisconnectedBufferOptions.java 3KB
MqttToken.java 3KB
TimerPingSender.java 2KB
IMqttMessageListener.java 2KB
Base64.java 2KB
MqttPersistenceException.java 2KB
MqttConnack.java 2KB
ExceptionHelper.java 2KB
MqttPubRel.java 2KB
IMqttDeliveryToken.java 2KB
MqttSuback.java 2KB
MqttPersistableWireMessage.java 2KB
MqttSecurityException.java 2KB
MqttDeliveryToken.java 2KB
MessageCatalog.java 2KB
MqttPubAck.java 2KB
MqttPubComp.java 2KB
MultiByteArrayInputStream.java 2KB
MqttPingReq.java 1KB
MqttDisconnect.java 1KB
CountingInputStream.java 1KB
MqttPubRec.java 1KB
ExtendedByteArrayOutputStream.java 1KB
IMqttActionListener.java 1KB
MqttUnsubAck.java 1KB
MqttPingSender.java 1KB
MqttCallbackExtended.java 1KB
MqttPingResp.java 1KB
MultiByteInteger.java 1KB
BufferedMessage.java 1KB
ResourceBundleCatalog.java 1KB
DestinationProvider.java 1KB
NetworkModule.java 1KB
MqttReceivedMessage.java 1KB
MqttAck.java 1KB
IDisconnectedBufferCallback.java 956B
HandshakeFailedException.java 819B
ClientDefaults.java 804B
PersistanceFileNameFilter.java 401B
PersistanceFileFilter.java 391B
MANIFEST.MF 427B
logcat.properties 6KB
messages_ru.properties 4KB
jsr47min.properties 3KB
messages_ja.properties 2KB
messages_ko.properties 2KB
messages_hu.properties 2KB
messages_zh_TW.properties 2KB
共 111 条
- 1
- 2
资源评论
过往旅行者
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 截图保存到相册,最简单的写法
- PLAN_11X250-dtk.stl
- Ollama是一个专为在本地环境中运行和定制大型语言模型而设计的工具
- 毕业设计 基于Rust和PyTorch框架的昆虫分类系统(含源码+项目文档说明+后端).zip
- 基于贵兰在线平台开展《数字素养通识课》教学-学生端操作手册.pdf
- Fluent 脚本编译并加载UDF
- 基于Mask2Former进行医疗图像分割系统(含源码+项目说明文档).zip
- 2024PHP彩虹工具网源码一个多功能工具箱程序支持72种常用站长和开发等工具
- YOLOv10在智能语音识别中的创新应用与代码实现
- 使用Flet0.24实现的自定义圆形头像加载本地图片的自定义组件CustomCircleAvata示例源代码IDE运行和调试通过
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功