15
15
import io .kubernetes .client .models .V1beta1Ingress ;
16
16
import io .kubernetes .client .util .Watch ;
17
17
import oracle .kubernetes .operator .TuningParameters ;
18
+ import oracle .kubernetes .operator .helpers .ClientPool ;
19
+ import oracle .kubernetes .operator .helpers .Pool ;
18
20
import oracle .kubernetes .operator .work .ContainerResolver ;
19
21
import oracle .kubernetes .weblogic .domain .v1 .Domain ;
20
22
import oracle .kubernetes .weblogic .domain .v1 .api .WeblogicApi ;
@@ -35,15 +37,13 @@ public class WatchBuilder {
35
37
36
38
private static WatchFactory FACTORY = new WatchFactoryImpl ();
37
39
38
- private ApiClient client ;
39
40
private CallParamsImpl callParams = new CallParamsImpl ();
40
41
41
42
public interface WatchFactory {
42
- <T > WatchI <T > createWatch (ApiClient client , CallParams callParams , Class <?> responseBodyType , BiFunction <ApiClient , CallParams , Call > function ) throws ApiException ;
43
+ <T > WatchI <T > createWatch (Pool < ApiClient > pool , CallParams callParams , Class <?> responseBodyType , BiFunction <ApiClient , CallParams , Call > function ) throws ApiException ;
43
44
}
44
45
45
- public WatchBuilder (ApiClient client ) {
46
- this .client = client ;
46
+ public WatchBuilder () {
47
47
TuningParameters tuning = ContainerResolver .getInstance ().getContainer ().getSPI (TuningParameters .class );
48
48
if (tuning != null ) {
49
49
callParams .setTimeoutSeconds (tuning .getWatchTuning ().watchLifetime );
@@ -76,7 +76,7 @@ public Type getOwnerType() {
76
76
* @throws ApiException if there is an error on the call that sets up the web hook.
77
77
*/
78
78
public WatchI <V1Service > createServiceWatch (String namespace ) throws ApiException {
79
- return FACTORY .createWatch (client , callParams , V1Service .class , new ListNamespacedServiceCall (namespace ));
79
+ return FACTORY .createWatch (ClientPool . getInstance () , callParams , V1Service .class , new ListNamespacedServiceCall (namespace ));
80
80
}
81
81
82
82
private class ListNamespacedServiceCall implements BiFunction <ApiClient , CallParams , Call > {
@@ -106,7 +106,7 @@ public Call apply(ApiClient client, CallParams callParams) {
106
106
* @throws ApiException if there is an error on the call that sets up the web hook.
107
107
*/
108
108
public WatchI <V1Pod > createPodWatch (String namespace ) throws ApiException {
109
- return FACTORY .createWatch (client , callParams , V1Pod .class , new ListPodCall (namespace ));
109
+ return FACTORY .createWatch (ClientPool . getInstance () , callParams , V1Pod .class , new ListPodCall (namespace ));
110
110
}
111
111
112
112
private class ListPodCall implements BiFunction <ApiClient , CallParams , Call > {
@@ -136,7 +136,7 @@ public Call apply(ApiClient client, CallParams callParams) {
136
136
* @throws ApiException if there is an error on the call that sets up the web hook.
137
137
*/
138
138
public WatchI <V1beta1Ingress > createIngressWatch (String namespace ) throws ApiException {
139
- return FACTORY .createWatch (client , callParams , V1beta1Ingress .class , new ListIngressCall (namespace ));
139
+ return FACTORY .createWatch (ClientPool . getInstance () , callParams , V1beta1Ingress .class , new ListIngressCall (namespace ));
140
140
}
141
141
142
142
private class ListIngressCall implements BiFunction <ApiClient , CallParams , Call > {
@@ -166,7 +166,7 @@ public Call apply(ApiClient client, CallParams callParams) {
166
166
* @throws ApiException if there is an error on the call that sets up the web hook.
167
167
*/
168
168
public WatchI <Domain > createDomainWatch (String namespace ) throws ApiException {
169
- return FACTORY .createWatch (client , callParams , Domain .class , new ListDomainsCall (namespace ));
169
+ return FACTORY .createWatch (ClientPool . getInstance () , callParams , Domain .class , new ListDomainsCall (namespace ));
170
170
}
171
171
172
172
private class ListDomainsCall implements BiFunction <ApiClient , CallParams , Call > {
@@ -196,7 +196,7 @@ public Call apply(ApiClient client, CallParams callParams) {
196
196
* @throws ApiException if there is an error on the call that sets up the web hook.
197
197
*/
198
198
public WatchI <V1ConfigMap > createConfigMapWatch (String namespace ) throws ApiException {
199
- return FACTORY .createWatch (client , callParams , V1ConfigMap .class , new ListNamespacedConfigMapCall (namespace ));
199
+ return FACTORY .createWatch (ClientPool . getInstance () , callParams , V1ConfigMap .class , new ListNamespacedConfigMapCall (namespace ));
200
200
}
201
201
202
202
private class ListNamespacedConfigMapCall implements BiFunction <ApiClient , CallParams , Call > {
@@ -280,9 +280,10 @@ public WatchBuilder withProgressRequestListener(ProgressRequestBody.ProgressRequ
280
280
281
281
static class WatchFactoryImpl implements WatchFactory {
282
282
@ Override
283
- public <T > WatchI <T > createWatch (ApiClient client , CallParams callParams , Class <?> responseBodyType , BiFunction <ApiClient , CallParams , Call > function ) throws ApiException {
283
+ public <T > WatchI <T > createWatch (Pool <ApiClient > pool , CallParams callParams , Class <?> responseBodyType , BiFunction <ApiClient , CallParams , Call > function ) throws ApiException {
284
+ ApiClient client = pool .take ();
284
285
try {
285
- return new WatchImpl <T >(Watch .createWatch (client , function .apply (client , callParams ), getType (responseBodyType )));
286
+ return new WatchImpl <T >(pool , client , Watch .createWatch (client , function .apply (client , callParams ), getType (responseBodyType )));
286
287
} catch (UncheckedApiException e ) {
287
288
throw e .getCause ();
288
289
}
0 commit comments