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


Java MqttClientPersistence类代码示例

本文整理汇总了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);
}
 
开发者ID:projectsrepos,项目名称:jim,代码行数:29,代码来源:MqttClientFactory.java

示例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 + "!");
    }
}
 
开发者ID:thingsboard,项目名称:thingsboard-gateway,代码行数:18,代码来源:TbPersistenceConfiguration.java

示例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 + "!");
  }
}
 
开发者ID:osswangxining,项目名称:iotgateway,代码行数:18,代码来源:TbPersistenceConfiguration.java

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

示例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();
}
 
开发者ID:octoblu,项目名称:droidblu,代码行数:32,代码来源:MqttConnection.java

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

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

示例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;

}
 
开发者ID:emqtt,项目名称:EMQ-Android-Toolkit,代码行数:32,代码来源:MQTTManager.java

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

示例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;
}
 
开发者ID:TheThingsNetwork,项目名称:java-app-sdk,代码行数:14,代码来源:Client.java

示例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;
}
 
开发者ID:projectsrepos,项目名称:jim,代码行数:40,代码来源:MqttPerformanceClient.java

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

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

示例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();
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:PahoEndpoint.java

示例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);
}
 
开发者ID:msiedlarek,项目名称:winthing,代码行数:14,代码来源:MessagingModule.java


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