diff options
author | Arne H Juul <arnej@yahooinc.com> | 2021-11-29 09:37:40 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2021-11-29 09:37:40 +0000 |
commit | 142423294621e37c2d41606d4e364296660e5c52 (patch) | |
tree | e5f140b2850b06c6cbdd02eda65324df6726e376 /document | |
parent | 3446278e9bee71cebe9b4b2ebcb90e371b049557 (diff) |
refactor for better readability and robustness
Diffstat (limited to 'document')
-rw-r--r-- | document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java index 0c34b12a2a5..5ba3f4d6a6a 100644 --- a/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java +++ b/document/src/main/java/com/yahoo/document/DocumentTypeManagerConfigurer.java @@ -75,17 +75,24 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub apply(config); } } + private void apply(DocumentmanagerConfig config) { setupAnnotationTypesWithoutPayloads(config); setupAnnotationRefTypes(config); + setupDatatypesWithRetry(config); + addStructInheritance(config); + addAnnotationTypePayloads(config); + addAnnotationTypeInheritance(config); + manager.replaceTemporaryTypes(); + } - log.log(Level.FINE, "Configuring document manager with " + config.datatype().size() + " data types."); - ArrayList<DocumentmanagerConfig.Datatype> failed = new ArrayList<>(config.datatype()); - while (!failed.isEmpty()) { - ArrayList<DocumentmanagerConfig.Datatype> tmp = failed; - failed = new ArrayList<>(); - for (int i = 0; i < tmp.size(); i++) { - DocumentmanagerConfig.Datatype thisDataType = tmp.get(i); + private void setupDatatypesWithRetry(DocumentmanagerConfig config) { + var tmp = new ArrayList<DocumentmanagerConfig.Datatype>(config.datatype()); + log.log(Level.FINE, "Configuring document manager with " + tmp.size() + " data types."); + while (! tmp.isEmpty()) { + int oldSz = tmp.size(); + var failed = new ArrayList<DocumentmanagerConfig.Datatype>(); + for (DocumentmanagerConfig.Datatype thisDataType : tmp) { int id = thisDataType.id(); try { registerTypeIdMapping(thisDataType, id); @@ -93,12 +100,11 @@ public class DocumentTypeManagerConfigurer implements ConfigSubscriber.SingleSub failed.add(thisDataType); } } + tmp = failed; + if (tmp.size() == oldSz) { + throw new IllegalArgumentException("No progress registering datatypes"); + } } - addStructInheritance(config); - addAnnotationTypePayloads(config); - addAnnotationTypeInheritance(config); - - manager.replaceTemporaryTypes(); } private void registerTypeIdMapping(DocumentmanagerConfig.Datatype thisDataType, int id) { |