4
4
import com .squareup .okhttp .Call ;
5
5
import io .kubernetes .client .*;
6
6
import io .kubernetes .client .informer .impl .DefaultSharedIndexInformer ;
7
+ import io .kubernetes .client .util .CallGenerator ;
7
8
import io .kubernetes .client .util .CallGeneratorParams ;
8
9
import io .kubernetes .client .util .Watch ;
9
10
import io .kubernetes .client .util .common .Collections ;
13
14
import java .util .concurrent .ExecutorService ;
14
15
import java .util .concurrent .Executors ;
15
16
import java .util .concurrent .Future ;
16
- import java .util .function .Function ;
17
17
18
18
/** SharedInformerFactory class constructs and caches informers for api types. */
19
19
public class SharedInformerFactory {
@@ -51,7 +51,7 @@ public SharedInformerFactory(ExecutorService threadPool) {
51
51
* @return the shared index informer
52
52
*/
53
53
public synchronized <ApiType , ApiListType > SharedIndexInformer <ApiType > sharedIndexInformerFor (
54
- Function < CallGeneratorParams , Call > callGenerator ,
54
+ CallGenerator callGenerator ,
55
55
Class <ApiType > apiTypeClass ,
56
56
Class <ApiListType > apiListTypeClass ) {
57
57
return sharedIndexInformerFor (callGenerator , apiTypeClass , apiListTypeClass , 0 );
@@ -70,7 +70,7 @@ public synchronized <ApiType, ApiListType> SharedIndexInformer<ApiType> sharedIn
70
70
* @return the shared index informer
71
71
*/
72
72
public synchronized <ApiType , ApiListType > SharedIndexInformer <ApiType > sharedIndexInformerFor (
73
- Function < CallGeneratorParams , Call > callGenerator ,
73
+ CallGenerator callGenerator ,
74
74
Class <ApiType > apiTypeClass ,
75
75
Class <ApiListType > apiListTypeClass ,
76
76
long resyncPeriodInMillis ) {
@@ -84,20 +84,20 @@ public synchronized <ApiType, ApiListType> SharedIndexInformer<ApiType> sharedIn
84
84
}
85
85
86
86
private <ApiType , ApiListType > ListerWatcher <ApiType , ApiListType > listerWatcherFor (
87
- Function < CallGeneratorParams , Call > callGenerator ,
87
+ CallGenerator callGenerator ,
88
88
Class <ApiType > apiTypeClass ,
89
89
Class <ApiListType > apiListTypeClass ) {
90
90
ApiClient apiClient = Configuration .getDefaultApiClient ();
91
91
return new ListerWatcher <ApiType , ApiListType >() {
92
92
@ Override
93
93
public ApiListType list (CallGeneratorParams params ) throws ApiException {
94
- Call call = callGenerator .apply (params );
94
+ Call call = callGenerator .generate (params );
95
95
return (ApiListType ) apiClient .execute (call , apiListTypeClass ).getData ();
96
96
}
97
97
98
98
@ Override
99
99
public Watch <ApiType > watch (CallGeneratorParams params ) throws ApiException {
100
- Call call = callGenerator .apply (params );
100
+ Call call = callGenerator .generate (params );
101
101
return Watch .createWatch (
102
102
apiClient ,
103
103
call ,
@@ -106,6 +106,19 @@ public Watch<ApiType> watch(CallGeneratorParams params) throws ApiException {
106
106
};
107
107
}
108
108
109
+ /**
110
+ * Gets existing shared index informer, return null if the requesting informer is never
111
+ * constructed.
112
+ *
113
+ * @param <ApiType> the type parameter
114
+ * @param apiTypeClass the api type class
115
+ * @return the existing shared index informer
116
+ */
117
+ public synchronized <ApiType > SharedIndexInformer <ApiType > getExistingSharedIndexInformer (
118
+ Class <ApiType > apiTypeClass ) {
119
+ return this .informers .get (TypeToken .get (apiTypeClass ).getType ());
120
+ }
121
+
109
122
/** Start all registered informers. */
110
123
public synchronized void startAllRegisteredInformers () {
111
124
if (Collections .isEmptyMap (informers )) {
0 commit comments