You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@bahir.apache.org by GitBox <gi...@apache.org> on 2019/06/23 08:42:49 UTC

[GitHub] [bahir] yanlin-Lynn commented on a change in pull request #84: [BAHIR-183] [WIP] HDFS based MQTT client persistence

yanlin-Lynn commented on a change in pull request #84: [BAHIR-183] [WIP] HDFS based MQTT client persistence
URL: https://github.com/apache/bahir/pull/84#discussion_r296471045
 
 

 ##########
 File path: sql-streaming-mqtt/src/main/scala/org/apache/bahir/sql/streaming/mqtt/MessageStore.scala
 ##########
 @@ -148,3 +141,113 @@ private[mqtt] class LocalMessageStore(val persistentStore: MqttClientPersistence
   }
 
 }
+
+private[mqtt] class HdfsMqttClientPersistence(config: Configuration)
+    extends MqttClientPersistence {
+
+  var rootPath: Path = _
+  var fileSystem: FileSystem = _
+
+  override def open(clientId: String, serverURI: String): Unit = {
+    try {
+      rootPath = new Path("mqtt/" + clientId + "/" + serverURI.replaceAll("[^a-zA-Z0-9]", "_"))
+      fileSystem = FileSystem.get(config)
+      if (!fileSystem.exists(rootPath)) {
+        fileSystem.mkdirs(rootPath)
+      }
+    }
+    catch {
+      case e: Exception => throw new MqttPersistenceException(e)
+    }
+  }
+
+  override def close(): Unit = {
+    try {
+      fileSystem.close()
+    }
+    catch {
+      case e: Exception => throw new MqttPersistenceException(e)
+    }
+  }
+
+  override def put(key: String, persistable: MqttPersistable): Unit = {
+    try {
+      val path = getPath(key)
 
 Review comment:
   I just worry about the performance of creating a file for each coming message.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services