@@ -84,11 +84,18 @@ public class CollectionCache<T extends IdentifiableAttributes> {
84
84
*/
85
85
private boolean isFullyLoadedOperationalLimitsGroup = false ;
86
86
87
+ private boolean isFullyLoadedCurrentLimitsGroup = false ;
88
+
87
89
/**
88
90
* Indicates if all the operational limits groups for a specific identifiable has been fully loaded and synchronized with the server.
89
91
*/
90
92
private final Set <String > fullyLoadedOperationalLimitsGroupsByBranchIds = new HashSet <>();
91
93
94
+ /**
95
+ * Indicates if all the operational limits groups for a specific identifiable has been fully loaded and synchronized with the server.
96
+ */
97
+ private final Set <String > fullyLoadedCurrentLimitsGroupsByBranchIds = new HashSet <>();
98
+
92
99
/**
93
100
* Map storing sets of removed operational limits names associated with identifiable IDs.
94
101
* The map is organized where:
@@ -383,6 +390,7 @@ public CollectionCache<T> clone(ObjectMapper objectMapper, int newVariantNum, Co
383
390
clonedCache .removedOperationalLimitsGroupsAttributes .addAll (removedOperationalLimitsGroupsAttributes );
384
391
clonedCache .fullyLoadedOperationalLimitsGroupsByBranchIds .addAll (fullyLoadedOperationalLimitsGroupsByBranchIds );
385
392
clonedCache .isFullyLoadedOperationalLimitsGroup = isFullyLoadedOperationalLimitsGroup ;
393
+ clonedCache .isFullyLoadedCurrentLimitsGroup = isFullyLoadedCurrentLimitsGroup ;
386
394
387
395
clonedCache .containerFullyLoaded .addAll (containerFullyLoaded );
388
396
clonedCache .removedResources .addAll (removedResources );
@@ -581,6 +589,10 @@ private boolean isOperationalLimitsGroupAttributesCached(String branchId) {
581
589
return (fullyLoadedOperationalLimitsGroupsByBranchIds .contains (branchId ) || isFullyLoadedOperationalLimitsGroup ) && resources .containsKey (branchId );
582
590
}
583
591
592
+ private boolean isCurrentLimitsGroupAttributesCached (String branchId ) {
593
+ return (fullyLoadedOperationalLimitsGroupsByBranchIds .contains (branchId ) || fullyLoadedCurrentLimitsGroupsByBranchIds .contains (branchId ) || isFullyLoadedOperationalLimitsGroup || isFullyLoadedCurrentLimitsGroup ) && resources .containsKey (branchId );
594
+ }
595
+
584
596
private boolean isFullyLoadedOperationalLimitsGroup (String branchId ) {
585
597
return isFullyLoadedOperationalLimitsGroup || fullyLoadedOperationalLimitsGroupsByBranchIds .contains (branchId );
586
598
}
@@ -600,6 +612,7 @@ private void addOperationalLimitsGroupAttributesToCache(String branchId, String
600
612
getCachedOperationalLimitsGroupAttributes (branchId , side ).putIfAbsent (operationalLimitsGroupName , operationalLimitsGroupAttributes );
601
613
OperationalLimitsGroupIdentifier identifier = OperationalLimitsGroupIdentifier .of (branchId , operationalLimitsGroupName , side );
602
614
removedOperationalLimitsGroupsAttributes .remove (identifier );
615
+ fullyLoadedOperationalLimitsGroupsByBranchIds .add (branchId );
603
616
}
604
617
605
618
public void removeOperationalLimitsGroupAttributesByName (String branchId , String operationalLimitsGroupName , int side ) {
@@ -628,6 +641,47 @@ public Map<String, Map<OperationalLimitsGroupIdentifier, OperationalLimitsGroupA
628
641
return Collections .emptyMap ();
629
642
}
630
643
644
+ /**
645
+ * Get all the operational limits group attributes for all the identifiables with specified resource type in the cache
646
+ */
647
+ public Map <String , Map <OperationalLimitsGroupIdentifier , OperationalLimitsGroupAttributes >> getSelectedCurrentLimitsGroupAttributesByResourceType (UUID networkUuid , int variantNum , ResourceType type ) {
648
+ if (!isFullyLoadedCurrentLimitsGroup ) {
649
+ // if collection has not yet been fully loaded we load it from the server
650
+ Map <String , Map <OperationalLimitsGroupIdentifier , OperationalLimitsGroupAttributes >> operationalLimitsGroupAttributesMap =
651
+ delegate .getSelectedCurrentLimitsGroupAttributesByResourceType (networkUuid , variantNum , type );
652
+
653
+ // we update the full cache and set it as fully loaded
654
+ operationalLimitsGroupAttributesMap .forEach (this ::addAllOperationalLimitsGroupAttributesToCache );
655
+ isFullyLoadedCurrentLimitsGroup = true ;
656
+ }
657
+ return Collections .emptyMap ();
658
+ }
659
+
660
+ public Optional <OperationalLimitsGroupAttributes > getCurrentLimitsAttributes (UUID networkUuid , int variantNum , ResourceType type ,
661
+ String branchId , String operationalLimitGroupName , int side ) {
662
+ Objects .requireNonNull (branchId );
663
+ if (isCurrentLimitsGroupAttributesCached (branchId )) {
664
+ return Optional .ofNullable (getCachedOperationalLimitsGroupAttributes (branchId , side ).get (operationalLimitGroupName ));
665
+ }
666
+
667
+ if (!isFullyLoadedOperationalLimitsGroup (branchId ) && !isRemovedOperationalLimitsGroupAttributes (branchId , operationalLimitGroupName , side )) {
668
+ return delegate .getCurrentLimitsGroupAttributes (networkUuid , variantNum , type , branchId , operationalLimitGroupName , side )
669
+ .map (attributes -> {
670
+ addCurrentLimitsGroupAttributesToCache (branchId , operationalLimitGroupName , side , attributes );
671
+ return attributes ;
672
+ });
673
+ }
674
+ return Optional .empty ();
675
+ }
676
+
677
+ private void addCurrentLimitsGroupAttributesToCache (String branchId , String operationalLimitsGroupName , int side , OperationalLimitsGroupAttributes operationalLimitsGroupAttributes ) {
678
+ Objects .requireNonNull (operationalLimitsGroupAttributes );
679
+ getCachedOperationalLimitsGroupAttributes (branchId , side ).putIfAbsent (operationalLimitsGroupName , operationalLimitsGroupAttributes );
680
+ OperationalLimitsGroupIdentifier identifier = OperationalLimitsGroupIdentifier .of (branchId , operationalLimitsGroupName , side );
681
+ removedOperationalLimitsGroupsAttributes .remove (identifier );
682
+ fullyLoadedCurrentLimitsGroupsByBranchIds .add (branchId );
683
+ }
684
+
631
685
/**
632
686
* Add operational limits group attributes to the cache when loading all the operational limits group attributes of an identifiable.<br/>
633
687
* This method is only used to get operational limits group attributes from the server so even if it adds some checks and reduces performance by a tiny bit,
@@ -638,9 +692,11 @@ private void addAllOperationalLimitsGroupAttributesToCache(String branchId, Map<
638
692
Objects .requireNonNull (operationalLimitsGroupAttributesMap );
639
693
640
694
operationalLimitsGroupAttributesMap .forEach ((identifier , limitsGroup ) -> {
641
- getCachedOperationalLimitsGroupAttributes (identifier .getBranchId (), identifier .getSide ())
642
- .putIfAbsent (limitsGroup .getId (), limitsGroup );
643
- removedOperationalLimitsGroupsAttributes .remove (identifier );
695
+ if (limitsGroup != null ) {
696
+ getCachedOperationalLimitsGroupAttributes (identifier .getBranchId (), identifier .getSide ())
697
+ .putIfAbsent (limitsGroup .getId (), limitsGroup );
698
+ removedOperationalLimitsGroupsAttributes .remove (identifier );
699
+ }
644
700
});
645
701
fullyLoadedOperationalLimitsGroupsByBranchIds .add (branchId );
646
702
}
0 commit comments