11package io .javaoperatorsdk .operator .processing .event .source .polling ;
22
33import java .time .Duration ;
4- import java .util .*;
5- import java .util .concurrent .*;
4+ import java .util .Collections ;
5+ import java .util .HashSet ;
6+ import java .util .Map ;
7+ import java .util .Optional ;
8+ import java .util .Set ;
9+ import java .util .concurrent .ConcurrentHashMap ;
10+ import java .util .concurrent .ScheduledExecutorService ;
11+ import java .util .concurrent .ScheduledFuture ;
12+ import java .util .concurrent .ScheduledThreadPoolExecutor ;
13+ import java .util .concurrent .TimeUnit ;
614import java .util .function .Predicate ;
715
816import org .slf4j .Logger ;
917import org .slf4j .LoggerFactory ;
1018
1119import io .fabric8 .kubernetes .api .model .HasMetadata ;
1220import io .javaoperatorsdk .operator .OperatorException ;
21+ import io .javaoperatorsdk .operator .api .reconciler .EventSourceContext ;
1322import io .javaoperatorsdk .operator .processing .event .ResourceID ;
1423import io .javaoperatorsdk .operator .processing .event .source .Cache ;
1524import io .javaoperatorsdk .operator .processing .event .source .CacheKeyMapper ;
@@ -43,19 +52,82 @@ public class PerResourcePollingEventSource<R, P extends HasMetadata>
4352 private final long period ;
4453 private final Set <ResourceID > fetchedForPrimaries = ConcurrentHashMap .newKeySet ();
4554
55+ public PerResourcePollingEventSource (ResourceFetcher <R , P > resourceFetcher ,
56+ EventSourceContext <P > context , Duration defaultPollingPeriod ,
57+ Class <R > resourceClass ) {
58+ this (resourceFetcher , context .getPrimaryCache (), defaultPollingPeriod .toMillis (),
59+ null , resourceClass ,
60+ CacheKeyMapper .singleResourceCacheKeyMapper ());
61+ }
4662
63+ /**
64+ * @deprecated use the variant which uses {@link EventSourceContext} instead of {@link Cache} and
65+ * {@link Duration} for period parameter as it provides a more intuitive API.
66+ *
67+ * @param resourceFetcher fetches resource related to a primary resource
68+ * @param resourceCache cache of the primary resource
69+ * @param period default polling period
70+ * @param resourceClass class of the target resource
71+ */
72+ @ Deprecated (forRemoval = true )
4773 public PerResourcePollingEventSource (ResourceFetcher <R , P > resourceFetcher ,
4874 Cache <P > resourceCache , long period , Class <R > resourceClass ) {
4975 this (resourceFetcher , resourceCache , period , null , resourceClass ,
5076 CacheKeyMapper .singleResourceCacheKeyMapper ());
5177 }
5278
79+ public PerResourcePollingEventSource (ResourceFetcher <R , P > resourceFetcher ,
80+ EventSourceContext <P > context ,
81+ Duration defaultPollingPeriod ,
82+ Class <R > resourceClass ,
83+ CacheKeyMapper <R > cacheKeyMapper ) {
84+ this (resourceFetcher , context .getPrimaryCache (), defaultPollingPeriod .toMillis (),
85+ null , resourceClass , cacheKeyMapper );
86+ }
87+
88+ /**
89+ * @deprecated use the variant which uses {@link EventSourceContext} instead of {@link Cache} and
90+ * {@link Duration} for period parameter as it provides a more intuitive API.
91+ *
92+ * @param resourceFetcher fetches resource related to a primary resource
93+ * @param resourceCache cache of the primary resource
94+ * @param period default polling period
95+ * @param resourceClass class of the target resource
96+ * @param cacheKeyMapper use to distinguish resource in case more resources are handled for a
97+ * single primary resource
98+ */
99+ @ Deprecated (forRemoval = true )
53100 public PerResourcePollingEventSource (ResourceFetcher <R , P > resourceFetcher ,
54101 Cache <P > resourceCache , long period , Class <R > resourceClass ,
55102 CacheKeyMapper <R > cacheKeyMapper ) {
56103 this (resourceFetcher , resourceCache , period , null , resourceClass , cacheKeyMapper );
57104 }
58105
106+ public PerResourcePollingEventSource (ResourceFetcher <R , P > resourceFetcher ,
107+ EventSourceContext <P > context ,
108+ Duration defaultPollingPeriod ,
109+ Predicate <P > registerPredicate ,
110+ Class <R > resourceClass ,
111+ CacheKeyMapper <R > cacheKeyMapper ) {
112+ this (resourceFetcher , context .getPrimaryCache (), defaultPollingPeriod .toMillis (),
113+ registerPredicate , resourceClass , cacheKeyMapper ,
114+ new ScheduledThreadPoolExecutor (DEFAULT_EXECUTOR_THREAD_NUMBER ));
115+ }
116+
117+ /**
118+ * @deprecated use the variant which uses {@link EventSourceContext} instead of {@link Cache} and
119+ * {@link Duration} for period parameter as it provides a more intuitive API.
120+ *
121+ * @param resourceFetcher fetches resource related to a primary resource
122+ * @param resourceCache cache of the primary resource
123+ * @param period default polling period
124+ * @param resourceClass class of the target resource
125+ * @param cacheKeyMapper use to distinguish resource in case more resources are handled for a
126+ * single primary resource
127+ * @param registerPredicate used to determine if the related resource for a custom resource should
128+ * be polled or not.
129+ */
130+ @ Deprecated (forRemoval = true )
59131 public PerResourcePollingEventSource (ResourceFetcher <R , P > resourceFetcher ,
60132 Cache <P > resourceCache , long period ,
61133 Predicate <P > registerPredicate , Class <R > resourceClass ,
@@ -64,7 +136,35 @@ public PerResourcePollingEventSource(ResourceFetcher<R, P> resourceFetcher,
64136 new ScheduledThreadPoolExecutor (DEFAULT_EXECUTOR_THREAD_NUMBER ));
65137 }
66138
67- public PerResourcePollingEventSource (ResourceFetcher <R , P > resourceFetcher ,
139+
140+ public PerResourcePollingEventSource (
141+ ResourceFetcher <R , P > resourceFetcher ,
142+ EventSourceContext <P > context , Duration defaultPollingPeriod ,
143+ Predicate <P > registerPredicate , Class <R > resourceClass ,
144+ CacheKeyMapper <R > cacheKeyMapper , ScheduledExecutorService executorService ) {
145+ this (resourceFetcher , context .getPrimaryCache (), defaultPollingPeriod .toMillis (),
146+ registerPredicate ,
147+ resourceClass , cacheKeyMapper , executorService );
148+ }
149+
150+ /**
151+ * @deprecated use the variant which uses {@link EventSourceContext} instead of {@link Cache} and
152+ * {@link Duration} for period parameter as it provides a more intuitive API.
153+ *
154+ * @param resourceFetcher fetches resource related to a primary resource
155+ * @param resourceCache cache of the primary resource
156+ * @param period default polling period
157+ * @param resourceClass class of the target resource
158+ * @param cacheKeyMapper use to distinguish resource in case more resources are handled for a
159+ * single primary resource
160+ * @param registerPredicate used to determine if the related resource for a custom resource should
161+ * be polled or not.
162+ * @param executorService custom executor service
163+ */
164+
165+ @ Deprecated (forRemoval = true )
166+ public PerResourcePollingEventSource (
167+ ResourceFetcher <R , P > resourceFetcher ,
68168 Cache <P > resourceCache , long period ,
69169 Predicate <P > registerPredicate , Class <R > resourceClass ,
70170 CacheKeyMapper <R > cacheKeyMapper , ScheduledExecutorService executorService ) {
0 commit comments