allthingssecurity commented on code in PR #28319:
URL: https://github.com/apache/camel/pull/28319#discussion_r4357959348


##########
components/camel-tahu/src/main/java/org/apache/camel/component/tahu/TahuEdgeProducer.java:
##########
@@ -174,7 +257,12 @@ protected void doStop() throws Exception {
 
             Future<?> clientFuture = 
descriptorFutures.remove(edgeNodeDescriptor);
             if (clientFuture != null) {
-                tahuEdgeClient.shutdown();
+                TahuEdgeClient client = tahuEdgeClient;

Review Comment:
   Applied in 6ae3e40c4d54: `doStop` takes `TahuEdgeClient client = 
currentClient();`, the client of the Edge Node in the map, so it shuts down and 
removes the client whose future it just removed.
   
   New test 
`clientIsShutDownWhenBothProducersOfTheEdgeNodeStopAfterOneWasRestarted`: two 
routes to one Edge Node endpoint, `node1` restarted (second NBIRTH), then 
`node2` and `node1` stopped; it waits for the second NDEATH and asserts that 
`descriptorClients` has no client for the Edge Node. Without the change it 
times out with `published: [NBIRTH, DDEATH/D1, NDEATH, NBIRTH]` (the second 
client is never shut down).
   
   _Claude Code on behalf of allthingssecurity_



##########
components/camel-tahu/src/main/java/org/apache/camel/component/tahu/TahuEdgeProducer.java:
##########
@@ -95,15 +137,7 @@ public void process(Exchange exchange) throws 
InvalidPayloadException {
 
     private TahuEdgeClient createClient(TahuEdgeEndpoint endpoint, 
EdgeNodeDescriptor edgeNodeDescriptor) {
 
-        // Only create clients for Edge Nodes, not Devices. If passed a
-        // DeviceDescriptor, create/lookup based on its EdgeNodeDescriptor, 
i.e. minus
-        // its deviceId.
-        EdgeNodeDescriptor clientCreationDescriptor = edgeNodeDescriptor;
-        if (edgeNodeDescriptor.isDeviceDescriptor()) {
-            clientCreationDescriptor = ((DeviceDescriptor) 
edgeNodeDescriptor).getEdgeNodeDescriptor();
-        }
-
-        TahuEdgeClient tahuEdgeClient = 
descriptorClients.computeIfAbsent(clientCreationDescriptor, end -> {
+        TahuEdgeClient tahuEdgeClient = 
descriptorClients.computeIfAbsent(clientDescriptor, end -> {

Review Comment:
   Done in 2a4fbe20238a: only an Edge Node producer creates the client. A 
Device producer's constructor no longer calls `createClient`; 
`TahuEdgeDeviceProducer.currentClient()` takes the client of its Edge Node from 
`descriptorClients` when it publishes, and fails the exchange with 
`IllegalStateException: Cannot publish the data of Device G/E/D: no producer of 
its Edge Node G/E is started` when there is none (so it also no longer 
publishes on a client that a stopped Edge Node producer shut down). Its metric 
map is still added on start (to the current client, or to the next client the 
Edge Node creates).
   
   New test 
`deviceProducerCreatedWhileTheEdgeNodeIsStoppedUsesTheClientOfTheEdgeNode`: the 
Edge Node route is stopped, then a Device route without `deviceIds` is added; a 
send fails with the `IllegalStateException`, and after the Edge Node route 
starts the Device is born (DBIRTH) and its data is published. Without the 
change `addRoutes` fails with `FailedToStartRouteException ... 
NullPointerException: Cannot invoke "String.split(String)" because 
"this.deviceIds" is null`. The failing send is a visible change, so there is an 
upgrade guide entry and a sentence in `tahu-edge-component.adoc`.
   
   _Claude Code on behalf of allthingssecurity_



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