1515import io .kubernetes .client .models .V1beta1Ingress ;
1616import io .kubernetes .client .util .Watch ;
1717import oracle .kubernetes .operator .TuningParameters ;
18+ import oracle .kubernetes .operator .helpers .ClientPool ;
19+ import oracle .kubernetes .operator .helpers .Pool ;
1820import oracle .kubernetes .operator .work .ContainerResolver ;
1921import oracle .kubernetes .weblogic .domain .v1 .Domain ;
2022import oracle .kubernetes .weblogic .domain .v1 .api .WeblogicApi ;
@@ -35,15 +37,13 @@ public class WatchBuilder {
3537
3638 private static WatchFactory FACTORY = new WatchFactoryImpl ();
3739
38- private ApiClient client ;
3940 private CallParamsImpl callParams = new CallParamsImpl ();
4041
4142 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 ;
4344 }
4445
45- public WatchBuilder (ApiClient client ) {
46- this .client = client ;
46+ public WatchBuilder () {
4747 TuningParameters tuning = ContainerResolver .getInstance ().getContainer ().getSPI (TuningParameters .class );
4848 if (tuning != null ) {
4949 callParams .setTimeoutSeconds (tuning .getWatchTuning ().watchLifetime );
@@ -76,7 +76,7 @@ public Type getOwnerType() {
7676 * @throws ApiException if there is an error on the call that sets up the web hook.
7777 */
7878 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 ));
8080 }
8181
8282 private class ListNamespacedServiceCall implements BiFunction <ApiClient , CallParams , Call > {
@@ -106,7 +106,7 @@ public Call apply(ApiClient client, CallParams callParams) {
106106 * @throws ApiException if there is an error on the call that sets up the web hook.
107107 */
108108 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 ));
110110 }
111111
112112 private class ListPodCall implements BiFunction <ApiClient , CallParams , Call > {
@@ -136,7 +136,7 @@ public Call apply(ApiClient client, CallParams callParams) {
136136 * @throws ApiException if there is an error on the call that sets up the web hook.
137137 */
138138 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 ));
140140 }
141141
142142 private class ListIngressCall implements BiFunction <ApiClient , CallParams , Call > {
@@ -166,7 +166,7 @@ public Call apply(ApiClient client, CallParams callParams) {
166166 * @throws ApiException if there is an error on the call that sets up the web hook.
167167 */
168168 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 ));
170170 }
171171
172172 private class ListDomainsCall implements BiFunction <ApiClient , CallParams , Call > {
@@ -196,7 +196,7 @@ public Call apply(ApiClient client, CallParams callParams) {
196196 * @throws ApiException if there is an error on the call that sets up the web hook.
197197 */
198198 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 ));
200200 }
201201
202202 private class ListNamespacedConfigMapCall implements BiFunction <ApiClient , CallParams , Call > {
@@ -280,9 +280,10 @@ public WatchBuilder withProgressRequestListener(ProgressRequestBody.ProgressRequ
280280
281281 static class WatchFactoryImpl implements WatchFactory {
282282 @ 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 ();
284285 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 )));
286287 } catch (UncheckedApiException e ) {
287288 throw e .getCause ();
288289 }
0 commit comments