use of org.apache.ratis.netty.NettyRpcProxy in project incubator-ratis by apache.
the class NettyClientRpc method sendRequest.
@Override
public RaftClientReply sendRequest(RaftClientRequest request) throws IOException {
final RaftPeerId serverId = request.getServerId();
final NettyRpcProxy proxy = getProxies().getProxy(serverId);
final RaftNettyServerRequestProto.Builder b = RaftNettyServerRequestProto.newBuilder();
final RaftRpcRequestProto rpcRequest;
if (request instanceof GroupManagementRequest) {
final GroupManagementRequestProto proto = ClientProtoUtils.toGroupManagementRequestProto((GroupManagementRequest) request);
b.setGroupManagementRequest(proto);
rpcRequest = proto.getRpcRequest();
} else if (request instanceof SetConfigurationRequest) {
final SetConfigurationRequestProto proto = ClientProtoUtils.toSetConfigurationRequestProto((SetConfigurationRequest) request);
b.setSetConfigurationRequest(proto);
rpcRequest = proto.getRpcRequest();
} else if (request instanceof GroupListRequest) {
final RaftProtos.GroupListRequestProto proto = ClientProtoUtils.toGroupListRequestProto((GroupListRequest) request);
b.setGroupListRequest(proto);
rpcRequest = proto.getRpcRequest();
} else if (request instanceof GroupInfoRequest) {
final RaftProtos.GroupInfoRequestProto proto = ClientProtoUtils.toGroupInfoRequestProto((GroupInfoRequest) request);
b.setGroupInfoRequest(proto);
rpcRequest = proto.getRpcRequest();
} else if (request instanceof TransferLeadershipRequest) {
final RaftProtos.TransferLeadershipRequestProto proto = ClientProtoUtils.toTransferLeadershipRequestProto((TransferLeadershipRequest) request);
b.setTransferLeadershipRequest(proto);
rpcRequest = proto.getRpcRequest();
} else if (request instanceof SnapshotManagementRequest) {
final RaftProtos.SnapshotManagementRequestProto proto = ClientProtoUtils.toSnapshotManagementRequestProto((SnapshotManagementRequest) request);
b.setSnapshotManagementRequest(proto);
rpcRequest = proto.getRpcRequest();
} else if (request instanceof LeaderElectionManagementRequest) {
final RaftProtos.LeaderElectionManagementRequestProto proto = ClientProtoUtils.toLeaderElectionManagementRequestProto((LeaderElectionManagementRequest) request);
b.setLeaderElectionManagementRequest(proto);
rpcRequest = proto.getRpcRequest();
} else {
final RaftClientRequestProto proto = ClientProtoUtils.toRaftClientRequestProto(request);
b.setRaftClientRequest(proto);
rpcRequest = proto.getRpcRequest();
}
if (request instanceof GroupListRequest) {
return ClientProtoUtils.toGroupListReply(proxy.send(rpcRequest, b.build()).getGroupListReply());
} else if (request instanceof GroupInfoRequest) {
return ClientProtoUtils.toGroupInfoReply(proxy.send(rpcRequest, b.build()).getGroupInfoReply());
} else {
return ClientProtoUtils.toRaftClientReply(proxy.send(rpcRequest, b.build()).getRaftClientReply());
}
}
use of org.apache.ratis.netty.NettyRpcProxy in project incubator-ratis by apache.
the class NettyRpcService method sendRaftNettyServerRequestProto.
private RaftNettyServerReplyProto sendRaftNettyServerRequestProto(RaftRpcRequestProto request, RaftNettyServerRequestProto proto) throws IOException {
final RaftPeerId id = RaftPeerId.valueOf(request.getReplyId());
final NettyRpcProxy p = getProxies().getProxy(id);
try {
return p.send(request, proto);
} catch (ClosedChannelException cce) {
getProxies().resetProxy(id);
throw cce;
}
}
Aggregations