Skip to content

Commit

Permalink
(fix) peer context should not be shared between connections, see sofa…
Browse files Browse the repository at this point in the history
…stack#461 (sofastack#528)

* (fix) peer context should not be shared between connections, see sofastack#461

* (feat) minor change
  • Loading branch information
killme2008 authored Nov 3, 2020
1 parent dfaa19a commit b395fe3
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 161 deletions.
12 changes: 12 additions & 0 deletions jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.alipay.sofa.jraft.rpc;

/**
*
* RPC connection
* @author jiachun.fjc
*/
public interface Connection {
Expand All @@ -37,6 +39,16 @@ public interface Connection {
*/
void setAttribute(final String key, final Object value);

/**
* Set the attribute to the connection if the key's item doesn't exist, otherwise returns the present item.
*
* @param key the attribute key
* @param value the attribute value
* @return the previous value associated with the specified key, or
* <tt>null</tt> if there was no mapping for the key.
*/
Object setAttributeIfAbsent(final String key, final Object value);

/**
* Close the connection.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class BoltRpcServer implements RpcServer {

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

public BoltRpcServer(com.alipay.remoting.rpc.RpcServer rpcServer) {
public BoltRpcServer(final com.alipay.remoting.rpc.RpcServer rpcServer) {
this.rpcServer = Requires.requireNonNull(rpcServer, "rpcServer");
}

Expand Down Expand Up @@ -66,6 +66,11 @@ public Object getAttribute(final String key) {
return conn.getAttribute(key);
}

@Override
public Object setAttributeIfAbsent(final String key, final Object value) {
return conn.setAttributeIfAbsent(key, value);
}

@Override
public void setAttribute(final String key, final Object value) {
conn.setAttribute(key, value);
Expand Down Expand Up @@ -140,14 +145,14 @@ public Executor getExecutor() {
}

public com.alipay.remoting.rpc.RpcServer getServer() {
return rpcServer;
return this.rpcServer;
}

private static class BoltConnection implements Connection {

private final com.alipay.remoting.Connection conn;

private BoltConnection(com.alipay.remoting.Connection conn) {
private BoltConnection(final com.alipay.remoting.Connection conn) {
this.conn = Requires.requireNonNull(conn, "conn");
}

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

@Override
public Object setAttributeIfAbsent(final String key, final Object value) {
return this.conn.setAttributeIfAbsent(key, value);
}

@Override
public void setAttribute(final String key, final Object value) {
this.conn.setAttribute(key, value);
Expand Down
Loading

0 comments on commit b395fe3

Please sign in to comment.