-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safely register rest handlers outside of constructor #51622
Comments
Pinging @elastic/es-core-infra (:Core/Infra/REST API) |
Thanks for opening this @jaymode! This has long bugged me. In addition to the JLS violation, this makes the handlers more complicated to initialize, when they could mostly have empty ctors, and more error prone to write since you may forget to actually register yourself. WDYT about having BaseRestHandler have a method for returning a |
@rjernst that's exactly my plan and the change I will be working on. It is necessary for part of the approach I plan to take for the initial system indices implementation |
This commit changes how RestHandlers are registered with the RestController so that a RestHandler no longer needs to register itself with the RestController. Instead the RestHandler interface has new methods which when called provide information about the method and path combinations that are handled by the handler including any deprecated and/or replaced combinations. This change also makes the publication of RestHandlers safe since they no longer publish a reference to themselves within their constructors. Closes elastic#51622
commit 771b4e1 Author: jaymode <jay@elastic.co> Date: Thu Feb 6 14:41:36 2020 -0700 fix duplicated api commit 94f1124 Author: jaymode <jay@elastic.co> Date: Thu Feb 6 14:24:01 2020 -0700 update javadoc commit 7c14750 Merge: 171e368 f21b641 Author: jaymode <jay@elastic.co> Date: Thu Feb 6 14:21:00 2020 -0700 Merge branch 'master' into rest_handler_safe_register commit 171e368 Author: jaymode <jay@elastic.co> Date: Thu Feb 6 14:20:28 2020 -0700 refactor to routes commit 263e2d2 Author: jaymode <jay@elastic.co> Date: Wed Feb 5 11:44:24 2020 -0700 fix inference api commit 9167512 Author: jaymode <jay@elastic.co> Date: Wed Feb 5 10:51:34 2020 -0700 fixes commit 2a1d841 Author: jaymode <jay@elastic.co> Date: Tue Feb 4 21:18:39 2020 -0700 RestHandlers declare handled methods and paths This commit changes how RestHandlers are registered with the RestController so that a RestHandler no longer needs to register itself with the RestController. Instead the RestHandler interface has new methods which when called provide information about the method and path combinations that are handled by the handler including any deprecated and/or replaced combinations. This change also makes the publication of RestHandlers safe since they no longer publish a reference to themselves within their constructors. Closes elastic#51622
This commit changes how RestHandlers are registered with the RestController so that a RestHandler no longer needs to register itself with the RestController. Instead the RestHandler interface has new methods which when called provide information about the routes (method and path combinations) that are handled by the handler including any deprecated and/or replaced combinations. This change also makes the publication of RestHandlers safe since they no longer publish a reference to themselves within their constructors. Closes #51622 Co-authored-by: Jason Tedor <jason@tedor.me>
This commit changes how RestHandlers are registered with the RestController so that a RestHandler no longer needs to register itself with the RestController. Instead the RestHandler interface has new methods which when called provide information about the routes (method and path combinations) that are handled by the handler including any deprecated and/or replaced combinations. This change also makes the publication of RestHandlers safe since they no longer publish a reference to themselves within their constructors. Closes #51622 Co-authored-by: Jason Tedor <jason@tedor.me> Backport of #51950
The common pattern used by the RestHandler objects within the codebase is to have a constructor which registers the handler with the RestController for a set of paths and methods, such as:
This is publishing the
this
reference before the object is fully constructed, which violates the JLS. This is similar to issues we have with registering cluster state listeners within constructors, see #38560.The text was updated successfully, but these errors were encountered: