6
6
import java .util .Map ;
7
7
import java .util .Set ;
8
8
import java .util .concurrent .ConcurrentHashMap ;
9
+ import java .util .stream .Stream ;
9
10
10
11
public abstract class AbstractConfigurationService implements ConfigurationService {
11
12
@@ -17,10 +18,21 @@ public AbstractConfigurationService(Version version) {
17
18
}
18
19
19
20
protected <R extends CustomResource > void register (ControllerConfiguration <R > config ) {
21
+ put (config , true );
22
+ }
23
+
24
+ protected <R extends CustomResource > void replace (ControllerConfiguration <R > config ) {
25
+ put (config , false );
26
+ }
27
+
28
+ private <R extends CustomResource > void put (
29
+ ControllerConfiguration <R > config , boolean failIfExisting ) {
20
30
final var name = config .getName ();
21
- final var existing = configurations .get (name );
22
- if (existing != null ) {
23
- throwExceptionOnNameCollision (config .getAssociatedControllerClassName (), existing );
31
+ if (failIfExisting ) {
32
+ final var existing = configurations .get (name );
33
+ if (existing != null ) {
34
+ throwExceptionOnNameCollision (config .getAssociatedControllerClassName (), existing );
35
+ }
24
36
}
25
37
configurations .put (name , config );
26
38
}
@@ -39,7 +51,19 @@ protected void throwExceptionOnNameCollision(
39
51
@ Override
40
52
public <R extends CustomResource > ControllerConfiguration <R > getConfigurationFor (
41
53
ResourceController <R > controller ) {
42
- return configurations .get (ControllerUtils .getNameFor (controller ));
54
+ return configurations .get (keyFor (controller ));
55
+ }
56
+
57
+ protected String keyFor (ResourceController controller ) {
58
+ return ControllerUtils .getNameFor (controller );
59
+ }
60
+
61
+ protected ControllerConfiguration getFor (String controllerName ) {
62
+ return configurations .get (controllerName );
63
+ }
64
+
65
+ protected Stream <ControllerConfiguration > controllerConfigurations () {
66
+ return configurations .values ().stream ();
43
67
}
44
68
45
69
@ Override
0 commit comments