11package de .rwth .idsg .steve .repository .impl ;
22
3+ import com .google .common .util .concurrent .Striped ;
34import de .rwth .idsg .steve .SteveException ;
45import de .rwth .idsg .steve .ocpp .OcppProtocol ;
56import de .rwth .idsg .steve .ocpp .OcppTransport ;
3132import java .util .Collections ;
3233import java .util .List ;
3334import java .util .Map ;
35+ import java .util .concurrent .locks .Lock ;
3436import java .util .stream .Collectors ;
3537
3638import static de .rwth .idsg .steve .SteveConfiguration .CONFIG ;
4951public class ChargePointRepositoryImpl implements ChargePointRepository {
5052
5153 private final boolean autoRegisterUnknownStations = CONFIG .getOcpp ().isAutoRegisterUnknownStations ();
54+ private final Striped <Lock > isRegisteredLocks = Striped .lock (16 );
55+
5256 private final DSLContext ctx ;
5357 private final AddressRepository addressRepository ;
5458
@@ -60,24 +64,30 @@ public ChargePointRepositoryImpl(DSLContext ctx, AddressRepository addressReposi
6064
6165 @ Override
6266 public boolean isRegistered (String chargeBoxId ) {
63- // 1. exit if already registered
64- if (isRegisteredInternal (chargeBoxId )) {
65- return true ;
66- }
67+ Lock l = isRegisteredLocks .get (chargeBoxId );
68+ l .lock ();
69+ try {
70+ // 1. exit if already registered
71+ if (isRegisteredInternal (chargeBoxId )) {
72+ return true ;
73+ }
6774
68- // 2. ok, this chargeBoxId is unknown. exit if auto-register is disabled
69- if (!autoRegisterUnknownStations ) {
70- return false ;
71- }
75+ // 2. ok, this chargeBoxId is unknown. exit if auto-register is disabled
76+ if (!autoRegisterUnknownStations ) {
77+ return false ;
78+ }
7279
73- // 3. chargeBoxId is unknown and auto-register is enabled. insert chargeBoxId
74- try {
75- addChargePoint (Collections .singletonList (chargeBoxId ));
76- log .warn ("Auto-registered unknown chargebox '{}'" , chargeBoxId );
77- return true ;
78- } catch (Exception e ) {
79- log .error ("Failed to auto-register unknown chargebox '" + chargeBoxId + "'" , e );
80- return false ;
80+ // 3. chargeBoxId is unknown and auto-register is enabled. insert chargeBoxId
81+ try {
82+ addChargePoint (Collections .singletonList (chargeBoxId ));
83+ log .warn ("Auto-registered unknown chargebox '{}'" , chargeBoxId );
84+ return true ;
85+ } catch (Exception e ) {
86+ log .error ("Failed to auto-register unknown chargebox '" + chargeBoxId + "'" , e );
87+ return false ;
88+ }
89+ } finally {
90+ l .unlock ();
8191 }
8292 }
8393
0 commit comments