This is an automated email from the ASF dual-hosted git repository.
szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 565d11149 RATIS-1848. Simplify PeerMap inheritance (#885)
565d11149 is described below
commit 565d111496382bef810dea8c4547410ebbd57bdc
Author: tison <[email protected]>
AuthorDate: Thu Jun 15 13:21:17 2023 +0800
RATIS-1848. Simplify PeerMap inheritance (#885)
---
.../java/org/apache/ratis/util/PeerProxyMap.java | 11 +---------
.../java/org/apache/ratis/netty/NettyRpcProxy.java | 25 +++++++++++-----------
2 files changed, 13 insertions(+), 23 deletions(-)
diff --git a/ratis-common/src/main/java/org/apache/ratis/util/PeerProxyMap.java
b/ratis-common/src/main/java/org/apache/ratis/util/PeerProxyMap.java
index 7655a3ff3..c5a08f56a 100644
--- a/ratis-common/src/main/java/org/apache/ratis/util/PeerProxyMap.java
+++ b/ratis-common/src/main/java/org/apache/ratis/util/PeerProxyMap.java
@@ -94,11 +94,6 @@ public class PeerProxyMap<PROXY extends Closeable>
implements RaftPeer.Add, Clos
this.createProxy = createProxy;
}
- public PeerProxyMap(String name) {
- this.name = name;
- this.createProxy = this::createProxyImpl;
- }
-
public String getName() {
return name;
}
@@ -150,7 +145,7 @@ public class PeerProxyMap<PROXY extends Closeable>
implements RaftPeer.Add, Clos
optional.ifPresent(proxy -> closeProxy(proxy, pp));
}
- /** @return true if the given throwable is handled; otherwise, the call is
an no-op, return false. */
+ /** @return true if the given throwable is handled; otherwise, the call is a
no-op, return false. */
public boolean handleException(RaftPeerId serverId, Throwable e, boolean
reconnect) {
if (reconnect || IOUtils.shouldReconnect(e)) {
resetProxy(serverId);
@@ -159,10 +154,6 @@ public class PeerProxyMap<PROXY extends Closeable>
implements RaftPeer.Add, Clos
return false;
}
- public PROXY createProxyImpl(RaftPeer peer) throws IOException {
- throw new UnsupportedOperationException();
- }
-
@Override
public void close() {
ConcurrentUtils.parallelForEachAsync(peers.values(),
diff --git
a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyRpcProxy.java
b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyRpcProxy.java
index b2b8763fb..74f92ce3f 100644
--- a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyRpcProxy.java
+++ b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyRpcProxy.java
@@ -49,23 +49,22 @@ import static
org.apache.ratis.proto.netty.NettyProtos.RaftNettyServerReplyProto
public class NettyRpcProxy implements Closeable {
public static class PeerMap extends PeerProxyMap<NettyRpcProxy> {
- private final EventLoopGroup group = new NioEventLoopGroup();
- private final RaftProperties properties;
+ private final EventLoopGroup group;
public PeerMap(String name, RaftProperties properties) {
- super(name);
- this.properties = properties;
+ this(name, properties, new NioEventLoopGroup());
}
- @Override
- public NettyRpcProxy createProxyImpl(RaftPeer peer)
- throws IOException {
- try {
- return new NettyRpcProxy(peer, properties, group);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw IOUtils.toInterruptedIOException("Failed connecting to " + peer,
e);
- }
+ private PeerMap(String name, RaftProperties properties, EventLoopGroup
group) {
+ super(name, peer -> {
+ try {
+ return new NettyRpcProxy(peer, properties, group);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw IOUtils.toInterruptedIOException("Failed connecting to " +
peer, e);
+ }
+ });
+ this.group = group;
}
@Override