Skip to content

Commit

Permalink
Improved: Enforce noninstantiability to ServiceGroupReader Class. (#177)
Browse files Browse the repository at this point in the history
(OFBIZ-11750)
Made class as final, added private constructor and corrected private data member name as per naming convention.
  • Loading branch information
surajkhurana committed Jun 4, 2020
1 parent af78727 commit e92becb
Showing 1 changed file with 8 additions and 6 deletions.
Expand Up @@ -35,12 +35,14 @@
/**
* ServiceGroupReader.java
*/
public class ServiceGroupReader {
public final class ServiceGroupReader {

private static final String MODULE = ServiceGroupReader.class.getName();
// using a cache is dangerous here because if someone clears it the groups won't work at all:
// public static UtilCache GROUPS_CACHE = new UtilCache("service.ServiceGroups", 0, 0, false);
private static final Map<String, GroupModel> GROUPS_CACHE = new ConcurrentHashMap<>();

// using a cache is dangerous here because if someone clears it the groups won't work at all: public static UtilCache groupsCache = new UtilCache("service.ServiceGroups", 0, 0, false);
private static final Map<String, GroupModel> groupsCache = new ConcurrentHashMap<>();
protected ServiceGroupReader() { }

public static void readConfig() {
List<ServiceGroups> serviceGroupsList = null;
Expand Down Expand Up @@ -79,7 +81,7 @@ public static void addGroupDefinitions(ResourceHandler handler) {
Debug.logError("XML Parsing error: <group> element 'name' attribute null or empty", MODULE);
continue;
}
groupsCache.put(groupName, new GroupModel(group));
GROUPS_CACHE.put(groupName, new GroupModel(group));
numDefs++;
}
if (Debug.infoOn()) {
Expand All @@ -94,9 +96,9 @@ public static void addGroupDefinitions(ResourceHandler handler) {
}

public static GroupModel getGroupModel(String serviceName) {
if (groupsCache.size() == 0) {
if (GROUPS_CACHE.size() == 0) {
ServiceGroupReader.readConfig();
}
return groupsCache.get(serviceName);
return GROUPS_CACHE.get(serviceName);
}
}

0 comments on commit e92becb

Please sign in to comment.