blob: 99ad7a291fc1c5aad9fe86113e134ea146edc84d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.component;
import com.yahoo.collections.Pair;
import com.yahoo.component.ComponentId;
import com.yahoo.component.ComponentSpecification;
import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.osgi.provider.model.ComponentModel;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* @author gjoranv
* @author tonytv
*/
public class Component<CHILD extends AbstractConfigProducer<?>, MODEL extends ComponentModel>
extends AbstractConfigProducer<CHILD> implements Comparable<Component<?, ?>> {
public final MODEL model;
final Set<Pair<String, Component>> injectedComponents = new LinkedHashSet<>();
public Component(MODEL model) {
super(model.getComponentId().stringValue());
this.model = model;
}
public ComponentId getGlobalComponentId() {
return model.getComponentId();
}
public ComponentId getComponentId() {
return model.getComponentId();
}
public ComponentSpecification getClassId() {
return model.getClassId();
}
public void inject(Component component) {
injectForName("", component);
}
public void injectForName(String name, Component component) {
injectedComponents.add(new Pair<>(name, component));
}
public void addComponent(CHILD child) {
addChild(child);
}
/** For testing only */
public Set<String> getInjectedComponentIds() {
Set<String> injectedIds = new HashSet<>();
for (Pair<String, Component> injected : injectedComponents) {
injectedIds.add(injected.getSecond().getSubId());
}
return injectedIds;
}
@Override
public int compareTo(Component<?, ?> other) {
return getComponentId().compareTo(other.getComponentId());
}
}
|