本文整理汇总了Java中com.google.protobuf.RpcController.failed方法的典型用法代码示例。如果您正苦于以下问题:Java RpcController.failed方法的具体用法?Java RpcController.failed怎么用?Java RpcController.failed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.RpcController
的用法示例。
在下文中一共展示了RpcController.failed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import com.google.protobuf.RpcController; //导入方法依赖的package包/类
public void start(String etcdIp,int etcdPort){
//服务需要满足的tag
String serviceTags = "stage=beta;version=1.0";
//服务名
String serviceFullName = "sogou.nlu.rpc.example.EchoService";
//初始化一个Channel
NrpcChannel nrpcChannel = new NrpcChannel(serviceFullName,serviceTags,etcdIp,etcdPort);
RpcController controller = nrpcChannel.newController();
//获取服务Stub
Echo.EchoService.BlockingInterface service = Echo.EchoService.newBlockingStub(nrpcChannel);
//构造请求消息
Echo.EchoRequest.Builder requestBuilder = Echo.EchoRequest.newBuilder();
requestBuilder.setMessageBytes(ByteString.copyFromUtf8("你好"));
Echo.EchoRequest request = requestBuilder.build();
int count = 50;
while(count-->0){
try{
com.sogou.nlu.demo.Echo.EchoResponse response = service.echo(controller,request);
if(controller.failed()){
continue;
}
System.out.println(response.getMessage());
}catch(Exception ex){
ex.printStackTrace();
}
try {
Thread.sleep(1000);
}catch(Exception e) {
}
}
}
示例2: getControllerException
import com.google.protobuf.RpcController; //导入方法依赖的package包/类
/**
* Retreivies exception stored during RPC invocation.
* @param controller the controller instance provided by the client when calling the service
* @return exception if any, or null; Will return DoNotRetryIOException for string represented
* failure causes in controller.
*/
@Nullable
public static IOException getControllerException(RpcController controller) throws IOException {
if (controller != null && controller.failed()) {
if (controller instanceof ServerRpcController) {
return ((ServerRpcController)controller).getFailedOn();
} else {
return new DoNotRetryIOException(controller.errorText());
}
}
return null;
}