aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroupRegistry.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroupRegistry.java
Publish
Diffstat (limited to 'config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroupRegistry.java')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroupRegistry.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroupRegistry.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroupRegistry.java
new file mode 100644
index 00000000000..fda962402d1
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/SourceGroupRegistry.java
@@ -0,0 +1,58 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.model.container.search.searchchain;
+
+import com.yahoo.component.ComponentId;
+import com.yahoo.component.ComponentSpecification;
+import com.yahoo.component.chain.model.ComponentAdaptor;
+import com.yahoo.component.provider.ComponentRegistry;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+
+/**
+ * Owns all the source groups in the search chains model.
+ * @author tonytv
+ */
+class SourceGroupRegistry {
+ private final ComponentRegistry<ComponentAdaptor<SourceGroup>> sourceGroups
+ = new ComponentRegistry<>();
+
+ private void add(Source source) {
+ getGroup(source.getComponentId()).add(source);
+ }
+
+ private SourceGroup getGroup(ComponentId sourceId) {
+ ComponentAdaptor<SourceGroup> group =
+ sourceGroups.getComponent(sourceId);
+ if (group == null) {
+ group = new ComponentAdaptor<>(sourceId,
+ new SourceGroup(sourceId));
+ sourceGroups.register(group.getId(), group);
+ }
+ return group.model;
+ }
+
+ void addSources(Provider provider) {
+ for (Source source : provider.getSources()) {
+ add(source);
+ }
+ }
+
+ public Collection<SourceGroup> groups() {
+ List<SourceGroup> result = new ArrayList<>();
+ for (ComponentAdaptor<SourceGroup> group :
+ sourceGroups.allComponents()) {
+ result.add(group.model);
+ }
+ return result;
+ }
+
+ public SourceGroup getComponent(ComponentSpecification spec) {
+ ComponentAdaptor<SourceGroup> result = sourceGroups.getComponent(spec);
+ return (result != null)?
+ result.model :
+ null;
+ }
+}