Replace anonymous class with method reference (#2929)
authorIgor Suhorukov <igor.suhorukov@gmail.com>
Tue, 11 Dec 2018 09:12:18 +0000 (12:12 +0300)
committerIan Luo <ian.luo@gmail.com>
Tue, 11 Dec 2018 09:12:18 +0000 (17:12 +0800)
* Replace anonymous class with method reference

* Revert changes as per @beiwei30 code review

dubbo-common/src/main/java/org/apache/dubbo/common/json/GenericJSONConverter.java
dubbo-common/src/test/java/org/apache/dubbo/common/concurrent/CompletableFutureTaskTest.java
dubbo-common/src/test/java/org/apache/dubbo/common/concurrent/ExecutionListTest.java
dubbo-common/src/test/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalTest.java
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperClient.java
dubbo-rpc/dubbo-rpc-rmi/src/main/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocol.java

index 166c192..74cf09a 100644 (file)
@@ -130,12 +130,7 @@ public class GenericJSONConverter implements JSONConverter {
         GlobalEncoderMap.put(Date.class, e);
 
         // init decoder map.
-        Decoder d = new Decoder() {
-            @Override
-            public Object decode(Object jv) {
-                return jv.toString();
-            }
-        };
+        Decoder d = Object::toString;
         GlobalDecoderMap.put(String.class, d);
 
         d = new Decoder() {
index 27d7da6..4513721 100644 (file)
@@ -78,12 +78,7 @@ public class CompletableFutureTaskTest {
 
         }, executor);
         final CountDownLatch countDownLatch = new CountDownLatch(1);
-        completableFuture.thenRunAsync(new Runnable() {
-            @Override
-            public void run() {
-                countDownLatch.countDown();
-            }
-        });
+        completableFuture.thenRunAsync(countDownLatch::countDown);
         countDownLatch.await();
     }
 
index bd1900e..417b4a4 100644 (file)
@@ -54,12 +54,7 @@ public class ExecutionListTest {
     @Test
     public void testExecuteRunnableWithDefaultExecutor() throws InterruptedException {
         final CountDownLatch countDownLatch = new CountDownLatch(1);
-        this.executionList.add(new Runnable() {
-            @Override
-            public void run() {
-                countDownLatch.countDown();
-            }
-        }, null);
+        this.executionList.add(countDownLatch::countDown, null);
 
         this.executionList.execute();
         countDownLatch.await();
index 631d121..caeda65 100644 (file)
@@ -49,12 +49,7 @@ public class InternalThreadLocalTest {
         };
 
         for (int i = 0; i < THREADS; i++) {
-            Thread t = new Thread(new Runnable() {
-                @Override
-                public void run() {
-                    internalThreadLocal.get();
-                }
-            });
+            Thread t = new Thread(internalThreadLocal::get);
             t.start();
         }
 
index 579acd0..07d7d78 100644 (file)
@@ -206,12 +206,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
         }\r
 \r
         if (delay != null && delay > 0) {\r
-            delayExportExecutor.schedule(new Runnable() {\r
-                @Override\r
-                public void run() {\r
-                    doExport();\r
-                }\r
-            }, delay, TimeUnit.MILLISECONDS);\r
+            delayExportExecutor.schedule(this::doExport, delay, TimeUnit.MILLISECONDS);\r
         } else {\r
             doExport();\r
         }\r
index 61360f0..fc2f86d 100644 (file)
@@ -245,12 +245,7 @@ public abstract class AbstractRegistry implements Registry {
             }\r
         } else {\r
             final AtomicReference<List<URL>> reference = new AtomicReference<List<URL>>();\r
-            NotifyListener listener = new NotifyListener() {\r
-                @Override\r
-                public void notify(List<URL> urls) {\r
-                    reference.set(urls);\r
-                }\r
-            };\r
+            NotifyListener listener = reference::set;\r
             subscribe(url, listener); // Subscribe logic guarantees the first notify to return\r
             List<URL> urls = reference.get();\r
             if (urls != null && !urls.isEmpty()) {\r
index 4f7faeb..784377a 100644 (file)
@@ -114,13 +114,7 @@ public class ZkclientZookeeperClient extends AbstractZookeeperClient<IZkChildLis
 \r
     @Override\r
     public IZkChildListener createTargetChildListener(String path, final ChildListener listener) {\r
-        return new IZkChildListener() {\r
-            @Override\r
-            public void handleChildChange(String parentPath, List<String> currentChilds)\r
-                    throws Exception {\r
-                listener.childChanged(parentPath, currentChilds);\r
-            }\r
-        };\r
+        return listener::childChanged;\r
     }\r
 \r
     @Override\r
index a9c78c7..8a28cc0 100644 (file)
@@ -22,12 +22,9 @@ import org.apache.dubbo.common.Version;
 import org.apache.dubbo.rpc.RpcException;\r
 import org.apache.dubbo.rpc.protocol.AbstractProxyProtocol;\r
 \r
-import org.aopalliance.intercept.MethodInvocation;\r
 import org.springframework.remoting.RemoteAccessException;\r
 import org.springframework.remoting.rmi.RmiProxyFactoryBean;\r
 import org.springframework.remoting.rmi.RmiServiceExporter;\r
-import org.springframework.remoting.support.RemoteInvocation;\r
-import org.springframework.remoting.support.RemoteInvocationFactory;\r
 \r
 import java.io.IOException;\r
 import java.net.SocketTimeoutException;\r
@@ -80,12 +77,7 @@ public class RmiProtocol extends AbstractProxyProtocol {
         // RMI needs extra parameter since it uses customized remote invocation object\r
         if (url.getParameter(Constants.DUBBO_VERSION_KEY, Version.getProtocolVersion()).equals(Version.getProtocolVersion())) {\r
             // Check dubbo version on provider, this feature only support\r
-            rmiProxyFactoryBean.setRemoteInvocationFactory(new RemoteInvocationFactory() {\r
-                @Override\r
-                public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {\r
-                    return new RmiRemoteInvocation(methodInvocation);\r
-                }\r
-            });\r
+            rmiProxyFactoryBean.setRemoteInvocationFactory(RmiRemoteInvocation::new);\r
         }\r
         rmiProxyFactoryBean.setServiceUrl(url.toIdentityString());\r
         rmiProxyFactoryBean.setServiceInterface(serviceType);\r