本文整理匯總了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;
}