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


##########
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:
   Good call — done in 5bb2c33.
   
   Each of the two pairs is now reported the first time a producer sees it 
(`AtomicBoolean` per pair, set with `compareAndSet`), so a hot path logs the 
line once instead of once per exchange. The verdict itself is unchanged, and a 
message carrying neither header still logs nothing.
   
   Verified rather than assumed: the test that half-sets the headers now calls 
each check twice, and a clean run of the embedded suite still writes exactly 4 
lines to `target/camel-infinispan-test.log` — one per pair per producer 
instance — where the previous code wrote 6 for the same test.
   
   _Claude Code on behalf of oscerd_



-- 
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