Skip to content

Commit

Permalink
Replace anonymous class with method reference (#2929)
Browse files Browse the repository at this point in the history
* Replace anonymous class with method reference

* Revert changes as per @beiwei30 code review
  • Loading branch information
igor-suhorukov authored and beiwei30 committed Dec 11, 2018
1 parent 0599f7d commit ce4defa
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,7 @@ public void encode(Object obj, JSONWriter jb) throws IOException {
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ public void testListener() throws InterruptedException {

}, executor);
final CountDownLatch countDownLatch = new CountDownLatch(1);
completableFuture.thenRunAsync(new Runnable() {
@Override
public void run() {
countDownLatch.countDown();
}
});
completableFuture.thenRunAsync(countDownLatch::countDown);
countDownLatch.await();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ public void testAddRunnableToExecutor() {
@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ protected Integer initialValue() throws Exception {
};

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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,7 @@ public synchronized void export() {
}

if (delay != null && delay > 0) {
delayExportExecutor.schedule(new Runnable() {
@Override
public void run() {
doExport();
}
}, delay, TimeUnit.MILLISECONDS);
delayExportExecutor.schedule(this::doExport, delay, TimeUnit.MILLISECONDS);
} else {
doExport();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,7 @@ public List<URL> lookup(URL url) {
}
} else {
final AtomicReference<List<URL>> reference = new AtomicReference<List<URL>>();
NotifyListener listener = new NotifyListener() {
@Override
public void notify(List<URL> urls) {
reference.set(urls);
}
};
NotifyListener listener = reference::set;
subscribe(url, listener); // Subscribe logic guarantees the first notify to return
List<URL> urls = reference.get();
if (urls != null && !urls.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,7 @@ public void doClose() {

@Override
public IZkChildListener createTargetChildListener(String path, final ChildListener listener) {
return new IZkChildListener() {
@Override
public void handleChildChange(String parentPath, List<String> currentChilds)
throws Exception {
listener.childChanged(parentPath, currentChilds);
}
};
return listener::childChanged;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.protocol.AbstractProxyProtocol;

import org.aopalliance.intercept.MethodInvocation;
import org.springframework.remoting.RemoteAccessException;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
import org.springframework.remoting.rmi.RmiServiceExporter;
import org.springframework.remoting.support.RemoteInvocation;
import org.springframework.remoting.support.RemoteInvocationFactory;

import java.io.IOException;
import java.net.SocketTimeoutException;
Expand Down Expand Up @@ -80,12 +77,7 @@ protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcExc
// RMI needs extra parameter since it uses customized remote invocation object
if (url.getParameter(Constants.DUBBO_VERSION_KEY, Version.getProtocolVersion()).equals(Version.getProtocolVersion())) {
// Check dubbo version on provider, this feature only support
rmiProxyFactoryBean.setRemoteInvocationFactory(new RemoteInvocationFactory() {
@Override
public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
return new RmiRemoteInvocation(methodInvocation);
}
});
rmiProxyFactoryBean.setRemoteInvocationFactory(RmiRemoteInvocation::new);
}
rmiProxyFactoryBean.setServiceUrl(url.toIdentityString());
rmiProxyFactoryBean.setServiceInterface(serviceType);
Expand Down

0 comments on commit ce4defa

Please sign in to comment.