You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2018/02/07 14:07:36 UTC

[incubator-openwhisk] branch master updated: Efficiently parse CompletionMessage. (#3253)

This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new e2d9ec0  Efficiently parse CompletionMessage. (#3253)
e2d9ec0 is described below

commit e2d9ec09aed1cd4d5ecbac6c7105a3410e30706e
Author: Markus Thömmes <ma...@me.com>
AuthorDate: Wed Feb 7 21:07:32 2018 +0700

    Efficiently parse CompletionMessage. (#3253)
    
    The parsing of `Either` relies on parsing failures in its generalized form. In this specialized case we can circumvent this and parse only once, without throwing any forced error messages.
    
    Fixes #3228
---
 .../src/main/scala/whisk/core/connector/Message.scala     | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/common/scala/src/main/scala/whisk/core/connector/Message.scala b/common/scala/src/main/scala/whisk/core/connector/Message.scala
index d79ba26..13e0ed6 100644
--- a/common/scala/src/main/scala/whisk/core/connector/Message.scala
+++ b/common/scala/src/main/scala/whisk/core/connector/Message.scala
@@ -95,6 +95,21 @@ case class CompletionMessage(override val transid: TransactionId,
 }
 
 object CompletionMessage extends DefaultJsonProtocol {
+  implicit def eitherResponse =
+    new JsonFormat[Either[ActivationId, WhiskActivation]] {
+      def write(either: Either[ActivationId, WhiskActivation]) = either match {
+        case Right(a) => a.toJson
+        case Left(b)  => b.toJson
+      }
+
+      def read(value: JsValue) = value match {
+        // per the ActivationId's serializer, it is guaranteed to be a String even if it only consists of digits
+        case _: JsString => Left(value.convertTo[ActivationId])
+        case _: JsObject => Right(value.convertTo[WhiskActivation])
+        case _           => deserializationError("could not read CompletionMessage")
+      }
+    }
+
   def parse(msg: String): Try[CompletionMessage] = Try(serdes.read(msg.parseJson))
   private val serdes = jsonFormat3(CompletionMessage.apply)
 }

-- 
To stop receiving notification emails like this one, please contact
rabbah@apache.org.