Skip to content
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

[#417] refactor: Eliminate raw use of parameterized class #891

Merged

Conversation

cchung100m
Copy link
Collaborator

Hi @zuston @advancedxy

Any comments and suggestions would be appreciated if you are available, thank you.

What changes were proposed in this pull request?

Eliminate raw use of parameterized class

Why are the changes needed?

Fix: #417

Does this PR introduce any user-facing change?

No.

How was this patch tested?

current UT

@cchung100m cchung100m changed the title [apache#417][Improvement] Eliminate raw use of parameterized class [#417][Improvement] Eliminate raw use of parameterized class May 19, 2023
@cchung100m cchung100m marked this pull request as draft May 19, 2023 07:05
@cchung100m cchung100m marked this pull request as ready for review May 19, 2023 07:25
@codecov-commenter
Copy link

codecov-commenter commented May 19, 2023

Codecov Report

Merging #891 (9283469) into master (3e58805) will increase coverage by 1.84%.
The diff coverage is 25.00%.

@@             Coverage Diff              @@
##             master     #891      +/-   ##
============================================
+ Coverage     55.24%   57.08%   +1.84%     
  Complexity     2201     2201              
============================================
  Files           333      313      -20     
  Lines         16449    14089    -2360     
  Branches       1307     1307              
============================================
- Hits           9087     8043    -1044     
+ Misses         6851     5606    -1245     
+ Partials        511      440      -71     
Impacted Files Coverage Δ
...va/org/apache/uniffle/client/util/ClientUtils.java 56.25% <ø> (ø)
...ava/org/apache/uniffle/common/util/RetryUtils.java 71.42% <0.00%> (ø)
...e/uniffle/coordinator/web/servlet/BaseServlet.java 10.00% <ø> (ø)
...dinator/web/servlet/CancelDecommissionServlet.java 27.27% <ø> (ø)
...e/coordinator/web/servlet/DecommissionServlet.java 27.27% <ø> (ø)
.../uniffle/coordinator/web/servlet/NodesServlet.java 20.00% <0.00%> (ø)
...java/org/apache/uniffle/common/util/JavaUtils.java 71.42% <50.00%> (ø)

... and 20 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -32,7 +32,7 @@ public static <T> T retry(RetryCmd<T> cmd, long intervalMs, int retryTimes) thro
}

public static <T> T retry(RetryCmd<T> cmd, long intervalMs, int retryTimes,
Set<Class> exceptionClasses) throws Throwable {
Set<Class<? extends Object>> exceptionClasses) throws Throwable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe Class<? extends Throwable> is preferred.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @advancedxy
Thanks for the kind reminder, I updated the part you mentioned.

private Response handlerRequest(
Callable<Response> function) {
Response response;
private <T> Response<T> handlerRequest(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be more suitable to make BaseServlet a generic class BaseServlet<T>?

@xianjingfeng what do you think?

Copy link
Member

@xianjingfeng xianjingfeng May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, it is allowed that the same servlet returns different data types.

Copy link
Member

@xianjingfeng xianjingfeng May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Response<Object> or Response<?> ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, it is allowed that the same servlet returns different data types.

Yeah, I get the flexibility. However, most of the servlets just return the same data type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No rules,We can implement all REST api through one servlet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can implement all REST api through one servlet.

If we are going to implement all REST API through one servlet, then there's no point to make this handlerRequest method a generic method. It should be simply defined as private Response<Object> handleRequest(...) then..

I would propose to something like this

public abstract class BaseServlet<T> extends HttpServlet {

  private Response<T> handlerRequest(
      Callable<Response<T>> function) {
    Response<T> response;
    try {
      // todo: Do something for authentication
      response = function.call();
    } catch (Exception e) {
      response = Response.fail(e.getMessage());
    }
    return response;
  }

  protected Response<T> handleGet(
      HttpServletRequest req,
      HttpServletResponse resp) throws ServletException, IOException {
    ...
  }

  protected Response<T> handlePost(
      HttpServletRequest req,
      HttpServletResponse resp) throws ServletException, IOException {
    ...
  }

}

For concrete servlet which handles and returns only one type should implement it with a concrete type.

For servlet that might return multiple types could defined it as

public class AnyReturnServlet extends BaseServlet<Object> {
  ...
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is ok for me.I don't care too much about this. Because maybe we are going to use jersey. #864

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @advancedxy @xianjingfeng

Thank you for sharing your thoughts and active feedback. I am open to whether make BaseServlet a generic class or not. Willing to do the change if we have a conclusion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am open to whether make BaseServlet a generic class or not. Willing to do the change if we have a conclusion.

Let's make it a generic class first, then we could replace it with jersey

@cchung100m cchung100m force-pushed the refactor_417_raw_use_of_parameterized_class branch from 4d39124 to 9283469 Compare May 24, 2023 10:31
@jerqi jerqi changed the title [#417][Improvement] Eliminate raw use of parameterized class [#417] refactor: Eliminate raw use of parameterized class May 24, 2023
@jerqi jerqi requested a review from advancedxy May 25, 2023 14:56
Copy link
Contributor

@advancedxy advancedxy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except the Servlet related change

@jerqi jerqi requested a review from advancedxy May 26, 2023 09:59
Copy link
Contributor

@jerqi jerqi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks all

@jerqi jerqi merged commit 753f426 into apache:master May 28, 2023
25 checks passed
@cchung100m cchung100m deleted the refactor_417_raw_use_of_parameterized_class branch July 6, 2023 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement] Eliminate raw use of parameterized class
5 participants