-
Notifications
You must be signed in to change notification settings - Fork 275
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
Refactor AsyncRequestResponseHandlerFactory #1356
Conversation
Unify rest.server.request.handler.factory and rest.server.response.handler.factory Refactor AsyncRequestResponseHandlerFactory to factory pattern from singleton pattern Add setupResponseHandler for RestRquestService. Remove setupRequestHandling from AsyncRequestResponseHandler.
Codecov Report
@@ Coverage Diff @@
## master #1356 +/- ##
=========================================
Coverage ? 72.05%
Complexity ? 6612
=========================================
Files ? 480
Lines ? 37585
Branches ? 4753
=========================================
Hits ? 27082
Misses ? 9232
Partials ? 1271
Continue to review full report at Codecov.
|
*/ | ||
@Config("rest.server.request.handler.factory") | ||
@Config("rest.server.request.response.handler.factory") | ||
@Default("com.github.ambry.rest.AsyncRequestResponseHandlerFactory") | ||
public final String restServerRequestHandlerFactory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change variable name to restServerRequestResponseHandlerFactory
this.metrics = metrics; | ||
metrics.trackAsyncRequestResponseHandler(this); | ||
if (isRunning()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this condition ever occur since this is logic is now in the constructor and isRunning is a non-static member?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't happen. Removing.
|
||
private AsyncRequestResponseHandler handler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be final, I believe
@@ -24,6 +24,11 @@ | |||
*/ | |||
public interface RestRequestService { | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add that this method must be called before the service is started
I reviewed the changes in the second commit |
This PR is now independent. |
@@ -233,7 +235,7 @@ public void start() throws InstantiationException { | |||
restResponseHandler.start(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had an offline discussion with Ze. restResponseHandler
and restRequestHandler
are actually same instance within restHandlerFactory
. Hence, calling start() once should suffice. Let's leave a comment here to explain we removed restRequestHandler.start();
. In the future, we probably could unify them.
@Override | ||
public void start() throws InstantiationException { | ||
if (responseHandler == null) { | ||
throw new InstantiationException("ResponseHandler is not set."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel like this could be an IllegalStateException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after a few minor comments are addressed
this.restRequestService = restRequestService; | ||
logger.trace("Request handling units count set to {}", requestWorkersCount); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: line 268, could you removing the leading underscore of _restRequestService
?
} | ||
logger.trace("Instantiated AsyncRequestResponseHandlerFactory as RestRequestHandler"); | ||
} | ||
|
||
/** | ||
* Returns an instance of {@link AsyncRequestResponseHandler}. | ||
* @return an instance of {@link AsyncRequestResponseHandler}. | ||
* @return an handler of {@link AsyncRequestResponseHandler}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor typo: return a handler
or return an instance
} | ||
|
||
/** | ||
* Returns an instance of {@link AsyncRequestResponseHandler}. | ||
* @return an instance of {@link AsyncRequestResponseHandler}. | ||
* @return an handler of {@link AsyncRequestResponseHandler}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@@ -171,7 +124,7 @@ private static void buildInstance(MetricRegistry metricRegistry) { | |||
public final Counter residualResponseSetSize; | |||
|
|||
/** | |||
* Creates an instance of RequestResponseHandlerMetrics using the given {@code metricRegistry}. | |||
* Creates an handler of RequestResponseHandlerMetrics using the given {@code metricRegistry}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: no need to change previous comment.
private final RestRequestService restRequestService; | ||
|
||
public MockRestRequestResponseHandler(RestRequestService restRequestService) { | ||
this.restRequestService = restRequestService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to check if restRequestService
is null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's mock, I think it's ok to throw null exception.
requestResponseHandler.setupRequestHandling(1, null); | ||
fail("Setting RestRequestService to null should have thrown exception"); | ||
requestResponseHandler = getAsyncRequestResponseHandler(-1); | ||
fail("Setting request workers < 0 should have thrown exception"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the difference between line 165 and line 173 test cases ?
Unify rest.server.request.handler.factory and rest.server.response.handler.factory
Refactor AsyncRequestResponseHandlerFactory to factory pattern from singleton pattern
Add setupResponseHandler for RestRequestService.
Remove setupRequestHandling from AsyncRequestResponseHandler.
A regular order to start rest handler would be: