org.apache.hadoop.hbase.ipc.ServerRpcController Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.ipc;
import com.google.protobuf.RpcCallback;
import com.google.protobuf.RpcController;
import java.io.IOException;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.util.StringUtils;
/**
* Used for server-side protobuf RPC service invocations. This handler allows
* invocation exceptions to easily be passed through to the RPC server from coprocessor
* {@link com.google.protobuf.Service} implementations.
*
*
* When implementing {@link com.google.protobuf.Service} defined methods,
* coprocessor endpoints can use the following pattern to pass exceptions back to the RPC client:
*
* public void myMethod(RpcController controller, MyRequest request,
* RpcCallback<MyResponse> done) {
* MyResponse response = null;
* try {
* // do processing
* response = MyResponse.getDefaultInstance(); // or use a new builder to populate the response
* } catch (IOException ioe) {
* // pass exception back up
* ResponseConverter.setControllerException(controller, ioe);
* }
* done.run(response);
* }
*
*
*/
@InterfaceAudience.Private
public class ServerRpcController implements RpcController {
/**
* The exception thrown within
* {@link com.google.protobuf.Service#callMethod(com.google.protobuf.Descriptors.MethodDescriptor, RpcController,
* com.google.protobuf.Message, RpcCallback)}
* if any.
*/
// TODO: it would be good widen this to just Throwable, but IOException is what we allow now
private IOException serviceException;
private String errorMessage;
@Override
public void reset() {
serviceException = null;
errorMessage = null;
}
@Override
public boolean failed() {
return (failedOnException() || errorMessage != null);
}
@Override
public String errorText() {
return errorMessage;
}
@Override
public void startCancel() {
// not implemented
}
@Override
public void setFailed(String message) {
errorMessage = message;
}
@Override
public boolean isCanceled() {
return false;
}
@Override
public void notifyOnCancel(RpcCallback