From c3360b7ee9baead8f13027abfa1df42d1ffa4990 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 12 Apr 2019 11:39:38 +0800 Subject: [PATCH] polish code and fix (#3761) (#3838) --- README.md | 6 +++--- .../dubbo/cache/support/expiring/ExpiringCache.java | 2 +- .../apache/dubbo/cache/support/expiring/ExpiringMap.java | 2 +- .../org/apache/dubbo/cache/support/jcache/JCache.java | 2 +- .../java/org/apache/dubbo/cache/support/lru/LruCache.java | 2 +- .../dubbo/cache/support/threadlocal/ThreadLocalCache.java | 7 +------ .../dubbo/validation/support/AbstractValidation.java | 2 +- .../dubbo/validation/support/jvalidation/JValidator.java | 8 ++++---- .../definition/builder/CollectionTypeBuilder.java | 2 +- .../metadata/definition/builder/EnumTypeBuilder.java | 2 +- .../dubbo/metadata/definition/builder/MapTypeBuilder.java | 3 +-- .../dubbo/metadata/definition/model/MethodDefinition.java | 2 +- .../metadata/definition/model/ServiceDefinition.java | 4 ++-- .../dubbo/metadata/definition/model/TypeDefinition.java | 4 ++-- .../apache/dubbo/metadata/definition/util/ClassUtils.java | 2 +- .../src/main/java/org/apache/dubbo/rpc/Filter.java | 8 ++++++++ 16 files changed, 30 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 2323272b390..513da15bd55 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ public class GreetingServiceImpl implements GreetingService { } ``` -*See [provider/GreetingServiceImpl.java](https://github.com/apache/incubator-dubbo-samples/blob/master/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java) on GitHub.* +*See [provider/GreetingServiceImpl.java](https://github.com/apache/incubator-dubbo-samples/blob/master/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/GreetingsServiceImpl.java) on GitHub.* ### Start service provider @@ -115,7 +115,7 @@ public class Application { } ``` -*See [provider/Application.java](https://github.com/apache/incubator-dubbo-samples/blob/master/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/Application.java) on GitHub.* +*See [provider/Application.java](https://github.com/apache/incubator-dubbo-samples/blob/master/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/Application.java) on GitHub.* ### Build and run the provider @@ -155,7 +155,7 @@ public class Application { The consumer will print out `Hello world` on the screen. -*See [consumer/Application.java](https://github.com/apache/incubator-dubbo-samples/blob/master/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/consumer/Application.java) on GitHub.* +*See [consumer/Application.java](https://github.com/apache/incubator-dubbo-samples/blob/master/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/Application.java) on GitHub.* ### Next steps diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java index 9295718dfc7..afaf8c6135e 100644 --- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java +++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java @@ -48,7 +48,7 @@ public ExpiringCache(URL url) { final int secondsToLive = url.getParameter("cache.seconds", 180); // Cache check interval (second) final int intervalSeconds = url.getParameter("cache.interval", 4); - ExpiringMap expiringMap = new ExpiringMap(secondsToLive, intervalSeconds); + ExpiringMap expiringMap = new ExpiringMap<>(secondsToLive, intervalSeconds); expiringMap.getExpireThread().startExpiryIfNotStarted(); this.store = expiringMap; } diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java index 381a43ada87..8f25c8d835e 100644 --- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java +++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java @@ -60,7 +60,7 @@ public ExpiringMap(int timeToLive) { } public ExpiringMap(int timeToLive, int expirationInterval) { - this(new ConcurrentHashMap(), timeToLive, expirationInterval); + this(new ConcurrentHashMap<>(), timeToLive, expirationInterval); } private ExpiringMap(ConcurrentHashMap delegateMap, int timeToLive, int expirationInterval) { diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java index 4be16c84b3e..0aae511dd62 100644 --- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java +++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java @@ -57,7 +57,7 @@ public JCache(URL url) { try { //configure the cache MutableConfiguration config = - new MutableConfiguration() + new MutableConfiguration<>() .setTypes(Object.class, Object.class) .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, url.getMethodParameter(method, "cache.write.expire", 60 * 1000)))) .setStoreByValue(false) diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCache.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCache.java index 1d745804d83..bb24fed9b22 100644 --- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCache.java +++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCache.java @@ -54,7 +54,7 @@ public class LruCache implements Cache { */ public LruCache(URL url) { final int max = url.getParameter("cache.size", 1000); - this.store = new LRUCache(max); + this.store = new LRUCache<>(max); } /** diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCache.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCache.java index 0f35ed3315e..412e1beae28 100644 --- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCache.java +++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCache.java @@ -51,12 +51,7 @@ public class ThreadLocalCache implements Cache { * @param url */ public ThreadLocalCache(URL url) { - this.store = new ThreadLocal>() { - @Override - protected Map initialValue() { - return new HashMap(); - } - }; + this.store = ThreadLocal.withInitial(HashMap::new); } /** diff --git a/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/AbstractValidation.java b/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/AbstractValidation.java index 17f6646f526..be161a94d7c 100644 --- a/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/AbstractValidation.java +++ b/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/AbstractValidation.java @@ -33,7 +33,7 @@ */ public abstract class AbstractValidation implements Validation { - private final ConcurrentMap validators = new ConcurrentHashMap(); + private final ConcurrentMap validators = new ConcurrentHashMap<>(); @Override public Validator getValidator(URL url) { diff --git a/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidator.java b/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidator.java index 735b37d76c8..86775de4813 100644 --- a/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidator.java +++ b/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/support/jvalidation/JValidator.java @@ -140,7 +140,7 @@ private static Object getMethodParameterBean(Class clazz, Method method, Obje if (Modifier.isPublic(member.getModifiers()) && member.getParameterTypes().length == 0 && member.getDeclaringClass() == annotation.annotationType()) { - Object value = member.invoke(annotation, new Object[0]); + Object value = member.invoke(annotation); if (null != value) { MemberValue memberValue = createMemberValue( classFile.getConstPool(), pool.get(member.getReturnType().getName()), value); @@ -295,15 +295,15 @@ private Class methodClass(String methodName) { private void validate(Set> violations, Object arg, Class... groups) { if (arg != null && !isPrimitives(arg.getClass())) { - if (Object[].class.isInstance(arg)) { + if (arg instanceof Object[]) { for (Object item : (Object[]) arg) { validate(violations, item, groups); } - } else if (Collection.class.isInstance(arg)) { + } else if (arg instanceof Collection) { for (Object item : (Collection) arg) { validate(violations, item, groups); } - } else if (Map.class.isInstance(arg)) { + } else if (arg instanceof Map) { for (Map.Entry entry : ((Map) arg).entrySet()) { validate(violations, entry.getKey(), groups); validate(violations, entry.getValue(), groups); diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/CollectionTypeBuilder.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/CollectionTypeBuilder.java index efdf239b209..de7dc73c1b3 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/CollectionTypeBuilder.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/CollectionTypeBuilder.java @@ -50,7 +50,7 @@ public TypeDefinition build(Type type, Class clazz, Map, TypeDefinit if (actualTypeArgs == null || actualTypeArgs.length != 1) { throw new IllegalArgumentException(MessageFormat.format( "[ServiceDefinitionBuilder] Collection type [{0}] with unexpected amount of arguments [{1}]." + Arrays.toString(actualTypeArgs), - new Object[]{type, actualTypeArgs})); + type, actualTypeArgs)); } Type actualType = actualTypeArgs[0]; diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/EnumTypeBuilder.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/EnumTypeBuilder.java index d0dea96302c..03953ebf24b 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/EnumTypeBuilder.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/EnumTypeBuilder.java @@ -40,7 +40,7 @@ public TypeDefinition build(Type type, Class clazz, Map, TypeDefinit TypeDefinition td = new TypeDefinition(clazz.getCanonicalName()); try { - Method methodValues = clazz.getDeclaredMethod("values", new Class[0]); + Method methodValues = clazz.getDeclaredMethod("values"); Object[] values = (Object[]) methodValues.invoke(clazz, new Object[0]); int length = values.length; for (int i = 0; i < length; i++) { diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/MapTypeBuilder.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/MapTypeBuilder.java index 771e421928a..905ad0728e0 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/MapTypeBuilder.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/builder/MapTypeBuilder.java @@ -48,8 +48,7 @@ public TypeDefinition build(Type type, Class clazz, Map, TypeDefinit Type[] actualTypeArgs = parameterizedType.getActualTypeArguments(); if (actualTypeArgs == null || actualTypeArgs.length != 2) { throw new IllegalArgumentException(MessageFormat.format( - "[ServiceDefinitionBuilder] Map type [{0}] with unexpected amount of arguments [{1}]." + Arrays.toString(actualTypeArgs), new Object[]{ - type, actualTypeArgs})); + "[ServiceDefinitionBuilder] Map type [{0}] with unexpected amount of arguments [{1}]." + Arrays.toString(actualTypeArgs), type, actualTypeArgs)); } for (Type actualType : actualTypeArgs) { diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java index 3746ab5b9bd..41ebda505cd 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java @@ -37,7 +37,7 @@ public String getName() { public List getParameters() { if (parameters == null) { - parameters = new ArrayList(); + parameters = new ArrayList<>(); } return parameters; } diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java index 78d3bcb6f66..ebc586d2629 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java @@ -40,14 +40,14 @@ public String getCodeSource() { public List getMethods() { if (methods == null) { - methods = new ArrayList(); + methods = new ArrayList<>(); } return methods; } public List getTypes() { if (types == null) { - types = new ArrayList(); + types = new ArrayList<>(); } return types; } diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java index 7ca5bd894aa..bb434dc848b 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java @@ -59,14 +59,14 @@ public String getId() { public List getItems() { if (items == null) { - items = new ArrayList(); + items = new ArrayList<>(); } return items; } public Map getProperties() { if (properties == null) { - properties = new HashMap(); + properties = new HashMap<>(); } return properties; } diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/ClassUtils.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/ClassUtils.java index 3257de5409d..7c7eacb3ac0 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/ClassUtils.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/util/ClassUtils.java @@ -64,7 +64,7 @@ public static String getCodeSource(Class clazz) { * @return field list */ public static List getNonStaticFields(final Class clazz) { - List result = new ArrayList(); + List result = new ArrayList<>(); Class target = clazz; while (target != null) { if (JaketConfigurationUtils.isExcludedType(target)) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Filter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Filter.java index e94c985ae8a..a17fd906d55 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Filter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Filter.java @@ -61,6 +61,14 @@ public interface Filter { */ Result invoke(Invoker invoker, Invocation invocation) throws RpcException; + /** + * Return processing result + * + * @param result result + * @param invoker invoker + * @param invocation invocation + * @return Return {@link Result} + */ default Result onResponse(Result result, Invoker invoker, Invocation invocation) { return result; }