11package org .prebid .server .analytics .reporter .pubstack ;
22
3- import io .vertx .core .AsyncResult ;
43import io .vertx .core .Future ;
54import io .vertx .core .Promise ;
65import io .vertx .core .Vertx ;
@@ -119,19 +118,22 @@ public String name() {
119118 @ Override
120119 public void initialize (Promise <Void > initializePromise ) {
121120 vertx .setPeriodic (configurationRefreshDelay , id -> fetchRemoteConfig ());
122- fetchRemoteConfig ();
123- initializePromise .tryComplete ();
121+ fetchRemoteConfig ()
122+ .onSuccess (initializePromise ::succeed )
123+ .onFailure (initializePromise ::fail );
124124 }
125125
126126 void shutdown () {
127127 eventHandlers .values ().forEach (PubstackEventHandler ::reportEvents );
128128 }
129129
130- private void fetchRemoteConfig () {
130+ private Future < Void > fetchRemoteConfig () {
131131 logger .info ("[pubstack] Updating config: {}" , pubstackConfig );
132- httpClient .get (makeEventEndpointUrl (pubstackConfig .getEndpoint (), pubstackConfig .getScopeId ()), timeout )
132+ return httpClient .get (makeEventEndpointUrl (pubstackConfig .getEndpoint (), pubstackConfig .getScopeId ()), timeout )
133133 .map (this ::processRemoteConfigurationResponse )
134- .onComplete (this ::updateConfigsOnChange );
134+ .map (this ::updateConfigsOnChange )
135+ .onFailure (PubstackAnalyticsReporter ::logError )
136+ .mapEmpty ();
135137 }
136138
137139 private PubstackConfig processRemoteConfigurationResponse (HttpClientResponse response ) {
@@ -148,15 +150,14 @@ private PubstackConfig processRemoteConfigurationResponse(HttpClientResponse res
148150 }
149151 }
150152
151- private void updateConfigsOnChange (AsyncResult <PubstackConfig > asyncConfigResult ) {
152- if (asyncConfigResult .failed ()) {
153- logger .error ("[pubstask] Fail to fetch remote configuration: {}" , asyncConfigResult .cause ().getMessage ());
154- } else if (!Objects .equals (pubstackConfig , asyncConfigResult .result ())) {
155- final PubstackConfig pubstackConfig = asyncConfigResult .result ();
153+ private Void updateConfigsOnChange (PubstackConfig config ) {
154+ if (!Objects .equals (pubstackConfig , config )) {
156155 eventHandlers .values ().forEach (PubstackEventHandler ::reportEvents );
157- this .pubstackConfig = pubstackConfig ;
156+ this .pubstackConfig = config ;
158157 updateHandlers (pubstackConfig );
159158 }
159+
160+ return null ;
160161 }
161162
162163 private void updateHandlers (PubstackConfig pubstackConfig ) {
@@ -187,4 +188,8 @@ private String makeEventHandlerEndpoint(String endpoint, EventType eventType) {
187188 throw new PreBidException (message );
188189 }
189190 }
191+
192+ private static void logError (Throwable throwable ) {
193+ logger .error ("[pubstask] Fail to fetch remote configuration: {}" , throwable .getCause ().getMessage ());
194+ }
190195}
0 commit comments