davsclaus commented on code in PR #26427:
URL: https://github.com/apache/camel/pull/26427#discussion_r4011926365


##########
components/camel-infinispan/camel-infinispan-common/src/main/java/org/apache/camel/component/infinispan/InfinispanProducer.java:
##########
@@ -417,13 +417,28 @@ protected <K, V> BasicCache<K, V> getCache(Message 
message) {
     }
 
     protected boolean hasLifespan(Message message) {
-        return !InfinispanUtil.isHeaderEmpty(message, 
InfinispanConstants.LIFESPAN_TIME)
-                && !InfinispanUtil.isHeaderEmpty(message, 
InfinispanConstants.LIFESPAN_TIME_UNIT);
+        return hasExpiry(message, InfinispanConstants.LIFESPAN_TIME, 
InfinispanConstants.LIFESPAN_TIME_UNIT);
     }
 
     protected boolean hasMaxIdleTime(Message message) {
-        return !InfinispanUtil.isHeaderEmpty(message, 
InfinispanConstants.MAX_IDLE_TIME)
-                && !InfinispanUtil.isHeaderEmpty(message, 
InfinispanConstants.MAX_IDLE_TIME_UNIT);
+        return hasExpiry(message, InfinispanConstants.MAX_IDLE_TIME, 
InfinispanConstants.MAX_IDLE_TIME_UNIT);
+    }
+
+    /**
+     * An expiry needs both an amount and the time unit it is expressed in. 
When only one of the two is on the message
+     * the expiry cannot be applied, and the entry is stored without it, so 
report that instead of dropping it quietly.
+     */
+    private boolean hasExpiry(Message message, String timeHeader, String 
timeUnitHeader) {
+        boolean hasTime = !InfinispanUtil.isHeaderEmpty(message, timeHeader);
+        boolean hasTimeUnit = !InfinispanUtil.isHeaderEmpty(message, 
timeUnitHeader);
+
+        if (hasTime != hasTimeUnit) {
+            LOG.warn("Both {} and {} are needed to set an expiry on cache {}, 
but only {} is set on the message,"

Review Comment:
   Non-blocking: this fires on every message (twice if both pairs are 
half-set). The misconfiguration is static — a route forgot a header — so 
consider logging it once per producer instance (e.g. an `AtomicBoolean 
warned`), otherwise a hot cache path floods the log at WARN. Fine either way; 
keeping it lenient rather than throwing is the right call.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to