Skip to content

Commit

Permalink
Minor memory improvements for RR
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Sep 28, 2021
1 parent 6673d6b commit 06f005e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jboss.resteasy.reactive.common.model;

import java.util.Objects;

public class MethodParameter {
public String name;
public String type;
Expand Down Expand Up @@ -117,4 +119,25 @@ public String toString() {
", type='" + type + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
MethodParameter that = (MethodParameter) o;
return encoded == that.encoded && single == that.single && optional == that.optional
&& isObtainedAsCollection == that.isObtainedAsCollection && Objects.equals(name, that.name)
&& Objects.equals(type, that.type) && Objects.equals(declaredType, that.declaredType)
&& Objects.equals(declaredUnresolvedType, that.declaredUnresolvedType)
&& Objects.equals(signature, that.signature) && parameterType == that.parameterType
&& Objects.equals(defaultValue, that.defaultValue);
}

@Override
public int hashCode() {
return Objects.hash(name, type, declaredType, declaredUnresolvedType, signature, parameterType, encoded, single,
defaultValue, optional, isObtainedAsCollection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public class RuntimeResourceDeployment {
* If the runtime will always default to blocking (e.g. Servlet)
*/
private final boolean defaultBlocking;
private final BlockingHandler blockingHandler;
private final ResponseWriterHandler responseWriterHandler;

public RuntimeResourceDeployment(DeploymentInfo info, Supplier<Executor> executorSupplier,
CustomServerRestHandlers customServerRestHandlers,
Expand All @@ -119,6 +121,8 @@ public RuntimeResourceDeployment(DeploymentInfo info, Supplier<Executor> executo
this.dynamicEntityWriter = dynamicEntityWriter;
this.resourceLocatorHandler = resourceLocatorHandler;
this.defaultBlocking = defaultBlocking;
this.blockingHandler = new BlockingHandler(executorSupplier);
this.responseWriterHandler = new ResponseWriterHandler(dynamicEntityWriter);
}

public RuntimeResource buildResourceMethod(ResourceClass clazz,
Expand Down Expand Up @@ -180,7 +184,7 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz,
Optional<Integer> blockingHandlerIndex = Optional.empty();
if (!defaultBlocking) {
if (method.isBlocking()) {
handlers.add(new BlockingHandler(executorSupplier));
handlers.add(blockingHandler);
blockingHandlerIndex = Optional.of(handlers.size() - 1);
score.add(ScoreSystem.Category.Execution, ScoreSystem.Diagnostic.ExecutionBlocking);
} else {
Expand Down Expand Up @@ -401,25 +405,25 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz,
//in future there will be one per filter
List<ServerRestHandler> responseFilterHandlers;
if (method.isSse()) {
handlers.add(new SseResponseWriterHandler());
handlers.add(SseResponseWriterHandler.INSTANCE);
responseFilterHandlers = Collections.emptyList();
} else {
handlers.add(new ResponseHandler());
addHandlers(handlers, clazz, method, info, HandlerChainCustomizer.Phase.AFTER_RESPONSE_CREATED);
responseFilterHandlers = new ArrayList<>(interceptorDeployment.setupResponseFilterHandler());
handlers.addAll(responseFilterHandlers);
handlers.add(new ResponseWriterHandler(dynamicEntityWriter));
handlers.add(responseWriterHandler);
}
if (!clazz.resourceExceptionMapper().isEmpty() && (instanceHandler != null)) {
// when class level exception mapper are used, we need to make sure that an instance of resource class exists
// so we can invoke it
abortHandlingChain.add(instanceHandler);
}
abortHandlingChain.add(new ExceptionHandler());
abortHandlingChain.add(new ResponseHandler());
abortHandlingChain.add(ExceptionHandler.INSTANCE);
abortHandlingChain.add(ResponseHandler.INSTANCE);
abortHandlingChain.addAll(responseFilterHandlers);

abortHandlingChain.add(new ResponseWriterHandler(dynamicEntityWriter));
abortHandlingChain.add(responseWriterHandler);
handlers.add(0, new AbortChainHandler(abortHandlingChain.toArray(EMPTY_REST_HANDLER_ARRAY)));

return new RuntimeResource(method.getHttpMethod(), methodPathTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
public class ExceptionHandler implements ServerRestHandler {

public static final ExceptionHandler INSTANCE = new ExceptionHandler();

@Override
public void handle(ResteasyReactiveRequestContext requestContext) throws Exception {
requestContext.mapExceptionIfPresent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
public class ResponseHandler implements ServerRestHandler {

public static final ResponseHandler INSTANCE = new ResponseHandler();

@Override
public void handle(ResteasyReactiveRequestContext requestContext) throws Exception {
Object result = requestContext.getResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
public class SseResponseWriterHandler implements ServerRestHandler {

public static final SseResponseWriterHandler INSTANCE = new SseResponseWriterHandler();

public SseResponseWriterHandler() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass())
return false;
ServerMethodParameter that = (ServerMethodParameter) o;
if (!super.equals(that)) {
return false;
}
return Objects.equals(converter, that.converter)
&& Objects.equals(customParameterExtractor, that.customParameterExtractor);
}

@Override
public int hashCode() {
return Objects.hash(converter, customParameterExtractor);
return Objects.hash(converter, customParameterExtractor) + super.hashCode();
}
}

0 comments on commit 06f005e

Please sign in to comment.