Skip to content

Commit

Permalink
remove rpc address parser for 'invalid checkConnection' (sofastack#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun authored May 6, 2020
1 parent 0489220 commit 090b5d4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.alipay.sofa.jraft.rpc.RaftRpcFactory;
import com.alipay.sofa.jraft.rpc.RpcClient;
import com.alipay.sofa.jraft.rpc.RpcServer;
import com.alipay.sofa.jraft.rpc.impl.core.JRaftRpcAddressParser;
import com.alipay.sofa.jraft.util.Endpoint;
import com.alipay.sofa.jraft.util.Requires;
import com.alipay.sofa.jraft.util.SPI;
Expand Down Expand Up @@ -69,7 +68,6 @@ public ConfigHelper<RpcClient> defaultJRaftClientConfigHelper(final RpcOptions o
final InvokeContext ctx = new InvokeContext();
ctx.put(InvokeContext.BOLT_CRC_SWITCH, opts.isEnableRpcChecksum());
client.setDefaultInvokeCtx(ctx);
client.setDefaultAddressParser(new JRaftRpcAddressParser());
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

import com.alipay.remoting.ConnectionEventType;
import com.alipay.remoting.RejectedExecutionPolicy;
import com.alipay.remoting.Url;
import com.alipay.remoting.config.switches.GlobalSwitch;
import com.alipay.remoting.rpc.RpcAddressParser;
import com.alipay.sofa.jraft.ReplicatorGroup;
import com.alipay.sofa.jraft.error.InvokeTimeoutException;
import com.alipay.sofa.jraft.error.RemotingException;
Expand All @@ -43,7 +41,6 @@
*/
public class BoltRpcClient implements RpcClient {

public static final String BOLT_ADDRESS_PARSER = "BOLT_ADDRESS_PARSER";
public static final String BOLT_CTX = "BOLT_CTX";
public static final String BOLT_REJECTED_EXECUTION_POLICY = "BOLT_REJECTED_EXECUTION_POLICY";

Expand All @@ -58,7 +55,6 @@ public class BoltRpcClient implements RpcClient {

private final com.alipay.remoting.rpc.RpcClient rpcClient;
private com.alipay.remoting.InvokeContext defaultInvokeCtx;
private RpcAddressParser defaultAddressParser = new RpcAddressParser();

public BoltRpcClient(com.alipay.remoting.rpc.RpcClient rpcClient) {
this.rpcClient = Requires.requireNonNull(rpcClient, "rpcClient");
Expand Down Expand Up @@ -99,10 +95,8 @@ public void registerConnectEventListener(final ReplicatorGroup replicatorGroup)
public Object invokeSync(final Endpoint endpoint, final Object request, final InvokeContext ctx,
final long timeoutMs) throws InterruptedException, RemotingException {
Requires.requireNonNull(endpoint, "endpoint");
final RpcAddressParser addressParser = getAddressParser(ctx);
try {
final Url url = addressParser.parse(endpoint.toString());
return this.rpcClient.invokeSync(url, request, getBoltInvokeCtx(ctx), (int) timeoutMs);
return this.rpcClient.invokeSync(endpoint.toString(), request, getBoltInvokeCtx(ctx), (int) timeoutMs);
} catch (final com.alipay.remoting.rpc.exception.InvokeTimeoutException e) {
throw new InvokeTimeoutException(e);
} catch (final com.alipay.remoting.exception.RemotingException e) {
Expand All @@ -115,11 +109,9 @@ public void invokeAsync(final Endpoint endpoint, final Object request, final Inv
final InvokeCallback callback, final long timeoutMs) throws InterruptedException,
RemotingException {
Requires.requireNonNull(endpoint, "endpoint");
final RpcAddressParser addressParser = getAddressParser(ctx);
try {
final Url url = addressParser.parse(endpoint.toString());
this.rpcClient.invokeWithCallback(url, request, getBoltInvokeCtx(ctx), getBoltCallback(callback, ctx),
(int) timeoutMs);
this.rpcClient.invokeWithCallback(endpoint.toString(), request, getBoltInvokeCtx(ctx),
getBoltCallback(callback, ctx), (int) timeoutMs);
} catch (final com.alipay.remoting.rpc.exception.InvokeTimeoutException e) {
throw new InvokeTimeoutException(e);
} catch (final com.alipay.remoting.exception.RemotingException e) {
Expand All @@ -139,19 +131,6 @@ public void setDefaultInvokeCtx(com.alipay.remoting.InvokeContext defaultInvokeC
this.defaultInvokeCtx = defaultInvokeCtx;
}

public RpcAddressParser getDefaultAddressParser() {
return defaultAddressParser;
}

public void setDefaultAddressParser(RpcAddressParser defaultAddressParser) {
this.defaultAddressParser = defaultAddressParser;
}

private RpcAddressParser getAddressParser(final InvokeContext ctx) {
return ctx == null ? this.defaultAddressParser : ctx.getOrDefault(BOLT_ADDRESS_PARSER,
this.defaultAddressParser);
}

private RejectedExecutionPolicy getRejectedPolicy(final InvokeContext ctx) {
return ctx == null ? RejectedExecutionPolicy.CALLER_HANDLE_EXCEPTION : ctx.getOrDefault(
BOLT_REJECTED_EXECUTION_POLICY, RejectedExecutionPolicy.CALLER_HANDLE_EXCEPTION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public ClientServiceConnectionEventProcessor(ReplicatorGroup rgGroup) {
}

@Override
public void onEvent(String remoteAddr, Connection conn) {
PeerId peer = new PeerId();
public void onEvent(final String remoteAddr, final Connection conn) {
final PeerId peer = new PeerId();
if (peer.parse(remoteAddr)) {
LOG.info("Peer {} is connected", peer);
rgGroup.checkReplicator(peer, true);
this.rgGroup.checkReplicator(peer, true);
} else {
LOG.error("Fail to parse peer: {}", remoteAddr);
}
Expand Down

This file was deleted.

0 comments on commit 090b5d4

Please sign in to comment.