Ottomata has submitted this change and it was merged.

Change subject: Adapt JsonStringMessageDecoder to kraken conventions
......................................................................


Adapt JsonStringMessageDecoder to kraken conventions

* Whitespace fixes
* Copyright header
* Package renaming

Change-Id: Iccad0282f680f4f18690eb8e550b1fc401791d35
---
M 
kraken-etl/src/main/java/org/wikimedia/analytics/kraken/etl/camus/kafka/coders/JsonStringMessageDecoder.java
1 file changed, 55 insertions(+), 39 deletions(-)

Approvals:
  Ottomata: Verified; Looks good to me, approved



diff --git 
a/kraken-etl/src/main/java/org/wikimedia/analytics/kraken/etl/camus/kafka/coders/JsonStringMessageDecoder.java
 
b/kraken-etl/src/main/java/org/wikimedia/analytics/kraken/etl/camus/kafka/coders/JsonStringMessageDecoder.java
index a283895..740754b 100644
--- 
a/kraken-etl/src/main/java/org/wikimedia/analytics/kraken/etl/camus/kafka/coders/JsonStringMessageDecoder.java
+++ 
b/kraken-etl/src/main/java/org/wikimedia/analytics/kraken/etl/camus/kafka/coders/JsonStringMessageDecoder.java
@@ -1,4 +1,20 @@
-package com.linkedin.camus.etl.kafka.coders;
+// Copyright (C) 2013 Wikimedia Foundation
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA.
+
+package org.wikimedia.analytics.kraken.etl.camus.kafka.coders;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -23,59 +39,59 @@
  * This MessageDecoder returns a CamusWrapper that works with Strings.
  */
 public class JsonStringMessageDecoder extends MessageDecoder<byte[], String> {
-       private static org.apache.log4j.Logger log = 
Logger.getLogger(JsonStringMessageDecoder.class);
+    private static org.apache.log4j.Logger log = 
Logger.getLogger(JsonStringMessageDecoder.class);
 
-       public  static final String CAMUS_MESSAGE_TIMESTAMP_FORMAT = 
"camus.message.timestamp.format";
-       public  static final String DEFAULT_TIMESTAMP_FORMAT       = 
"[dd/MMM/yyyy:HH:mm:ss Z]";
+    public  static final String CAMUS_MESSAGE_TIMESTAMP_FORMAT = 
"camus.message.timestamp.format";
+    public  static final String DEFAULT_TIMESTAMP_FORMAT       = 
"[dd/MMM/yyyy:HH:mm:ss Z]";
 
-       public  static final String CAMUS_MESSAGE_TIMESTAMP_FIELD  = 
"camus.message.timestamp.field";
-       public  static final String DEFAULT_TIMESTAMP_FIELD        = 
"timestamp";
+    public  static final String CAMUS_MESSAGE_TIMESTAMP_FIELD  = 
"camus.message.timestamp.field";
+    public  static final String DEFAULT_TIMESTAMP_FIELD        = "timestamp";
 
-       private String timestampFormat;
-       private String timestampField;
+    private String timestampFormat;
+    private String timestampField;
 
-       @Override
-       public void init(Properties props, String topicName) {
-           this.props     = props;
+    @Override
+    public void init(Properties props, String topicName) {
+        this.props     = props;
         this.topicName = topicName;
 
         timestampFormat = props.getProperty(CAMUS_MESSAGE_TIMESTAMP_FORMAT, 
DEFAULT_TIMESTAMP_FORMAT);
         timestampField  = props.getProperty(CAMUS_MESSAGE_TIMESTAMP_FIELD,  
DEFAULT_TIMESTAMP_FIELD);
-       }
+    }
 
-       @Override
-       public CamusWrapper<String> decode(byte[] payload) {
-               long       timestamp = 0;
-               String     payloadString;
-               JsonObject jsonObject;
+    @Override
+    public CamusWrapper<String> decode(byte[] payload) {
+        long       timestamp = 0;
+        String     payloadString;
+        JsonObject jsonObject;
 
-               payloadString =  new String(payload);
+        payloadString =  new String(payload);
 
-               // Parse the payload into a JsonObject.
-               try {
-                       jsonObject = new 
JsonParser().parse(payloadString).getAsJsonObject();
-               } catch (RuntimeException e) {
-                       log.error("Caught exception while parsing JSON string 
'" + payloadString + "'.");
-                       throw new RuntimeException(e);
-               }
+        // Parse the payload into a JsonObject.
+        try {
+            jsonObject = new 
JsonParser().parse(payloadString).getAsJsonObject();
+        } catch (RuntimeException e) {
+            log.error("Caught exception while parsing JSON string '" + 
payloadString + "'.");
+            throw new RuntimeException(e);
+        }
 
-               // Attempt to read and parse the timestamp element into a long.
-               if (jsonObject.has(timestampField)) {
-                       String timestampString = 
jsonObject.get(timestampField).getAsString();
-                       try {
-                               timestamp = new 
SimpleDateFormat(timestampFormat).parse(timestampString).getTime();
-                       } catch (Exception e) {
-                               log.error("Could not parse timestamp '" + 
timestampString + "' while decoding JSON message.");
-                       }
-           }
+        // Attempt to read and parse the timestamp element into a long.
+        if (jsonObject.has(timestampField)) {
+            String timestampString = 
jsonObject.get(timestampField).getAsString();
+            try {
+                timestamp = new 
SimpleDateFormat(timestampFormat).parse(timestampString).getTime();
+            } catch (Exception e) {
+                    log.error("Could not parse timestamp '" + timestampString 
+ "' while decoding JSON message.");
+            }
+        }
 
         // If timestamp wasn't set in the above block,
         // then set it to current time.
-               if (timestamp == 0) {
-                       log.warn("Couldn't find or parse timestamp field '" + 
timestampField + "' in JSON message, defaulting to current time.");
-               timestamp = System.currentTimeMillis();
-       }
+        if (timestamp == 0) {
+            log.warn("Couldn't find or parse timestamp field '" + 
timestampField + "' in JSON message, defaulting to current time.");
+            timestamp = System.currentTimeMillis();
+        }
 
         return new CamusWrapper<String>(payloadString, timestamp);
-       }
+    }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/90165
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iccad0282f680f4f18690eb8e550b1fc401791d35
Gerrit-PatchSet: 1
Gerrit-Project: analytics/kraken
Gerrit-Branch: master
Gerrit-Owner: QChris <[email protected]>
Gerrit-Reviewer: Ottomata <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to