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


Java MqttDefaultFilePersistence类代码示例

本文整理汇总了Java中org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence的典型用法代码示例。如果您正苦于以下问题:Java MqttDefaultFilePersistence类的具体用法?Java MqttDefaultFilePersistence怎么用?Java MqttDefaultFilePersistence使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MqttDefaultFilePersistence类属于org.eclipse.paho.client.mqttv3.persist包,在下文中一共展示了MqttDefaultFilePersistence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPersistence

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的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

示例2: mqttClientFactory

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
@Bean
public MqttPahoClientFactory mqttClientFactory() {
	DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
	factory.setServerURIs(mqttProperties.getUrl());
	factory.setUserName(mqttProperties.getUsername());
	factory.setPassword(mqttProperties.getPassword());
	factory.setCleanSession(mqttProperties.isCleanSession());
	factory.setConnectionTimeout(mqttProperties.getConnectionTimeout());
	factory.setKeepAliveInterval(mqttProperties.getKeepAliveInterval());
	if (ObjectUtils.nullSafeEquals(mqttProperties.getPersistence(), "file")) {
		factory.setPersistence(new MqttDefaultFilePersistence(mqttProperties.getPersistenceDirectory()));
	}
	else if (ObjectUtils.nullSafeEquals(mqttProperties.getPersistence(), "memory")) {
		factory.setPersistence(new MemoryPersistence());
	}
	return factory;
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:mqtt,代码行数:18,代码来源:MqttConfiguration.java

示例3: getPersistence

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的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: onCreate

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
/**
 * 服务初始化回调函数
 */
@Override
public void onCreate() {
    super.onCreate();

    /**创建一个Handler*/
    mConnHandler = new Handler();
    try {
        /**新建一个本地临时存储数据的目录,该目录存储将要发送到服务器的数据,直到数据被发送到服务器*/
        mDataStore = new MqttDefaultFilePersistence(getCacheDir().getAbsolutePath());
    } catch(Exception e) {
        e.printStackTrace();
        /**新建一个内存临时存储数据的目录*/
        mDataStore = null;
        mMemStore = new MemoryPersistence();
    }
    /**连接的参数选项*/
    mOpts = new MqttConnectOptions();
    /**删除以前的Session*/
    mOpts.setCleanSession(MQTT_CLEAN_SESSION);
    // Do not set keep alive interval on mOpts we keep track of it with alarm's
    /**定时器用来实现心跳*/
    mAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    /**管理网络连接*/
    mConnectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
}
 
开发者ID:LiuJunb,项目名称:HelloMQTT,代码行数:29,代码来源:MQService.java

示例5: connect

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
/**
 *
 *
 */
private void connect() throws MqttException {
    connOpt = new MqttConnectOptions();

    connOpt.setCleanSession(true);
    connOpt.setKeepAliveInterval(3600);
    connOpt.setConnectionTimeout(3600);
    connOpt.setUserName(sharedPref.getString("pref_username", ""));
    connOpt.setPassword(sharedPref.getString("pref_password", "").toCharArray());

    String tmpDir = createTempDir().getPath(); //System.getProperty("java.io.tmpdir");
    Log.i(TAG, "Persistence will be done in " + tmpDir);

    MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir);

    // Connect to Broker
    mClient = new MqttClient(sharedPref.getString("pref_url", "") + ":" + sharedPref.getString("pref_port", "1883"), android_id + "_client", dataStore);
    mClient.setCallback(this);
    mClient.connect(connOpt);
    Log.i(TAG, "Connected to " + sharedPref.getString("pref_url", ""));

}
 
开发者ID:caribewave,项目名称:android-app,代码行数:26,代码来源:MQTTClient.java

示例6: MQTTTestClient

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
/**
 * Generate a MQTT client with given parameters
 *
 * @param brokerURL url of MQTT provider
 * @param userName username to connect to MQTT provider
 * @param password password to connect to MQTT provider
 * @param clientId unique id for the publisher/subscriber client
 * @throws MqttException in case of issue of connect/publish/consume
 */
public MQTTTestClient(String brokerURL, String userName, char[] password, String clientId) throws MqttException {
    this.brokerURL = brokerURL;
    //Store messages until server fetches them
    MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(JAVA_TMP_DIR + "/" + clientId);
    mqttClient = new MqttClient(brokerURL, clientId, dataStore);
    SimpleMQTTCallback callback = new SimpleMQTTCallback();
    mqttClient.setCallback(callback);
    MqttConnectOptions connectOptions = new MqttConnectOptions();
    connectOptions.setUserName(userName);
    connectOptions.setPassword(password);
    connectOptions.setCleanSession(true);
    mqttClient.connect(connectOptions);

    log.info("MQTTTestClient successfully connected to broker at " + this.brokerURL);
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:25,代码来源:MQTTTestClient.java

示例7: createMqttClient

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
private MqttClient createMqttClient(String hostName, String port, String sslEnable
        , String uniqueClientId, int qos, String tempStore) {
    MqttDefaultFilePersistence dataStore = getDataStore(uniqueClientId, qos, tempStore);

    String mqttEndpointURL = hostName + ":" + port;
    // If SSL is enabled in the config, Use SSL tranport
    if (sslEnable != null && sslEnable.equalsIgnoreCase("true")) {
        mqttEndpointURL = "ssl://" + mqttEndpointURL;
    } else {
        mqttEndpointURL = "tcp://" + mqttEndpointURL;
    }
    MqttClient mqttClient;
    if(log.isDebugEnabled()){
        log.debug("ClientId " + uniqueClientId);
    }
    try {
        mqttClient = new MqttClient(mqttEndpointURL, uniqueClientId, dataStore);

    } catch (MqttException e) {
        log.error("Error while creating the MQTT client...", e);
        throw new AxisMqttException("Error while creating the MQTT client", e);
    }
    return mqttClient;
}
 
开发者ID:wso2,项目名称:wso2-axis2-transports,代码行数:25,代码来源:MqttConnectionFactory.java

示例8: startClientsTesting

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
private static void startClientsTesting() throws MqttException, InterruptedException {
    String host = "localhost";
    int numToSend = 10;
    int messagesPerSecond = 10000;
    String dialog_id = "test1";

    String tmpDir = System.getProperty("java.io.tmpdir");
    MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir);
    MqttAsyncClient pub = new MqttAsyncClient("tcp://" + host + ":1883", "PublisherClient" + dialog_id, dataStore);
    MqttDefaultFilePersistence dataStoreSub = new MqttDefaultFilePersistence(tmpDir);
    MqttAsyncClient sub = new MqttAsyncClient("tcp://" + host + ":1883", "SubscriberClient" + dialog_id,
            dataStoreSub);

    BenchmarkSubscriber suscriberBench = new BenchmarkSubscriber(sub, dialog_id);
    suscriberBench.connect();

    BenchmarkPublisher publisherBench = new BenchmarkPublisher(pub, numToSend, messagesPerSecond, dialog_id);
    publisherBench.connect();
    publisherBench.firePublishes();

    suscriberBench.waitFinish();
    publisherBench.waitFinish();
    System.out.println("Started clients (sub/pub) for testing");
}
 
开发者ID:andsel,项目名称:moquette,代码行数:25,代码来源:ProtocolDecodingServer.java

示例9: doConnectBroker

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
private boolean doConnectBroker() {
	try {
		LOG.debug("{} > connect..", url);

		final MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
		mqttConnectOptions.setUserName("admin");
		mqttConnectOptions.setPassword("admin".toCharArray());
		mqttConnectOptions.setCleanSession(true);
		mqttConnectOptions.setWill(pubTopic2Mqtt, "Bye, bye Baby!".getBytes(), 0, false);

		// client
		final String tmpDir = System.getProperty("java.io.tmpdir");
		final MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir);
		LOG.info("creating MqttAsyncClient for {} and {}", url, clientId);
		mqttAsyncClient = new MqttAsyncClient(url, clientId, dataStore);

		// callback
		mqttAsyncClient.setCallback(this);

		// connect
		mqttAsyncClient.connect(mqttConnectOptions).waitForCompletion();

		// subscriptions
		for (final String subTopic : subTopics) {
			LOG.info("client {} subscribing to {}", clientId, subTopic);
			mqttAsyncClient.subscribe(subTopic, 0);
		}

		LOG.info("{} > mqtt connection established for {}.", url, clientId);
		return true;
	} catch (final Throwable throwable) {
		LOG.error("{} > connection failed. ({})", url, throwable.getMessage());
		close();
		return false;
	}
}
 
开发者ID:dcsolutions,项目名称:kalinka,代码行数:37,代码来源:MqttClient.java

示例10: resolvePersistence

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的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

示例11: MoquetteProxyContext

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
/**
 * Initializes an object that can be used for sending messages to the broker
 * which is running on localhost.
 */
public MoquetteProxyContext() {
  try {
    this.dataStore = new MqttDefaultFilePersistence();
    this.client = new MqttAsyncClient(getFullMqttBrokerUrl(), MQTT_CLIENT_NAME, dataStore);
  } catch (MqttException e) {
    // The exception is thrown when there is an unrecognized MQTT Message in the persistant
    // storage location. Messages are removed from persistant storage once the broker
    // sends the message to subscribers (does not wait for confirmation)
    throw new IllegalStateException("Unrecognized message in the persistent data store location."
        + " Consider clearing the default persistent storage location.");
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-mqtt-proxy,代码行数:17,代码来源:MoquetteProxyContext.java

示例12: doStart

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
@Override
protected synchronized void doStart() throws FlumeException {
  if (client == null) {
    try {
      new File(journalDir).mkdirs();
      client = new MqttClient(providerUrl, getName(), new MqttDefaultFilePersistence(journalDir));
      if (LOG.isInfoEnabled()) {
        LOG.info("MQTT client created with [" + providerUrl + "/" + destinationName + "]");
      }
    } catch (Exception e) {
      throw new FlumeException("MQTT client create failed with [" + providerUrl + "/" + destinationName + "]", e);
    }
  }
}
 
开发者ID:ggear,项目名称:cloudera-framework,代码行数:15,代码来源:MqttSource.java

示例13: start

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
@Override
public void start(boolean asyncMode) throws IOException, MqttException {
   publishService = Executors.newSingleThreadExecutor();

   //This sample stores in a temporary directory... where messages temporarily
   // stored until the message has been delivered to the server.
   //..a real application ought to store them somewhere
   // where they are not likely to get deleted or tampered with
   String tmpDir = System.getProperty("java.io.tmpdir");
   MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir);

   // Construct the connection options object that contains connection parameters
   // such as cleanSession and LWT
   conOpt = new MqttConnectOptions();
   conOpt.setCleanSession(clean);
   if (password != null) {
      conOpt.setPassword(this.password.toCharArray());
   }
   if (userName != null) {
      conOpt.setUserName(this.userName);
   }

   // Construct an MQTT blocking mode client
   if(clientID == null) {
      InetAddress addr = InetAddress.getLocalHost();
      clientID = "Parser-" + addr.getHostAddress();
   }
   client = new MqttClient(this.brokerURL, clientID, dataStore);

   // Set this wrapper as the callback handler
   client.setCallback(this);
}
 
开发者ID:starksm64,项目名称:RaspberryPiBeaconParser,代码行数:33,代码来源:MqttPublisher.java

示例14: Sample

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
/**
 * Constructs an instance of the sample client wrapper
 * 
 * @param brokerUrl
 *          the url of the server to connect to
 * @param clientId
 *          the client id to connect with
 * @param cleanSession
 *          clear state at end of connection or not (durable or non-durable
 *          subscriptions)
 * @param quietMode
 *          whether debug should be printed to standard out
 * @param userName
 *          the username to connect with
 * @param password
 *          the password for the user
 * @throws MqttException if an error happens
 */
public Sample(String brokerUrl, String clientId, boolean cleanSession, boolean quietMode, String userName, String password) throws MqttException {
  this.brokerUrl = brokerUrl;
  this.quietMode = quietMode;
  this.clean = cleanSession;
  this.password = password;
  this.userName = userName;
  // This sample stores in a temporary directory... where messages temporarily
  // stored until the message has been delivered to the server.
  // ..a real application ought to store them somewhere
  // where they are not likely to get deleted or tampered with
  String tmpDir = System.getProperty("java.io.tmpdir");
  MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir);

  try {
    // Construct the connection options object that contains connection
    // parameters
    // such as cleanSession and LWT
    conOpt = new MqttConnectOptions();
    conOpt.setCleanSession(clean);
    if (password != null) {
      conOpt.setPassword(this.password.toCharArray());
    }
    if (userName != null) {
      conOpt.setUserName(this.userName);
    }

    // Construct an MQTT blocking mode client
    client = new MqttClient(this.brokerUrl, clientId, dataStore);

    // Set this wrapper as the callback handler
    client.setCallback(this);

  } catch (MqttException e) {
    e.printStackTrace();
    log("Unable to set up client: " + e.toString());
    System.exit(1);
  }
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:57,代码来源:Sample.java

示例15: build

import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; //导入依赖的package包/类
public MqttClient build() {
MqttClient client;
try {
    if (memoryPersistence) {
	client = new MqttClient(uri, clientUID, new MemoryPersistence());
    } else {
	client = new MqttClient(uri, clientUID,
				new MqttDefaultFilePersistence());
    }
} catch (MqttException e) {
    e.printStackTrace();
    client = null;
}
return client;
   }
 
开发者ID:knr1,项目名称:ch.bfh.mobicomp,代码行数:16,代码来源:MqttClientBuilder.java


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