-
Notifications
You must be signed in to change notification settings - Fork 58
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
[FEATURE] Refactor ExtensionsRunner class #116
Comments
😆 |
The following is plan to refactor class for ExtensionsRunner
|
The transport requests all follow the model, so this code could be extracted: public void sendFooRequest(TransportService transportService) {
logger.info("Sending " + foo + " request to OpenSearch");
TransportResponseHandler<Foo> handler = new FooHandler();
try {
transportService.sendRequest(
opensearchNode,
ExtensionsOrchestrator.REQUEST_FOO,
new ExtensionRequest(ExtensionsOrchestrator.RequestType.REQUEST_FOO),
fooResponseHandler
);
} catch (Exception e) {
logger.info("Failed to send " + foo + " request to OpenSearch", e);
}
} We could create a new class and instantiate it with Then we could create a
|
@dbwiddis Then create a new method based on the example code which shows on comment to make connect between For the |
@mloufra not quite. Let me go back to the "why" of this refactoring. When you see the same code repeated a lot it's good to put the repetitive stuff in one location so there's only a single method to test/debug. Lots of bugs slip in during copy/paste code where someone forgot to change one of the things they copied (for example, the log message on failure for the In this case, the "interesting" and "different" part of the code is in the embedded So the goal here is to create a single "helper" method somewhere (either in ExtensionsRunner, in an existing class related to the TransportService, or in a new class you create) that does the logging and exception handling parts. Then you can have just a single method call for each type in ExtensionsRunner passing the objects that are different to that same helper method. |
Thanks @dbwiddis for your clarification. I will update that on my plan. |
Due to delays caused by too frequent merge conflicts, I raise a PR for first step of my plan. After this PR getting merged, I will work on second step of my plan(to create new class handle Netty4 and initialize transport service method). |
Is your feature request related to a problem?
Originally posted by @peternied in #109 (comment)
What solution would you like?
There are 513 lines.
We can definitely separate out lines 157-471 into at least one other class, possibly two or three.
the(these are all single method calls but take up several lines, probably ok to leave).transportService.registerRequestHandler()
calls are all the same except for two lines, and could benefit from a helper method for the 80-90% of that code that is common.What alternatives have you considered?
Doing nothing. It's tempting.
Do you have any additional context?
Like most code, this starts small and grows to the point where the problem is obvious. We're there.
The text was updated successfully, but these errors were encountered: