Skip to content

Commit

Permalink
polish code and fix (apache#3761) (apache#3838)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenlushun authored and vio-lin committed Apr 29, 2019
1 parent c18a03c commit c3360b7
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 28 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object, Object> expiringMap = new ExpiringMap<Object, Object>(secondsToLive, intervalSeconds);
ExpiringMap<Object, Object> expiringMap = new ExpiringMap<>(secondsToLive, intervalSeconds);
expiringMap.getExpireThread().startExpiryIfNotStarted();
this.store = expiringMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ExpiringMap(int timeToLive) {
}

public ExpiringMap(int timeToLive, int expirationInterval) {
this(new ConcurrentHashMap<K, ExpiryObject>(), timeToLive, expirationInterval);
this(new ConcurrentHashMap<>(), timeToLive, expirationInterval);
}

private ExpiringMap(ConcurrentHashMap<K, ExpiryObject> delegateMap, int timeToLive, int expirationInterval) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public JCache(URL url) {
try {
//configure the cache
MutableConfiguration config =
new MutableConfiguration<Object, Object>()
new MutableConfiguration<>()
.setTypes(Object.class, Object.class)
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, url.getMethodParameter(method, "cache.write.expire", 60 * 1000))))
.setStoreByValue(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object, Object>(max);
this.store = new LRUCache<>(max);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ public class ThreadLocalCache implements Cache {
* @param url
*/
public ThreadLocalCache(URL url) {
this.store = new ThreadLocal<Map<Object, Object>>() {
@Override
protected Map<Object, Object> initialValue() {
return new HashMap<Object, Object>();
}
};
this.store = ThreadLocal.withInitial(HashMap::new);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public abstract class AbstractValidation implements Validation {

private final ConcurrentMap<String, Validator> validators = new ConcurrentHashMap<String, Validator>();
private final ConcurrentMap<String, Validator> validators = new ConcurrentHashMap<>();

@Override
public Validator getValidator(URL url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -295,15 +295,15 @@ private Class methodClass(String methodName) {

private void validate(Set<ConstraintViolation<?>> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, 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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, 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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public String getName() {

public List<TypeDefinition> getParameters() {
if (parameters == null) {
parameters = new ArrayList<TypeDefinition>();
parameters = new ArrayList<>();
}
return parameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public String getCodeSource() {

public List<MethodDefinition> getMethods() {
if (methods == null) {
methods = new ArrayList<MethodDefinition>();
methods = new ArrayList<>();
}
return methods;
}

public List<TypeDefinition> getTypes() {
if (types == null) {
types = new ArrayList<TypeDefinition>();
types = new ArrayList<>();
}
return types;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public String getId() {

public List<TypeDefinition> getItems() {
if (items == null) {
items = new ArrayList<TypeDefinition>();
items = new ArrayList<>();
}
return items;
}

public Map<String, TypeDefinition> getProperties() {
if (properties == null) {
properties = new HashMap<String, TypeDefinition>();
properties = new HashMap<>();
}
return properties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static String getCodeSource(Class<?> clazz) {
* @return field list
*/
public static List<Field> getNonStaticFields(final Class<?> clazz) {
List<Field> result = new ArrayList<Field>();
List<Field> result = new ArrayList<>();
Class<?> target = clazz;
while (target != null) {
if (JaketConfigurationUtils.isExcludedType(target)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c3360b7

Please sign in to comment.