apupier commented on code in PR #22158:
URL: https://github.com/apache/camel/pull/22158#discussion_r3000134657


##########
components/camel-state-store/camel-state-store/src/main/java/org/apache/camel/component/statestore/StateStoreProducer.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.statestore;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.support.DefaultProducer;
+
+/**
+ * Producer for the State Store component that performs key-value operations.
+ */
+public class StateStoreProducer extends DefaultProducer {
+
+    private final StateStoreEndpoint endpoint;
+
+    public StateStoreProducer(StateStoreEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        StateStoreOperations op = determineOperation(exchange);
+        if (op == null) {
+            throw new IllegalArgumentException(
+                    "No operation specified. Set the operation via URI option 
or header " + StateStoreConstants.OPERATION);
+        }
+
+        StateStoreBackend backend = endpoint.getBackend();
+        long ttl = determineTtl(exchange);
+        Message message = exchange.getMessage();
+
+        switch (op) {
+            case put -> {
+                String key = requireKey(message);
+                Object value = message.getBody();
+                Object previous = backend.put(key, value, ttl);
+                message.setBody(previous);
+            }
+            case putIfAbsent -> {
+                String key = requireKey(message);
+                Object value = message.getBody();
+                Object existing = backend.putIfAbsent(key, value, ttl);
+                message.setBody(existing);

Review Comment:
   maybe normal but I was surprised when reading it that when performing and 
operation to store a state, we change the message body with the previous value



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