You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/12/18 17:11:36 UTC

(camel) branch main updated (5f3c86019c1 -> 868c1ad1b79)

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

orpiske pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from 5f3c86019c1 CAMEL-20225: use a monotonic source for computing duration
     new f7048e5f4e3 CAMEL-20225: simplify getting a ZonedDateTime
     new 868c1ad1b79 CAMEL-20225: simplify getting a Date instance from the clock API

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/cloudevents/CloudEvent.java     |  5 +----
 .../knative/ce/AbstractCloudEventProcessor.java     |  5 +----
 .../src/main/java/org/apache/camel/Clock.java       | 21 +++++++++++++++++++++
 .../org/apache/camel/support/LanguageHelper.java    |  3 +--
 4 files changed, 24 insertions(+), 10 deletions(-)


(camel) 02/02: CAMEL-20225: simplify getting a Date instance from the clock API

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 868c1ad1b7962d69fd51942d1712f4673ffd0e81
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Dec 15 13:15:07 2023 -0300

    CAMEL-20225: simplify getting a Date instance from the clock API
---
 core/camel-api/src/main/java/org/apache/camel/Clock.java          | 8 ++++++++
 .../src/main/java/org/apache/camel/support/LanguageHelper.java    | 3 +--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/Clock.java b/core/camel-api/src/main/java/org/apache/camel/Clock.java
index 78983ca05a0..2936f8dd5d5 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Clock.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Clock.java
@@ -48,4 +48,12 @@ public interface Clock {
     default ZonedDateTime asZonedCreationDateTime() {
         return ZonedDateTime.ofInstant(Instant.ofEpochMilli(getCreated()), ZoneId.systemDefault());
     }
+
+    /**
+     * Get the creation date/time as regular Java Date instance
+     * @return A Date instance from the computed creation time
+     */
+    default Date asDate() {
+        return new Date(getCreated());
+    }
 }
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/LanguageHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/LanguageHelper.java
index 65c19334c8e..fdbb92ce501 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/LanguageHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/LanguageHelper.java
@@ -263,8 +263,7 @@ public final class LanguageHelper {
      * @return          A Date instance
      */
     public static Date dateFromExchangeCreated(Exchange exchange) {
-        long num = exchange.getClock().getCreated();
-        return new Date(num);
+        return exchange.getClock().asDate();
     }
 
     /**


(camel) 01/02: CAMEL-20225: simplify getting a ZonedDateTime

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f7048e5f4e370a418eb7cca3cca4ef9f10c3db83
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Dec 15 13:08:09 2023 -0300

    CAMEL-20225: simplify getting a ZonedDateTime
---
 .../org/apache/camel/component/cloudevents/CloudEvent.java  |  5 +----
 .../component/knative/ce/AbstractCloudEventProcessor.java   |  5 +----
 core/camel-api/src/main/java/org/apache/camel/Clock.java    | 13 +++++++++++++
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/components/camel-cloudevents/src/main/java/org/apache/camel/component/cloudevents/CloudEvent.java b/components/camel-cloudevents/src/main/java/org/apache/camel/component/cloudevents/CloudEvent.java
index 9f3d6451e59..c181cb01733 100644
--- a/components/camel-cloudevents/src/main/java/org/apache/camel/component/cloudevents/CloudEvent.java
+++ b/components/camel-cloudevents/src/main/java/org/apache/camel/component/cloudevents/CloudEvent.java
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.component.cloudevents;
 
-import java.time.Instant;
-import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.Collection;
@@ -76,8 +74,7 @@ public interface CloudEvent {
      * Construct event time from given Camel exchange.
      */
     default String getEventTime(Exchange exchange) {
-        final ZonedDateTime created
-                = ZonedDateTime.ofInstant(Instant.ofEpochMilli(exchange.getClock().getCreated()), ZoneId.systemDefault());
+        final ZonedDateTime created = exchange.getClock().asZonedCreationDateTime();
         return DateTimeFormatter.ISO_INSTANT.format(created);
     }
 
diff --git a/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/ce/AbstractCloudEventProcessor.java b/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/ce/AbstractCloudEventProcessor.java
index 3165c2d8911..2c9fee8985a 100644
--- a/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/ce/AbstractCloudEventProcessor.java
+++ b/components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/ce/AbstractCloudEventProcessor.java
@@ -17,8 +17,6 @@
 package org.apache.camel.component.knative.ce;
 
 import java.io.InputStream;
-import java.time.Instant;
-import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.Map;
@@ -122,8 +120,7 @@ abstract class AbstractCloudEventProcessor implements CloudEventProcessor {
             setCloudEventHeader(headers, CloudEvent.CAMEL_CLOUD_EVENT_SOURCE, exchange::getFromRouteId);
             setCloudEventHeader(headers, CloudEvent.CAMEL_CLOUD_EVENT_VERSION, ce::version);
             setCloudEventHeader(headers, CloudEvent.CAMEL_CLOUD_EVENT_TIME, () -> {
-                final ZonedDateTime created
-                        = ZonedDateTime.ofInstant(Instant.ofEpochMilli(exchange.getClock().getCreated()), ZoneId.systemDefault());
+                final ZonedDateTime created = exchange.getClock().asZonedCreationDateTime();
 
                 return DateTimeFormatter.ISO_INSTANT.format(created);
             });
diff --git a/core/camel-api/src/main/java/org/apache/camel/Clock.java b/core/camel-api/src/main/java/org/apache/camel/Clock.java
index f19ecd35a07..78983ca05a0 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Clock.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Clock.java
@@ -17,6 +17,11 @@
 
 package org.apache.camel;
 
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.util.Date;
+
 /**
  * A clock used to track the lifetime of an exchange
  */
@@ -35,4 +40,12 @@ public interface Clock {
      * @see    System#currentTimeMillis()
      */
     long getCreated();
+
+    /**
+     * Get the creation date/time as with time-zone information
+     * @return A ZonedDateTime instance from the computed creation time
+     */
+    default ZonedDateTime asZonedCreationDateTime() {
+        return ZonedDateTime.ofInstant(Instant.ofEpochMilli(getCreated()), ZoneId.systemDefault());
+    }
 }