本文整理汇总了Java中org.eclipse.paho.client.mqttv3.MqttClientPersistence类的典型用法代码示例。如果您正苦于以下问题:Java MqttClientPersistence类的具体用法?Java MqttClientPersistence怎么用?Java MqttClientPersistence使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MqttClientPersistence类属于org.eclipse.paho.client.mqttv3包,在下文中一共展示了MqttClientPersistence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMqttClient
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
/**
* get MqttClient by clientKey
* @param clientKey
* @return
* @throws MqttException
*/
public static MqttClient getMqttClient(String serverURI, String clientId,StringRedisTemplate redisTemplate)
throws MqttException{
String clientKey=serverURI.concat(clientId);
if(clientMap.get(clientKey)==null){
lock.lock();
if(clientMap.get(clientKey)==null){
MqttClientPersistence persistence = new MemoryPersistence();
MqttClient client = new MqttClient(serverURI, clientId, persistence);
MqttConnectOptions connOpts = new MqttConnectOptions();
MqttCallback callback = new IMMqttCallBack(client,redisTemplate);
client.setCallback(callback);
connOpts.setCleanSession(true);
client.connect(connOpts);
clientMap.put(clientKey, client);
}
lock.unlock();
}
return clientMap.get(clientKey);
}
示例2: getPersistence
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
public MqttClientPersistence getPersistence() {
if (StringUtils.isEmpty(type) || type.equals("memory")) {
log.info("Initializing default memory persistence!");
return new MemoryPersistence();
} else if (type.equals("file")) {
if (StringUtils.isEmpty(path)) {
log.info("Initializing default file persistence!");
return new MqttDefaultFilePersistence();
} else {
log.info("Initializing file persistence using directory: {}", path);
return new MqttDefaultFilePersistence(path);
}
} else {
log.error("Unknown persistence option: {}. Only 'memory' and 'file' are supported at the moment!", type);
throw new IllegalArgumentException("Unknown persistence option: " + type + "!");
}
}
示例3: getPersistence
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
public MqttClientPersistence getPersistence() {
if (StringUtils.isEmpty(type) || type.equals("memory")) {
log.info("Initializing default memory persistence!");
return new MemoryPersistence();
} else if (type.equals("file")) {
if (StringUtils.isEmpty(path)) {
log.info("Initializing default file persistence!");
return new MqttDefaultFilePersistence();
} else {
log.info("Initializing file persistence using directory: {}", path);
return new MqttDefaultFilePersistence(path);
}
} else {
log.error("Unknown persistence option: {}. Only 'memory' and 'file' are supported at the moment!", type);
throw new IllegalArgumentException("Unknown persistence option: " + type + "!");
}
}
示例4: MqttConnection
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
/**
* Constructor - create an MqttConnection to communicate with MQTT server
*
* @param service
* our "parent" service - we make callbacks to it
* @param serverURI
* the URI of the MQTT server to which we will connect
* @param clientId
* the name by which we will identify ourselves to the MQTT
* server
* @param persistence
* the persistence class to use to store in-flight message. If
* null then the default persistence mechanism is used
* @param clientHandle
* the "handle" by which the activity will identify us
*/
MqttConnection(MqttService service, String serverURI, String clientId,
MqttClientPersistence persistence, String clientHandle) {
this.serverURI = serverURI;
this.service = service;
this.clientId = clientId;
this.persistence = persistence;
this.clientHandle = clientHandle;
StringBuilder stringBuilder = new StringBuilder(this.getClass().getCanonicalName());
stringBuilder.append(" ");
stringBuilder.append(clientId);
stringBuilder.append(" ");
stringBuilder.append("on host ");
stringBuilder.append(serverURI);
wakeLockTag = stringBuilder.toString();
}
示例5: MqttConnection
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
/**
* Constructor - create an MqttConnection to communicate with MQTT server
*
* @param service
* our "parent" service - we make callbacks to it
* @param serverURI
* the URI of the MQTT server to which we will connect
* @param clientId
* the name by which we will identify ourselves to the MQTT
* server
* @param persistence the persistence class to use to store in-flight message. If null then the
* default persistence mechanism is used
* @param clientHandle
* the "handle" by which the activity will identify us
*/
MqttConnection(MqttService service, String serverURI, String clientId,
MqttClientPersistence persistence, String clientHandle) {
this.serverURI = serverURI.toString();
this.service = service;
this.clientId = clientId;
this.persistence = persistence;
this.clientHandle = clientHandle;
StringBuffer buff = new StringBuffer(this.getClass().getCanonicalName());
buff.append(" ");
buff.append(clientId);
buff.append(" ");
buff.append("on host ");
buff.append(serverURI);
wakeLockTag = buff.toString();
}
示例6: ConnectActionListener
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
/**
* @param persistence
* @param client
* @param comms
* @param options
* @param userToken
* @param userContext
* @param userCallback
*/
public ConnectActionListener(
MqttAsyncClient client,
MqttClientPersistence persistence,
ClientComms comms,
MqttConnectOptions options,
MqttToken userToken,
Object userContext,
IMqttActionListener userCallback) {
this.persistence = persistence;
this.client = client;
this.comms = comms;
this.options = options;
this.userToken = userToken;
this.userContext = userContext;
this.userCallback = userCallback;
this.originalMqttVersion = options.getMqttVersion();
}
示例7: ClientState
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
protected ClientState(MqttClientPersistence persistence, CommsTokenStore tokenStore,
CommsCallback callback, ClientComms clientComms, MqttPingSender pingSender) throws MqttException {
log.setResourceName(clientComms.getClient().getClientId());
log.finer(CLASS_NAME, "<Init>", "" );
inUseMsgIds = new Hashtable();
pendingMessages = new Vector(this.maxInflight);
pendingFlows = new Vector();
outboundQoS2 = new Hashtable();
outboundQoS1 = new Hashtable();
inboundQoS2 = new Hashtable();
pingCommand = new MqttPingReq();
inFlightPubRels = 0;
actualInFlight = 0;
this.persistence = persistence;
this.callback = callback;
this.tokenStore = tokenStore;
this.clientComms = clientComms;
this.pingSender = pingSender;
restoreState();
}
示例8: createClient
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
public MqttAndroidClient createClient(String id, String serverURI, String clientId) {
MqttClientPersistence mqttClientPersistence = new MemoryPersistence();
MqttAndroidClient client = new MqttAndroidClient(MyApplication.getContext(), serverURI, clientId, mqttClientPersistence);
client.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable cause) {
LogUtil.e("connectionLost");
EventBus.getDefault().post(new MQTTActionEvent(Constant.MQTTStatusConstant.CONNECTION_LOST, null, cause));
}
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
LogUtil.d("topic is " + topic + ",message is " + message.toString() + ", qos is " + message.getQos());
EventBus.getDefault().postSticky(new MessageEvent(new EmqMessage(topic, message)));
}
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
LogUtil.d("deliveryComplete");
}
});
mClients.put(id, client);
return client;
}
示例9: PahoAsyncMqttClientService
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
/**
* Default constructor
*
* @param serverUri the Server URI to connect to
* @param clientId the Client ID to connect as
* @param connectionType the {@link MqttClientConnectType} this instance will be used as
* @param clientPersistence TODO: add description
* @throws IllegalArgumentException if the {@code serverUri} is blank or null, the
* {@code clientId} is blank or null, or if the {@code connectionType} value is null
* @throws MqttException if the underlying {@link MqttAsyncClient} instance cannot be created
*/
public PahoAsyncMqttClientService(final String serverUri, final String clientId,
final MqttClientConnectionType connectionType,
final MqttClientPersistence clientPersistence)
throws MqttException
{
super(connectionType);
Assert.hasText(serverUri, "'serverUri' must be set!");
Assert.hasText(clientId, "'clientId' must be set!");
this.clientPersistence = clientPersistence;
mqttClient = new MqttAsyncClient(serverUri, clientId, this.clientPersistence);
mqttClient.setCallback(this);
}
示例10: setMqttPersistence
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
/**
* Change the default Mqtt persistence settings
*
* @param _persistence A custom persistence setting
* @return the Client instance
*/
public Client setMqttPersistence(MqttClientPersistence _persistence) {
if (mqttClient != null) {
throw new RuntimeException("Can not be called while client is running");
}
persistence = _persistence;
return this;
}
示例11: getMqttClient
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
/**
* get MqttClient by clientKey
*
* @param clientKey
* @return
* @throws MqttException
* @throws NoSuchAlgorithmException
*/
private MqttClient getMqttClient(String clientId) throws MqttException {
MqttClientPersistence persistence = new MemoryPersistence();
MqttClient client = new MqttClient(broker_address, clientId,
persistence);
MqttConnectOptions connOpts = new MqttConnectOptions();
MqttCallback callback = new MqttCallback() {
public void messageArrived(String topic, MqttMessage message)
throws Exception {
long arriveTime = System.currentTimeMillis();
String msgID = message.toString();
for(MsgHandleInterface handle : handleList)
handle.handle(msgID,topic);
Object[] str = {msgID,arriveTime};
arriveQueue.put(str);
}
public void deliveryComplete(IMqttDeliveryToken token) {
}
public void connectionLost(Throwable cause) {
}
};
client.setCallback(callback);
connOpts.setKeepAliveInterval(3600);
connOpts.setCleanSession(true);
client.connect(connOpts);
return client;
}
示例12: newPersistenceProvider
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
private static MqttClientPersistence newPersistenceProvider(String className) {
Class<?> clazz = null;
try {
clazz = Class.forName(className);
return (MqttClientPersistence) clazz.newInstance();
}
catch (Exception e) {
throw new IllegalArgumentException(e.getLocalizedMessage(), e);
}
}
示例13: client
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
@NonNull
public static IMqttAsyncClient client(
@NonNull final String url,
@NonNull final String id,
@NonNull final MqttClientPersistence persistence) throws MqttException {
return new MqttAsyncClient(url, id, persistence);
}
示例14: resolvePersistence
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
protected MqttClientPersistence resolvePersistence() {
if (persistence == PahoPersistence.MEMORY) {
return new MemoryPersistence();
} else {
if (filePersistenceDirectory != null) {
return new MqttDefaultFilePersistence(filePersistenceDirectory);
} else {
return new MqttDefaultFilePersistence();
}
}
}
示例15: configure
import org.eclipse.paho.client.mqttv3.MqttClientPersistence; //导入依赖的package包/类
@Override
protected void configure() {
bind(MqttClientPersistence.class).to(MemoryPersistence.class).in(Singleton.class);
bind(Registry.class).to(SimpleRegistry.class).in(Singleton.class);
bind(Engine.class).in(Singleton.class);
bind(MessagePublisher.class).to(Engine.class);
expose(Registry.class);
expose(MessagePublisher.class);
expose(Engine.class);
}