camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-11447: Optimise - MessageHistoryFactory should use long instead of Date
Date Sat, 24 Jun 2017 19:49:59 GMT
Repository: camel
Updated Branches:
  refs/heads/master 73ad5d4d8 -> 68387853c


CAMEL-11447: Optimise - MessageHistoryFactory should use long instead of Date


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

Branch: refs/heads/master
Commit: 68387853cf3a3bfbdb6057e8868fc95c50c03294
Parents: 73ad5d4
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Jun 24 21:44:33 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Jun 24 21:44:33 2017 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/camel/MessageHistory.java |  8 ++++++++
 .../org/apache/camel/impl/DefaultMessageHistory.java   | 13 +++++++++----
 .../camel/impl/DefaultMessageHistoryFactory.java       |  5 +++++
 .../apache/camel/processor/CamelInternalProcessor.java |  2 +-
 .../org/apache/camel/spi/MessageHistoryFactory.java    | 12 ++++++++++++
 .../impl/DefaultAsyncProcessorAwaitManagerTest.java    |  4 ++--
 .../metrics/messagehistory/MetricsMessageHistory.java  |  6 ++----
 .../messagehistory/MetricsMessageHistoryFactory.java   |  8 +++++++-
 8 files changed, 46 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/68387853/camel-core/src/main/java/org/apache/camel/MessageHistory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/MessageHistory.java b/camel-core/src/main/java/org/apache/camel/MessageHistory.java
index e7e33f5..217b9d2 100644
--- a/camel-core/src/main/java/org/apache/camel/MessageHistory.java
+++ b/camel-core/src/main/java/org/apache/camel/MessageHistory.java
@@ -35,10 +35,18 @@ public interface MessageHistory {
 
     /**
      * Gets the timestamp at the point of this history.
+     *
+     * @deprecated use {@link #getTime()}
      */
+    @Deprecated
     Date getTimestamp();
 
     /**
+     * Gets the timestamp at the point of this history.
+     */
+    long getTime();
+
+    /**
      * Gets the elapsed time in millis processing the node took
      */
     long getElapsed();

http://git-wip-us.apache.org/repos/asf/camel/blob/68387853/camel-core/src/main/java/org/apache/camel/impl/DefaultMessageHistory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultMessageHistory.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultMessageHistory.java
index ac3b93c..5083794 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultMessageHistory.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultMessageHistory.java
@@ -29,10 +29,10 @@ public class DefaultMessageHistory implements MessageHistory {
     private final String routeId;
     private final NamedNode node;
     private final String nodeId;
-    private final Date timestamp;
+    private final long timestamp;
     private long elapsed;
 
-    public DefaultMessageHistory(String routeId, NamedNode node, Date timestamp) {
+    public DefaultMessageHistory(String routeId, NamedNode node, long timestamp) {
         this.routeId = routeId;
         this.node = node;
         this.nodeId = node.getId();
@@ -48,6 +48,11 @@ public class DefaultMessageHistory implements MessageHistory {
     }
 
     public Date getTimestamp() {
+        return new Date(timestamp);
+    }
+
+    @Override
+    public long getTime() {
         return timestamp;
     }
 
@@ -56,8 +61,8 @@ public class DefaultMessageHistory implements MessageHistory {
     }
 
     public void nodeProcessingDone() {
-        if (timestamp != null) {
-            elapsed = System.currentTimeMillis() - timestamp.getTime();
+        if (timestamp > 0) {
+            elapsed = System.currentTimeMillis() - timestamp;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/68387853/camel-core/src/main/java/org/apache/camel/impl/DefaultMessageHistoryFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultMessageHistoryFactory.java
b/camel-core/src/main/java/org/apache/camel/impl/DefaultMessageHistoryFactory.java
index 89c2f40..aa97e3c 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultMessageHistoryFactory.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultMessageHistoryFactory.java
@@ -26,6 +26,11 @@ public class DefaultMessageHistoryFactory implements MessageHistoryFactory
{
 
     @Override
     public MessageHistory newMessageHistory(String routeId, NamedNode node, Date timestamp)
{
+        return new DefaultMessageHistory(routeId, node, timestamp.getTime());
+    }
+
+    @Override
+    public MessageHistory newMessageHistory(String routeId, NamedNode node, long timestamp)
{
         return new DefaultMessageHistory(routeId, node, timestamp);
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/68387853/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
index d315ecc..eb59fc1 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
@@ -770,7 +770,7 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor {
                 }
             }
 
-            MessageHistory history = factory.newMessageHistory(targetRouteId, definition,
new Date());
+            MessageHistory history = factory.newMessageHistory(targetRouteId, definition,
System.currentTimeMillis());
             list.add(history);
             return history;
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/68387853/camel-core/src/main/java/org/apache/camel/spi/MessageHistoryFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/MessageHistoryFactory.java b/camel-core/src/main/java/org/apache/camel/spi/MessageHistoryFactory.java
index 977ff56..10cf2f8 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/MessageHistoryFactory.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/MessageHistoryFactory.java
@@ -33,6 +33,18 @@ public interface MessageHistoryFactory {
      * @param node      the node in the route
      * @param timestamp the time the message processed at this node.
      * @return a new {@link MessageHistory}
+     * @deprecated use {@link #newMessageHistory(String, NamedNode, long)}
      */
+    @Deprecated
     MessageHistory newMessageHistory(String routeId, NamedNode node, Date timestamp);
+
+    /**
+     * Creates a new {@link MessageHistory}
+     *
+     * @param routeId   the route id
+     * @param node      the node in the route
+     * @param timestamp the time the message processed at this node.
+     * @return a new {@link MessageHistory}
+     */
+    MessageHistory newMessageHistory(String routeId, NamedNode node, long timestamp);
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/68387853/camel-core/src/test/java/org/apache/camel/impl/DefaultAsyncProcessorAwaitManagerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/DefaultAsyncProcessorAwaitManagerTest.java
b/camel-core/src/test/java/org/apache/camel/impl/DefaultAsyncProcessorAwaitManagerTest.java
index b91354e..ed4de4c 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/DefaultAsyncProcessorAwaitManagerTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/DefaultAsyncProcessorAwaitManagerTest.java
@@ -75,7 +75,7 @@ public class DefaultAsyncProcessorAwaitManagerTest {
         LinkedList<MessageHistory> messageHistories = new LinkedList<>();
         messageHistories.add(MESSAGE_HISTORY_FACTORY.newMessageHistory(null,
                 new MockNamedNode().withId(null),
-                null));
+                0));
         exchange.setProperty(Exchange.MESSAGE_HISTORY, messageHistories);
         AsyncProcessorAwaitManager.AwaitThread awaitThread = defaultAsyncProcessorAwaitManager.browse().iterator().next();
         assertThat(awaitThread.getRouteId(), is(nullValue()));
@@ -89,7 +89,7 @@ public class DefaultAsyncProcessorAwaitManagerTest {
         LinkedList<MessageHistory> messageHistories = new LinkedList<>();
         messageHistories.add(MESSAGE_HISTORY_FACTORY.newMessageHistory("routeId",
                 new MockNamedNode().withId("nodeId"),
-                null));
+                0));
         exchange.setProperty(Exchange.MESSAGE_HISTORY, messageHistories);
         AsyncProcessorAwaitManager.AwaitThread awaitThread = defaultAsyncProcessorAwaitManager.browse().iterator().next();
         assertThat(awaitThread.getRouteId(), is("routeId"));

http://git-wip-us.apache.org/repos/asf/camel/blob/68387853/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistory.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistory.java
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistory.java
index 33e1c2a..6cd6526 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistory.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistory.java
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.component.metrics.messagehistory;
 
-import java.util.Date;
-
 import com.codahale.metrics.Timer;
 import org.apache.camel.MessageHistory;
 import org.apache.camel.NamedNode;
@@ -30,8 +28,8 @@ public class MetricsMessageHistory extends DefaultMessageHistory {
 
     private final Timer.Context context;
 
-    public MetricsMessageHistory(String routeId, NamedNode namedNode, Timer timer) {
-        super(routeId, namedNode, new Date());
+    public MetricsMessageHistory(String routeId, NamedNode namedNode, Timer timer, long timestamp)
{
+        super(routeId, namedNode, timestamp);
         this.context = timer.time();
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/68387853/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryFactory.java
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryFactory.java
index c738af5..f279dba 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryFactory.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryFactory.java
@@ -125,9 +125,15 @@ public class MetricsMessageHistoryFactory extends ServiceSupport implements
Came
     }
 
     @Override
+    @Deprecated
     public MessageHistory newMessageHistory(String routeId, NamedNode namedNode, Date date)
{
+        return newMessageHistory(routeId, namedNode, date.getTime());
+    }
+
+    @Override
+    public MessageHistory newMessageHistory(String routeId, NamedNode namedNode, long timestamp)
{
         Timer timer = metricsRegistry.timer(createName("history", routeId, namedNode.getId()));
-        return new MetricsMessageHistory(routeId, namedNode, timer);
+        return new MetricsMessageHistory(routeId, namedNode, timer, timestamp);
     }
 
     private String createName(String type, String routeId, String id) {


Mime
View raw message