2
2
3
3
import java .util .LinkedHashSet ;
4
4
import java .util .List ;
5
- import java .util .Map ;
6
5
import java .util .Objects ;
7
6
import java .util .Optional ;
8
7
import java .util .Set ;
9
8
import java .util .function .Function ;
10
9
import java .util .stream .Collectors ;
11
- import java .util .stream .Stream ;
12
10
13
11
import org .slf4j .Logger ;
14
12
import org .slf4j .LoggerFactory ;
@@ -69,27 +67,23 @@ public void postProcessDefaultEventSourcesAfterProcessorInitializer() {
69
67
*/
70
68
@ Override
71
69
public synchronized void start () {
72
- startEventSource (eventSources .namedControllerResourceEventSource ());
70
+ startEventSource (eventSources .controllerResourceEventSource ());
73
71
74
72
executorServiceManager .boundedExecuteAndWaitForAllToComplete (
75
- eventSources .additionalNamedEventSources ()
73
+ eventSources .additionalEventSources ()
76
74
.filter (es -> es .priority ().equals (EventSourceStartPriority .RESOURCE_STATE_LOADER )),
77
75
this ::startEventSource ,
78
76
getThreadNamer ("start" ));
79
77
80
78
executorServiceManager .boundedExecuteAndWaitForAllToComplete (
81
- eventSources .additionalNamedEventSources ()
79
+ eventSources .additionalEventSources ()
82
80
.filter (es -> es .priority ().equals (EventSourceStartPriority .DEFAULT )),
83
81
this ::startEventSource ,
84
82
getThreadNamer ("start" ));
85
83
}
86
84
87
- private static Function <NamedEventSource , String > getThreadNamer (String stage ) {
88
- return es -> {
89
- final var name = es .name ();
90
- return es .priority () + " " + stage + " -> "
91
- + (es .isNameSet () ? name + " " + es .original ().getClass () : es .original ());
92
- };
85
+ private static Function <EventSource , String > getThreadNamer (String stage ) {
86
+ return es -> es .priority () + " " + stage + " -> " + es .name ();
93
87
}
94
88
95
89
private static Function <NamespaceChangeable , String > getEventSourceThreadNamer (String stage ) {
@@ -98,28 +92,26 @@ private static Function<NamespaceChangeable, String> getEventSourceThreadNamer(S
98
92
99
93
@ Override
100
94
public synchronized void stop () {
101
- stopEventSource (eventSources .namedControllerResourceEventSource ());
95
+ stopEventSource (eventSources .controllerResourceEventSource ());
102
96
executorServiceManager .boundedExecuteAndWaitForAllToComplete (
103
- eventSources .additionalNamedEventSources (),
97
+ eventSources .additionalEventSources (),
104
98
this ::stopEventSource ,
105
99
getThreadNamer ("stop" ));
106
100
}
107
101
108
102
@ SuppressWarnings ("rawtypes" )
109
- private void logEventSourceEvent (NamedEventSource eventSource , String event ) {
103
+ private void logEventSourceEvent (EventSource eventSource , String event ) {
110
104
if (log .isDebugEnabled ()) {
111
- if (eventSource .original () instanceof ResourceEventSource source ) {
112
- log .debug ("{} event source {} for {}" , event ,
113
- eventSource .isNameSet () ? eventSource .name () : eventSource ,
105
+ if (eventSource instanceof ResourceEventSource source ) {
106
+ log .debug ("{} event source {} for {}" , event , eventSource .name (),
114
107
source .resourceType ());
115
108
} else {
116
- log .debug ("{} event source {}" , event ,
117
- eventSource .isNameSet () ? eventSource .name () : eventSource );
109
+ log .debug ("{} event source {}" , event , eventSource .name ());
118
110
}
119
111
}
120
112
}
121
113
122
- private Void startEventSource (NamedEventSource eventSource ) {
114
+ private Void startEventSource (EventSource eventSource ) {
123
115
try {
124
116
logEventSourceEvent (eventSource , "Starting" );
125
117
eventSource .start ();
@@ -132,7 +124,7 @@ private Void startEventSource(NamedEventSource eventSource) {
132
124
return null ;
133
125
}
134
126
135
- private Void stopEventSource (NamedEventSource eventSource ) {
127
+ private Void stopEventSource (EventSource eventSource ) {
136
128
try {
137
129
logEventSourceEvent (eventSource , "Stopping" );
138
130
eventSource .stop ();
@@ -149,13 +141,11 @@ public final synchronized void registerEventSource(EventSource eventSource)
149
141
Objects .requireNonNull (eventSource , "EventSource must not be null" );
150
142
try {
151
143
if (eventSource instanceof ManagedInformerEventSource managedInformerEventSource ) {
152
-
153
144
managedInformerEventSource .setConfigurationService (
154
145
controller .getConfiguration ().getConfigurationService ());
155
146
}
156
- final var named = new NamedEventSource (eventSource , eventSource .name ());
157
- eventSources .add (named );
158
- named .setEventHandler (controller .getEventProcessor ());
147
+ eventSources .add (eventSource );
148
+ eventSource .setEventHandler (controller .getEventProcessor ());
159
149
} catch (IllegalStateException | MissingCRDException e ) {
160
150
throw e ; // leave untouched
161
151
} catch (Exception e ) {
@@ -166,8 +156,7 @@ public final synchronized void registerEventSource(EventSource eventSource)
166
156
167
157
@ SuppressWarnings ("unchecked" )
168
158
public void broadcastOnResourceEvent (ResourceAction action , P resource , P oldResource ) {
169
- eventSources .additionalNamedEventSources ()
170
- .map (NamedEventSource ::original )
159
+ eventSources .additionalEventSources ()
171
160
.forEach (source -> {
172
161
if (source instanceof ResourceEventAware ) {
173
162
var lifecycleAwareES = ((ResourceEventAware <P >) source );
@@ -202,18 +191,12 @@ public void changeNamespaces(Set<String> namespaces) {
202
191
203
192
public Set <EventSource > getRegisteredEventSources () {
204
193
return eventSources .flatMappedSources ()
205
- .map (NamedEventSource ::original )
206
- .collect (Collectors .toCollection (LinkedHashSet ::new ));
207
- }
208
194
209
- public Map <String , EventSource > allEventSources () {
210
- return eventSources .allNamedEventSources ().collect (Collectors .toMap (NamedEventSource ::name ,
211
- NamedEventSource ::original ));
195
+ .collect (Collectors .toCollection (LinkedHashSet ::new ));
212
196
}
213
197
214
- @ SuppressWarnings ("unused" )
215
- public Stream <? extends EventSourceMetadata > getNamedEventSourcesStream () {
216
- return eventSources .flatMappedSources ();
198
+ public List <EventSource > allEventSources () {
199
+ return eventSources .allEventSources ().toList ();
217
200
}
218
201
219
202
public ControllerResourceEventSource <P > getControllerResourceEventSource () {
@@ -227,9 +210,9 @@ public <R> List<ResourceEventSource<R, P>> getResourceEventSourcesFor(Class<R> d
227
210
@ Override
228
211
public EventSource dynamicallyRegisterEventSource (EventSource eventSource ) {
229
212
synchronized (this ) {
230
- var actual = eventSources .existing (eventSource . name (), eventSource );
213
+ var actual = eventSources .existing (eventSource );
231
214
if (actual != null ) {
232
- eventSource = actual . eventSource () ;
215
+ eventSource = actual ;
233
216
} else {
234
217
registerEventSource (eventSource );
235
218
}
0 commit comments