Technoboy- commented on a change in pull request #1384: URL: https://github.com/apache/shardingsphere-elasticjob/pull/1384#discussion_r472647842
########## File path: elasticjob-infra/elasticjob-restful/src/main/java/org/apache/shardingsphere/elasticjob/restful/handler/Handler.java ########## @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.elasticjob.restful.handler; + +import lombok.Getter; +import org.apache.shardingsphere.elasticjob.restful.Http; +import org.apache.shardingsphere.elasticjob.restful.annotation.ParamSource; +import org.apache.shardingsphere.elasticjob.restful.annotation.Param; +import org.apache.shardingsphere.elasticjob.restful.annotation.RequestBody; +import org.apache.shardingsphere.elasticjob.restful.annotation.Returning; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +/** + * Handle holds a handle method and an instance for method invoking. + * Describes parameters requirements of handle method. + */ +public final class Handler { + + private final Object instance; + + private final Method handleMethod; + + @Getter + private final List<HandlerParameter> handlerParameters; + + /** + * HTTP status code to return. + */ + @Getter + private final int httpStatusCode; + + /** + * Content type to producing. + */ + @Getter + private final String producing; + + public Handler(final Object instance, final Method handleMethod) { + this.instance = instance; + this.handleMethod = handleMethod; + this.handlerParameters = parseHandleMethodParameter(); + this.httpStatusCode = parseReturning(); + this.producing = parseProducing(); + } + + /** + * Execute handle method with required arguments. + * + * @param args Required arguments + * @return Method invoke result + * @throws InvocationTargetException Wraps exception thrown by invoked method + * @throws IllegalAccessException Handle method is not accessible + */ + public Object execute(final Object... args) throws InvocationTargetException, IllegalAccessException { + return handleMethod.invoke(instance, args); + } + + private List<HandlerParameter> parseHandleMethodParameter() { + List<HandlerParameter> params = new ArrayList<>(); Review comment: LinkedList is prefered ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
