You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iota.apache.org by to...@apache.org on 2016/11/29 23:29:10 UTC

[11/31] incubator-iota git commit: Removed scalastyle in ZMQPublisher and ZMQSubscriber

Removed scalastyle in ZMQPublisher and ZMQSubscriber


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/2b585a1f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/2b585a1f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/2b585a1f

Branch: refs/heads/master
Commit: 2b585a1f018ea77daed68ba4856e8ac202352fa2
Parents: 7cc1745
Author: Shivansh <sh...@gmail.com>
Authored: Fri Nov 4 00:17:00 2016 +0530
Committer: Shivansh <sh...@gmail.com>
Committed: Fri Nov 4 00:17:00 2016 +0530

----------------------------------------------------------------------
 .../iota/fey/performer/ZMQPublisher.scala       |  8 +++--
 .../iota/fey/performer/ZMQSubscriber.scala      | 38 ++++++++++----------
 2 files changed, 23 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/2b585a1f/performers/zmq/src/main/scala/org/apache/iota/fey/performer/ZMQPublisher.scala
----------------------------------------------------------------------
diff --git a/performers/zmq/src/main/scala/org/apache/iota/fey/performer/ZMQPublisher.scala b/performers/zmq/src/main/scala/org/apache/iota/fey/performer/ZMQPublisher.scala
index 252a8bc..0f19aa0 100644
--- a/performers/zmq/src/main/scala/org/apache/iota/fey/performer/ZMQPublisher.scala
+++ b/performers/zmq/src/main/scala/org/apache/iota/fey/performer/ZMQPublisher.scala
@@ -33,14 +33,16 @@ class ZMQPublisher(override val params: Map[String, String] = Map.empty,
 
   //-------default params----------
   val DEFAULT_PORT = 5559
+  val DEFAULT_NULL = null
+
   var port: Int = DEFAULT_PORT
   var target: String = "localhost"
   val DEFAULT_LINGER = 200
   val DEFAULT_HMW = 10
 
   //-------class vars-------------------
-  var ctx: ZMQ.Context = null
-  var pub: ZMQ.Socket = null
+  var ctx: ZMQ.Context = DEFAULT_NULL
+  var pub: ZMQ.Socket = DEFAULT_NULL
   var count: Int = 0
 
   override def onStart: Unit = {
@@ -113,7 +115,7 @@ class ZMQPublisher(override val params: Map[String, String] = Map.empty,
     // The tuple has the following elements: lrn, timestamp, value, type
     // And we have to create a message with the format:
     // DATA|cloud|lrn|timestamp|{"<type>" : <value>}
-    s"""DATA|cloud| ${fields._1}|${fields._2}|{"${fields._3}":"${fields._4}"}"""
+    s"""DATA|cloud| ${fields._1}|${fields._2}|{${fields._3}:${fields._4}}"""
   }
 
   def sendZMQ(Message: String): Unit = {

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/2b585a1f/performers/zmq/src/main/scala/org/apache/iota/fey/performer/ZMQSubscriber.scala
----------------------------------------------------------------------
diff --git a/performers/zmq/src/main/scala/org/apache/iota/fey/performer/ZMQSubscriber.scala b/performers/zmq/src/main/scala/org/apache/iota/fey/performer/ZMQSubscriber.scala
index c7d0381..7e51980 100644
--- a/performers/zmq/src/main/scala/org/apache/iota/fey/performer/ZMQSubscriber.scala
+++ b/performers/zmq/src/main/scala/org/apache/iota/fey/performer/ZMQSubscriber.scala
@@ -31,25 +31,25 @@ class ZMQSubscriber(override val params: Map[String, String] = Map.empty,
                     override val autoScale: Boolean = false) extends FeyGenericActor {
 
   //-------default params----------
-  var port: Int = 5563
+  val DEFAULT_PORT = 5563
+  val DEFAULT_NULL = null
+  var port: Int = DEFAULT_PORT
   var target: String = "localhost"
   val topic_filter: String = "DATA"
 
   //-------class vars-------------------
-  var ctx: ZMQ.Context = null
-  var pub: ZMQ.Socket = null
+  var ctx: ZMQ.Context = DEFAULT_NULL
+  var pub: ZMQ.Socket = DEFAULT_NULL
   var count: Int = 0
 
-  override def onStart = {
+  override def onStart: Unit = {
     log.info("Starting ZMQ Subscriber")
     try {
-
-      _params_check()
+      checkParams()
 
       // Prepare our context and subscriber
       ctx = ZMQ.context(1)
       val subscriber = ctx.socket(ZMQ.SUB)
-
       subscriber.bind(s"tcp://$target:$port")
       subscriber.subscribe(topic_filter.getBytes())
       while (true) {
@@ -66,21 +66,21 @@ class ZMQSubscriber(override val params: Map[String, String] = Map.empty,
     }
   }
 
-  override def onStop = {
+  override def onStop: Unit = {
     pub.disconnect("tcp://" + target + ":" + port)
     pub.close()
     ctx.close()
-    pub = null
-    ctx = null
+    pub = DEFAULT_NULL
+    ctx = DEFAULT_NULL
   }
 
-  override def onRestart(reason: Throwable) = {
+  override def onRestart(reason: Throwable): Unit = {
     // Called after actor is up and running - after self restart
     try {
-      if (pub != null) {
+      if (Option(pub).isDefined) {
         pub.close()
       }
-      if (ctx != null) {
+      if (Option(ctx).isDefined) {
         ctx.close()
       }
     }
@@ -95,9 +95,7 @@ class ZMQSubscriber(override val params: Map[String, String] = Map.empty,
     case x => log.debug(s"Untreated $x")
   }
 
-  override def execute() = {
-    log.debug(s"Msg count: $count")
-  }
+  override def execute(): Unit = log.debug(s"Msg count: $count")
 
   override def processMessage[T](message: T, sender: ActorRef): Unit = {
     message match {
@@ -105,14 +103,14 @@ class ZMQSubscriber(override val params: Map[String, String] = Map.empty,
     }
   }
 
-  def _format_messages(fields: (String, String, String, String)): String = {
+  def formatMessages(fields: (String, String, String, String)): String = {
     // The tuple has the following elements: lrn, timestamp, value, type
     // And we have to create a message with the format:
     // DATA|cloud|lrn|timestamp|{"<type>" : <value>}
-    "DATA|cloud|" + fields._1 + "|" + fields._2 + "|" + s"""{"${fields._3}":"${fields._4}"}"""
+    s"""DATA|cloud|${fields._1}|${fields._2}|{${fields._3}:${fields._4}}"""
   }
 
-  def _params_check() = {
+  def checkParams(): Unit = {
     if (params.contains("zmq_port")) {
       port = params("zmq_port").toInt
     }
@@ -121,4 +119,4 @@ class ZMQSubscriber(override val params: Map[String, String] = Map.empty,
     }
   }
 
-}
\ No newline at end of file
+}