|
29 | 29 | import io.neonbee.endpoint.odatav4.internal.olingo.OlingoEndpointHandler; |
30 | 30 | import io.neonbee.entity.EntityModel; |
31 | 31 | import io.neonbee.internal.RegexBlockList; |
32 | | -import io.neonbee.internal.SharedDataAccessor; |
| 32 | +import io.neonbee.internal.SharedDataAccessorFactory; |
33 | 33 | import io.neonbee.logging.LoggingFacade; |
34 | 34 | import io.vertx.core.Future; |
35 | 35 | import io.vertx.core.Vertx; |
@@ -201,27 +201,35 @@ public Future<Router> createEndpointRouter(Vertx vertx, String basePath, JsonObj |
201 | 201 | // when NeonBee is started and / or in case the endpoint is not used. |
202 | 202 | Route initialRoute = router.route(); |
203 | 203 | initialRoute.handler( |
204 | | - routingContext -> new SharedDataAccessor(vertx, ODataV4Endpoint.class).getLocalLock(asyncLock -> |
205 | | - // immediately initialize the router, this will also "arm" the event bus listener |
206 | | - (!initialized.getAndSet(true) |
207 | | - ? refreshRouter(vertx, router, basePath, uriConversion, exposedEntities, models) |
208 | | - : succeededFuture()).onComplete(handler -> { |
209 | | - // wait for the refresh to finish (the result doesn't matter), remove the initial route, as |
210 | | - // this will redirect all requests to the registered service endpoint handlers (if non have |
211 | | - // been registered, e.g. due to a failure in model loading, it'll result in an 404). Could |
212 | | - // have been removed already by refreshRouter, we don't care! |
213 | | - initialRoute.remove(); |
214 | | - if (asyncLock.succeeded()) { |
215 | | - // releasing the lock will cause other requests unblock and not call the initial route |
216 | | - asyncLock.result().release(); |
217 | | - } |
218 | | - |
219 | | - // let the router again handle the context again, now with either all service endpoints |
220 | | - // registered, or none in case there have been a failure while loading the models. |
221 | | - // NOTE: Re-route is the only elegant way I found to restart the current router to take |
222 | | - // the new routes! Might consider checking again with the Vert.x 4.0 release. |
223 | | - routingContext.reroute(routingContext.request().uri()); |
224 | | - }))); |
| 204 | + routingContext -> new SharedDataAccessorFactory(vertx) |
| 205 | + .getSharedDataAccessor(ODataV4Endpoint.class) |
| 206 | + .getLocalLock(asyncLock -> |
| 207 | + // immediately initialize the router, this will also "arm" the event bus listener |
| 208 | + (!initialized.getAndSet(true) |
| 209 | + ? refreshRouter(vertx, router, basePath, uriConversion, exposedEntities, models) |
| 210 | + : succeededFuture()).onComplete(handler -> { |
| 211 | + // wait for the refresh to finish (the result doesn't matter), remove the initial |
| 212 | + // route, as |
| 213 | + // this will redirect all requests to the registered service endpoint handlers (if |
| 214 | + // non have |
| 215 | + // been registered, e.g. due to a failure in model loading, it'll result in an 404). |
| 216 | + // Could |
| 217 | + // have been removed already by refreshRouter, we don't care! |
| 218 | + initialRoute.remove(); |
| 219 | + if (asyncLock.succeeded()) { |
| 220 | + // releasing the lock will cause other requests unblock and not call the initial |
| 221 | + // route |
| 222 | + asyncLock.result().release(); |
| 223 | + } |
| 224 | + |
| 225 | + // let the router again handle the context again, now with either all service |
| 226 | + // endpoints |
| 227 | + // registered, or none in case there have been a failure while loading the models. |
| 228 | + // NOTE: Re-route is the only elegant way I found to restart the current router to |
| 229 | + // take |
| 230 | + // the new routes! Might consider checking again with the Vert.x 4.0 release. |
| 231 | + routingContext.reroute(routingContext.request().uri()); |
| 232 | + }))); |
225 | 233 |
|
226 | 234 | return succeededFuture(router); |
227 | 235 | } |
|
0 commit comments