Skip to content

Commit b395fe3

Browse files
authored
(fix) peer context should not be shared between connections, see #461 (#528)
* (fix) peer context should not be shared between connections, see #461 * (feat) minor change
1 parent dfaa19a commit b395fe3

File tree

6 files changed

+361
-161
lines changed

6 files changed

+361
-161
lines changed

jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/Connection.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.alipay.sofa.jraft.rpc;
1818

1919
/**
20+
*
21+
* RPC connection
2022
* @author jiachun.fjc
2123
*/
2224
public interface Connection {
@@ -37,6 +39,16 @@ public interface Connection {
3739
*/
3840
void setAttribute(final String key, final Object value);
3941

42+
/**
43+
* Set the attribute to the connection if the key's item doesn't exist, otherwise returns the present item.
44+
*
45+
* @param key the attribute key
46+
* @param value the attribute value
47+
* @return the previous value associated with the specified key, or
48+
* <tt>null</tt> if there was no mapping for the key.
49+
*/
50+
Object setAttributeIfAbsent(final String key, final Object value);
51+
4052
/**
4153
* Close the connection.
4254
*/

jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/impl/BoltRpcServer.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class BoltRpcServer implements RpcServer {
3838

3939
private final com.alipay.remoting.rpc.RpcServer rpcServer;
4040

41-
public BoltRpcServer(com.alipay.remoting.rpc.RpcServer rpcServer) {
41+
public BoltRpcServer(final com.alipay.remoting.rpc.RpcServer rpcServer) {
4242
this.rpcServer = Requires.requireNonNull(rpcServer, "rpcServer");
4343
}
4444

@@ -66,6 +66,11 @@ public Object getAttribute(final String key) {
6666
return conn.getAttribute(key);
6767
}
6868

69+
@Override
70+
public Object setAttributeIfAbsent(final String key, final Object value) {
71+
return conn.setAttributeIfAbsent(key, value);
72+
}
73+
6974
@Override
7075
public void setAttribute(final String key, final Object value) {
7176
conn.setAttribute(key, value);
@@ -140,14 +145,14 @@ public Executor getExecutor() {
140145
}
141146

142147
public com.alipay.remoting.rpc.RpcServer getServer() {
143-
return rpcServer;
148+
return this.rpcServer;
144149
}
145150

146151
private static class BoltConnection implements Connection {
147152

148153
private final com.alipay.remoting.Connection conn;
149154

150-
private BoltConnection(com.alipay.remoting.Connection conn) {
155+
private BoltConnection(final com.alipay.remoting.Connection conn) {
151156
this.conn = Requires.requireNonNull(conn, "conn");
152157
}
153158

@@ -156,6 +161,11 @@ public Object getAttribute(final String key) {
156161
return this.conn.getAttribute(key);
157162
}
158163

164+
@Override
165+
public Object setAttributeIfAbsent(final String key, final Object value) {
166+
return this.conn.setAttributeIfAbsent(key, value);
167+
}
168+
159169
@Override
160170
public void setAttribute(final String key, final Object value) {
161171
this.conn.setAttribute(key, value);

0 commit comments

Comments
 (0)