Skip to content

Commit

Permalink
refactor RpcController
Browse files Browse the repository at this point in the history
  • Loading branch information
ponfee committed May 11, 2024
1 parent 70afe89 commit f55d30b
Show file tree
Hide file tree
Showing 22 changed files with 186 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import cn.ponfee.disjob.common.util.Numbers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -239,6 +240,16 @@ public static <S, T> List<T> convert(List<S> source, Function<S, T> mapper) {
return source.stream().map(mapper).collect(ImmutableList.toImmutableList());
}

public static <S, T> Set<T> convert(Set<S> source, Function<S, T> mapper) {
if (source == null) {
return null;
}
if (source.isEmpty()) {
return Collections.emptySet();
}
return source.stream().map(mapper).collect(ImmutableSet.toImmutableSet());
}

@SafeVarargs
public static <T> List<T> concat(List<T> list, T... array) {
if (list == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public final class ThreadPoolExecutors {
public static final int MAX_CAP = 0x7FFF;

// ----------------------------------------------------------build-in rejected policy

/**
* Throw RejectedExecutionException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package cn.ponfee.disjob.common.spring;

import cn.ponfee.disjob.common.date.JavaUtilDateFormat;
import cn.ponfee.disjob.common.spring.JacksonDateConfigurer.JacksonDateConfiguration;
import cn.ponfee.disjob.common.util.Jsons;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -34,12 +35,11 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Import(JacksonDateConfigurer.Configurer.class)
@Import(JacksonDateConfiguration.class)
public @interface JacksonDateConfigurer {

class Configurer {

public Configurer(@Nullable ObjectMapper objectMapper) {
class JacksonDateConfiguration {
public JacksonDateConfiguration(@Nullable ObjectMapper objectMapper) {
if (objectMapper == null) {
return;
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package cn.ponfee.disjob.common.spring;

import cn.ponfee.disjob.common.collect.Collects;
import cn.ponfee.disjob.common.spring.MybatisDataSourceConfigurer.MybatisDataSourceRegistrar;
import cn.ponfee.disjob.common.util.Strings;
import com.google.common.base.CaseFormat;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -78,7 +79,7 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Import(MybatisDataSourceConfigurer.MybatisDataSourceRegistrar.class)
@Import(MybatisDataSourceRegistrar.class)
public @interface MybatisDataSourceConfigurer {

String DATA_SOURCE_NAME_SUFFIX = "DataSource";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ public static MultiValueMap<String, String> convertToMultiValueMap(Map<String, O
* @param arguments the arguments
* @param <T> result type
* @return result object
* @see LocalizedMethodArguments
* @see LocalizedMethodArgumentResolver
* @see RpcControllerConfigurer
*/
public static <T> T invoke(RestTemplate restTemplate, String url, HttpMethod httpMethod,
Type returnType, Map<String, String> headersMap, Object... arguments) {
Expand All @@ -187,7 +186,7 @@ public static <T> T invoke(RestTemplate restTemplate, String url, HttpMethod htt
if (QUERY_PARAM_METHODS.contains(httpMethod)) {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
if (ArrayUtils.isNotEmpty(arguments)) {
builder.queryParams(LocalizedMethodArgumentUtils.buildQueryParams(arguments));
builder.queryParams(RpcControllerUtils.buildQueryParameters(arguments));
}
uri = builder.build().encode().toUri();
arguments = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@

package cn.ponfee.disjob.common.spring;

import org.springframework.core.annotation.AliasFor;
import org.springframework.web.bind.annotation.RestController;

import java.lang.annotation.*;

/**
* Mark this subclass is a spring web controller and with rpc({@code LocalizedMethodArguments}) trait
* RPC based spring mvc RestController
*
* @author Ponfee
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RestController
@LocalizedMethodArguments
public interface RpcController {
public @interface RpcController {

@AliasFor(annotation = RestController.class)
String value() default "";

}
Loading

0 comments on commit f55d30b

Please sign in to comment.