[SCB-2604] Use lambad instead of annonymous class (#3128)
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/locator/MicroservicePaths.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/locator/MicroservicePaths.java
index 2137a04..21f014a 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/locator/MicroservicePaths.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/locator/MicroservicePaths.java
@@ -19,7 +19,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -44,7 +43,7 @@
public void sortPath() {
RestOperationComparator comparator = new RestOperationComparator();
- Collections.sort(this.dynamicPathOperationsList, comparator);
+ this.dynamicPathOperationsList.sort(comparator);
}
public void addResource(RestOperationMeta swaggerRestOperation) {
diff --git a/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/BeanRpcTest.java b/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/BeanRpcTest.java
index 69e7f0c..f5b1368 100644
--- a/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/BeanRpcTest.java
+++ b/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/BeanRpcTest.java
@@ -28,27 +28,25 @@
}
public void init() {
- new Thread() {
- public void run() {
- while (true) {
+ new Thread(() -> {
+ while (true) {
+ try {
+ System.out.println("XXXXXXXXXXXXXXXXXXXXXXXX" + test.getTestString(null));
+ break;
+ } catch (Exception e) {
+ e.printStackTrace();
try {
- System.out.println("XXXXXXXXXXXXXXXXXXXXXXXX" + test.getTestString(null));
- break;
- } catch (Exception e) {
- e.printStackTrace();
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e1) {
- e1.printStackTrace();
- }
- continue;
- } catch (Throwable e) {
- System.out.println("XXXXXXXXXXXXXXXXXXXXXXXX: teset case error");
- e.printStackTrace();
- System.exit(0);
+ Thread.sleep(1000);
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
}
+ continue;
+ } catch (Throwable e) {
+ System.out.println("XXXXXXXXXXXXXXXXXXXXXXXX: teset case error");
+ e.printStackTrace();
+ System.exit(0);
}
}
- }.start();
+ }).start();
}
}
diff --git a/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/TestFlowControl.java b/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/TestFlowControl.java
index faed30f..d2e06a7 100644
--- a/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/TestFlowControl.java
+++ b/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/TestFlowControl.java
@@ -55,26 +55,24 @@
AtomicBoolean failed = new AtomicBoolean(false);
CountDownLatch countDownLatch = new CountDownLatch(10);
for (int i = 0; i < 10; i++) {
- new Thread() {
- public void run() {
- for (int i = 0; i < 10; i++) {
- try {
- int result = function.apply(10);
- if (result != 10) {
- TestMgr.failed("", new Exception("not expected"));
- }
- } catch (InvocationException e) {
- TestMgr.check(e.getStatusCode(), 429);
- TestMgr.check(e.getMessage(),
- "InvocationException: code=429;msg=CommonExceptionData [message=" + role
- + " request rejected by qps flowcontrol]");
- failed.set(true);
- break;
+ new Thread(() -> {
+ for (int i1 = 0; i1 < 10; i1++) {
+ try {
+ int result = function.apply(10);
+ if (result != 10) {
+ TestMgr.failed("", new Exception("not expected"));
}
+ } catch (InvocationException e) {
+ TestMgr.check(e.getStatusCode(), 429);
+ TestMgr.check(e.getMessage(),
+ "InvocationException: code=429;msg=CommonExceptionData [message=" + role
+ + " request rejected by qps flowcontrol]");
+ failed.set(true);
+ break;
}
- countDownLatch.countDown();
}
- }.start();
+ countDownLatch.countDown();
+ }).start();
}
countDownLatch.await(10, TimeUnit.SECONDS);
TestMgr.check(expected, failed.get());
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestInvokeWhenServerNotReady.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestInvokeWhenServerNotReady.java
index 5be0e2f..faa6f98 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestInvokeWhenServerNotReady.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestInvokeWhenServerNotReady.java
@@ -41,50 +41,44 @@
}
private void startRestTemplateCall() {
- new Thread() {
- public void run() {
- for (int i = 0; i < 100; i++) {
- try {
- RestTemplate template = RestTemplateBuilder.create();
- template.getForObject("servicecomb://springmvc/upload/isServerStartUpSuccess", Boolean.class);
- } catch (Throwable e) {
- // ignore
- }
+ new Thread(() -> {
+ for (int i = 0; i < 100; i++) {
+ try {
+ RestTemplate template = RestTemplateBuilder.create();
+ template.getForObject("servicecomb://springmvc/upload/isServerStartUpSuccess", Boolean.class);
+ } catch (Throwable e) {
+ // ignore
}
}
- }.start();
+ }).start();
}
private void startRpcCall() {
- new Thread() {
- public void run() {
- for (int i = 0; i < 100; i++) {
- try {
- InvocationContext context = new InvocationContext();
- client.testInvocationTimeout(context, 1001, "customized");
- } catch (Throwable e) {
- // ignore
- }
+ new Thread(() -> {
+ for (int i = 0; i < 100; i++) {
+ try {
+ InvocationContext context = new InvocationContext();
+ client.testInvocationTimeout(context, 1001, "customized");
+ } catch (Throwable e) {
+ // ignore
}
}
- }.start();
+ }).start();
}
private void startInvokerUtilsCall() {
- new Thread() {
- public void run() {
- for (int i = 0; i < 100; i++) {
- try {
- Map<String, Object> args = new HashMap<>();
- args.put("timeout", 1);
- args.put("name", "customized");
- InvokerUtils
- .syncInvoke("springmvc", "SpringMVCCommonSchemaInterface", "testInvocationTimeout", args, String.class);
- } catch (Throwable e) {
- // ignore
- }
+ new Thread(() -> {
+ for (int i = 0; i < 100; i++) {
+ try {
+ Map<String, Object> args = new HashMap<>();
+ args.put("timeout", 1);
+ args.put("name", "customized");
+ InvokerUtils
+ .syncInvoke("springmvc", "SpringMVCCommonSchemaInterface", "testInvocationTimeout", args, String.class);
+ } catch (Throwable e) {
+ // ignore
}
}
- }.start();
+ }).start();
}
}
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/EarlyConsumer.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/EarlyConsumer.java
index 6e282df..09cd40e 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/EarlyConsumer.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/EarlyConsumer.java
@@ -36,23 +36,21 @@
private volatile boolean stopped = false;
public EarlyConsumer() {
- new Thread() {
- public void run() {
- while (!stopped) {
- LOGGER.info("calling service");
- try {
- healthSchema.heartbeat();
- } catch (Throwable e) {
- // ignore error
- }
- try {
- Thread.sleep(100);
- } catch (Throwable e) {
- // ignore error
- }
+ new Thread(() -> {
+ while (!stopped) {
+ LOGGER.info("calling service");
+ try {
+ healthSchema.heartbeat();
+ } catch (Throwable e) {
+ // ignore error
+ }
+ try {
+ Thread.sleep(100);
+ } catch (Throwable e) {
+ // ignore error
}
}
- }.start();
+ }).start();
}
@Override
diff --git a/foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/HashFieldMapEx.java b/foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/HashFieldMapEx.java
index 5e1f71e..d810233 100644
--- a/foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/HashFieldMapEx.java
+++ b/foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/HashFieldMapEx.java
@@ -60,7 +60,7 @@
List<FieldSchema<T>> fieldList = new ArrayList<>(fields.size());
fieldList.addAll(fields);
- Collections.sort(fieldList, Comparator.comparingInt(FieldSchema::getFieldNumber));
+ fieldList.sort(Comparator.comparingInt(FieldSchema::getFieldNumber));
this.fields = Collections.unmodifiableList(fieldList);
}
diff --git a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/cache/MicroserviceInstanceCache.java b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/cache/MicroserviceInstanceCache.java
index dd3cf44..07fcec6 100644
--- a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/cache/MicroserviceInstanceCache.java
+++ b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/cache/MicroserviceInstanceCache.java
@@ -17,7 +17,6 @@
package org.apache.servicecomb.registry.cache;
-import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@@ -67,16 +66,12 @@
public static MicroserviceInstance getOrCreate(String serviceId, String instanceId) {
try {
String key = String.format("%s@%s", serviceId, instanceId);
- return instances.get(key, new Callable<MicroserviceInstance>() {
-
- @Override
- public MicroserviceInstance call() {
- MicroserviceInstance instance = DiscoveryManager.INSTANCE.getMicroserviceInstance(serviceId, instanceId);
- if (instance == null) {
- throw new IllegalArgumentException("instance id not exists.");
- }
- return instance;
+ return instances.get(key, () -> {
+ MicroserviceInstance instance = DiscoveryManager.INSTANCE.getMicroserviceInstance(serviceId, instanceId);
+ if (instance == null) {
+ throw new IllegalArgumentException("instance id not exists.");
}
+ return instance;
});
} catch (ExecutionException | UncheckedExecutionException e) {
logger.error("get microservice instance from cache failed, {}, {}", String.format("%s@%s", serviceId, instanceId),
diff --git a/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/SSLManagerTest.java b/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/SSLManagerTest.java
index a11b70e..87eee1a 100644
--- a/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/SSLManagerTest.java
+++ b/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/SSLManagerTest.java
@@ -27,8 +27,6 @@
import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;
-import javax.net.ssl.HandshakeCompletedEvent;
-import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLServerSocket;
@@ -151,25 +149,19 @@
try {
clientsocket.connect(new InetSocketAddress("127.0.0.1", 8886));
- new Thread() {
- public void run() {
+ new Thread(() -> {
- try {
- SSLSocket s = (SSLSocket) serverSocket.accept();
- s.addHandshakeCompletedListener(new HandshakeCompletedListener() {
+ try {
+ SSLSocket s = (SSLSocket) serverSocket.accept();
+ s.addHandshakeCompletedListener(arg0 -> {
- @Override
- public void handshakeCompleted(HandshakeCompletedEvent arg0) {
-
- }
- });
- s.getOutputStream().write(new byte[] {0, 1});
- } catch (IOException e) {
- e.printStackTrace();
- Assertions.fail("this should not happen");
- }
+ });
+ s.getOutputStream().write(new byte[] {0, 1});
+ } catch (IOException e) {
+ e.printStackTrace();
+ Assertions.fail("this should not happen");
}
- }.start();
+ }).start();
clientsocket.startHandshake();
clientsocket.close();
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpParser.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpParser.java
index 244d67a..5a1f7b4 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpParser.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/server/TestTcpParser.java
@@ -33,13 +33,10 @@
@Test
public void test() throws UnsupportedEncodingException {
- TcpBufferHandler output = new TcpBufferHandler() {
- @Override
- public void handle(long _msgId, Buffer _headerBuffer, Buffer _bodyBuffer) {
- msgId = _msgId;
- headerBuffer = _headerBuffer;
- bodyBuffer = _bodyBuffer;
- }
+ TcpBufferHandler output = (_msgId, _headerBuffer, _bodyBuffer) -> {
+ msgId = _msgId;
+ headerBuffer = _headerBuffer;
+ bodyBuffer = _bodyBuffer;
};
byte[] header = new byte[] {1, 2, 3};
diff --git a/handlers/handler-bizkeeper/src/test/java/org/apache/servicecomb/bizkeeper/TestBizkeeperHandler.java b/handlers/handler-bizkeeper/src/test/java/org/apache/servicecomb/bizkeeper/TestBizkeeperHandler.java
index 8a8d403..dc4c307 100644
--- a/handlers/handler-bizkeeper/src/test/java/org/apache/servicecomb/bizkeeper/TestBizkeeperHandler.java
+++ b/handlers/handler-bizkeeper/src/test/java/org/apache/servicecomb/bizkeeper/TestBizkeeperHandler.java
@@ -26,7 +26,6 @@
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import com.netflix.hystrix.HystrixCommandProperties;
@@ -162,13 +161,10 @@
.thenThrow(new RuntimeException());
FallbackPolicyManager.addPolicy(policy);
System.setProperty("servicecomb.fallbackpolicy.groupname.testHandleInError.policy", "throwException");
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(InvocationOnMock invocation) {
- AsyncResponse asyncRsp = invocation.getArgument(0, AsyncResponse.class);
- asyncRsp.fail(InvocationType.CONSUMER, new Exception("testHandleInError"));
- return null;
- }
+ Mockito.doAnswer((Answer<Void>) invocation -> {
+ AsyncResponse asyncRsp = invocation.getArgument(0, AsyncResponse.class);
+ asyncRsp.fail(InvocationType.CONSUMER, new Exception("testHandleInError"));
+ return null;
}).when(invocation).next(Mockito.any(AsyncResponse.class));
bizkeeperHandler.handle(invocation, f -> {
Assertions.assertTrue(f.isFailed());
@@ -193,13 +189,10 @@
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName())
.thenReturn("testHandleSuccess");
- Mockito.doAnswer(new Answer<Void>() {
- @Override
- public Void answer(InvocationOnMock invocation) {
- AsyncResponse asyncRsp = invocation.getArgument(0, AsyncResponse.class);
- asyncRsp.success("");
- return null;
- }
+ Mockito.doAnswer((Answer<Void>) invocation -> {
+ AsyncResponse asyncRsp = invocation.getArgument(0, AsyncResponse.class);
+ asyncRsp.success("");
+ return null;
}).when(invocation).next(Mockito.any(AsyncResponse.class));
bizkeeperHandler.handle(invocation, f -> {
Assertions.assertTrue(f.isSucceed());
diff --git a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceCreator.java b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceCreator.java
index e9ee9bd..9098f5f 100644
--- a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceCreator.java
+++ b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceCreator.java
@@ -57,19 +57,15 @@
List<ServerListFilterExt> filters = new ArrayList<>();
- filters.add(new ServerListFilterExt() {
- @Override
- public List<ServiceCombServer> getFilteredListOfServers(List<ServiceCombServer> serverList,
- Invocation invocation) {
- List<ServiceCombServer> filteredServers = new ArrayList<>();
- for (ServiceCombServer server : servers) {
- if (server.getHost().equals("host1")) {
- continue;
- }
- filteredServers.add(server);
+ filters.add((serverList, invocation1) -> {
+ List<ServiceCombServer> filteredServers = new ArrayList<>();
+ for (ServiceCombServer server1 : servers) {
+ if (server1.getHost().equals("host1")) {
+ continue;
}
- return filteredServers;
+ filteredServers.add(server1);
}
+ return filteredServers;
});
lb.setFilters(filters);
@@ -109,19 +105,15 @@
servers.add(server2);
List<ServerListFilterExt> filters = new ArrayList<>();
- filters.add(new ServerListFilterExt() {
- @Override
- public List<ServiceCombServer> getFilteredListOfServers(List<ServiceCombServer> serverList,
- Invocation invocation) {
- List<ServiceCombServer> filteredServers = new ArrayList<>();
- for (ServiceCombServer server : servers) {
- if (server.getHost().equals("host1")) {
- continue;
- }
- filteredServers.add(server);
+ filters.add((serverList, invocation1) -> {
+ List<ServiceCombServer> filteredServers = new ArrayList<>();
+ for (ServiceCombServer server1 : servers) {
+ if (server1.getHost().equals("host1")) {
+ continue;
}
- return filteredServers;
+ filteredServers.add(server1);
}
+ return filteredServers;
});
lb.setFilters(filters);
new Expectations() {
@@ -165,19 +157,15 @@
servers.add(server);
servers.add(server2);
List<ServerListFilterExt> filters = new ArrayList<>();
- filters.add(new ServerListFilterExt() {
- @Override
- public List<ServiceCombServer> getFilteredListOfServers(List<ServiceCombServer> serverList,
- Invocation invocation) {
- List<ServiceCombServer> filteredServers = new ArrayList<>();
- for (ServiceCombServer server : servers) {
- if (server.getHost().equals("host1")) {
- continue;
- }
- filteredServers.add(server);
+ filters.add((serverList, invocation1) -> {
+ List<ServiceCombServer> filteredServers = new ArrayList<>();
+ for (ServiceCombServer server1 : servers) {
+ if (server1.getHost().equals("host1")) {
+ continue;
}
- return filteredServers;
+ filteredServers.add(server1);
}
+ return filteredServers;
});
lb.setFilters(filters);
new Expectations() {
diff --git a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/reference/RpcReferenceProcessor.java b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/reference/RpcReferenceProcessor.java
index 71be2c9..fb74820 100644
--- a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/reference/RpcReferenceProcessor.java
+++ b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/reference/RpcReferenceProcessor.java
@@ -33,11 +33,7 @@
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
// 扫描所有field,处理扩展的field标注
- ReflectionUtils.doWithFields(bean.getClass(), new ReflectionUtils.FieldCallback() {
- public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
- processConsumerField(bean, field);
- }
- });
+ ReflectionUtils.doWithFields(bean.getClass(), field -> processConsumerField(bean, field));
return bean;
}