cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbros...@apache.org
Subject cassandra git commit: make json date formatter thread safe patch by dbrosius reviewed by thobbs for CASSANDRA-10814
Date Tue, 22 Dec 2015 00:21:57 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 8565ca89a -> ebbd51698


make json date formatter thread safe
patch by dbrosius reviewed by thobbs for CASSANDRA-10814


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/ebbd5169
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ebbd5169
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ebbd5169

Branch: refs/heads/cassandra-2.2
Commit: ebbd516985bc3e2859ae00e63a024b837cb4b429
Parents: 8565ca8
Author: Dave Brosius <dbrosius@mebigfatguy.com>
Authored: Mon Dec 21 19:20:49 2015 -0500
Committer: Dave Brosius <dbrosius@mebigfatguy.com>
Committed: Mon Dec 21 19:20:49 2015 -0500

----------------------------------------------------------------------
 .../org/apache/cassandra/db/marshal/DateType.java    |  2 +-
 .../apache/cassandra/db/marshal/TimestampType.java   |  2 +-
 .../cassandra/serializers/TimestampSerializer.java   | 15 +++++++++++++--
 3 files changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/ebbd5169/src/java/org/apache/cassandra/db/marshal/DateType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/DateType.java b/src/java/org/apache/cassandra/db/marshal/DateType.java
index 359ce52..82ed876 100644
--- a/src/java/org/apache/cassandra/db/marshal/DateType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DateType.java
@@ -82,7 +82,7 @@ public class DateType extends AbstractType<Date>
     @Override
     public String toJSONString(ByteBuffer buffer, int protocolVersion)
     {
-        return '"' + TimestampSerializer.TO_JSON_FORMAT.format(TimestampSerializer.instance.deserialize(buffer))
+ '"';
+        return '"' + TimestampSerializer.getJsonDateFormatter().format(TimestampSerializer.instance.deserialize(buffer))
+ '"';
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ebbd5169/src/java/org/apache/cassandra/db/marshal/TimestampType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/TimestampType.java b/src/java/org/apache/cassandra/db/marshal/TimestampType.java
index b01651d..1704362 100644
--- a/src/java/org/apache/cassandra/db/marshal/TimestampType.java
+++ b/src/java/org/apache/cassandra/db/marshal/TimestampType.java
@@ -90,7 +90,7 @@ public class TimestampType extends AbstractType<Date>
     @Override
     public String toJSONString(ByteBuffer buffer, int protocolVersion)
     {
-        return '"' + TimestampSerializer.TO_JSON_FORMAT.format(TimestampSerializer.instance.deserialize(buffer))
+ '"';
+        return '"' + TimestampSerializer.getJsonDateFormatter().format(TimestampSerializer.instance.deserialize(buffer))
+ '"';
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ebbd5169/src/java/org/apache/cassandra/serializers/TimestampSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/serializers/TimestampSerializer.java b/src/java/org/apache/cassandra/serializers/TimestampSerializer.java
index ab81fcc..78ee7e7 100644
--- a/src/java/org/apache/cassandra/serializers/TimestampSerializer.java
+++ b/src/java/org/apache/cassandra/serializers/TimestampSerializer.java
@@ -96,8 +96,14 @@ public class TimestampSerializer implements TypeSerializer<Date>
         }
     };
 
-    public static final SimpleDateFormat TO_JSON_FORMAT = new SimpleDateFormat(dateStringPatterns[15]);
-
+    private static final ThreadLocal<SimpleDateFormat> FORMATTER_TO_JSON = new ThreadLocal<SimpleDateFormat>()
+    {
+        protected SimpleDateFormat initialValue()
+        {
+            return new SimpleDateFormat(dateStringPatterns[15]);
+        }
+    };
+    
     public static final TimestampSerializer instance = new TimestampSerializer();
 
     public Date deserialize(ByteBuffer bytes)
@@ -138,6 +144,11 @@ public class TimestampSerializer implements TypeSerializer<Date>
             throw new MarshalException(String.format("Unable to coerce '%s' to a formatted
date (long)", source), e1);
         }
     }
+    
+    public static SimpleDateFormat getJsonDateFormatter() 
+    {
+    	return FORMATTER_TO_JSON.get();
+    }
 
     public void validate(ByteBuffer bytes) throws MarshalException
     {


Mime
View raw message