Skip to content

Commit

Permalink
GH-5105: make MonitoringImpl in FedX thread safe (#5106)
Browse files Browse the repository at this point in the history
  • Loading branch information
aschwarte10 authored Aug 13, 2024
2 parents 1044c5c + ffde1ff commit 20fb23f
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import org.eclipse.rdf4j.federated.FedXConfig;
import org.eclipse.rdf4j.federated.endpoint.Endpoint;
Expand Down Expand Up @@ -50,11 +51,7 @@ public class MonitoringImpl implements MonitoringService {

@Override
public void monitorRemoteRequest(Endpoint e) {
MonitoringInformation m = requestMap.get(e);
if (m == null) {
m = new MonitoringInformation(e);
requestMap.put(e, m);
}
MonitoringInformation m = requestMap.computeIfAbsent(e, (endpoint) -> new MonitoringInformation(endpoint));
m.increaseRequests();
}

Expand All @@ -75,28 +72,27 @@ public void resetMonitoringInformation() {

public static class MonitoringInformation {
private final Endpoint e;
private int numberOfRequests = 0;
private AtomicInteger numberOfRequests = new AtomicInteger(0);

public MonitoringInformation(Endpoint e) {
this.e = e;
}

private void increaseRequests() {
// TODO make thread safe
numberOfRequests++;
numberOfRequests.incrementAndGet();
}

@Override
public String toString() {
return e.getName() + " => " + numberOfRequests;
return e.getName() + " => " + numberOfRequests.get();
}

public Endpoint getE() {
return e;
}

public int getNumberOfRequests() {
return numberOfRequests;
return numberOfRequests.get();
}
}

Expand Down

0 comments on commit 20fb23f

Please sign in to comment.