本文整理匯總了Java中com.google.protobuf.Descriptors.MethodDescriptor類的典型用法代碼示例。如果您正苦於以下問題:Java MethodDescriptor類的具體用法?Java MethodDescriptor怎麽用?Java MethodDescriptor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MethodDescriptor類屬於com.google.protobuf.Descriptors包,在下文中一共展示了MethodDescriptor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Call
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="NP_NULL_ON_SOME_PATH",
justification="Can't figure why this complaint is happening... see below")
Call(int id, final BlockingService service, final MethodDescriptor md, RequestHeader header,
Message param, CellScanner cellScanner, Connection connection, Responder responder,
long size, TraceInfo tinfo, final InetAddress remoteAddress) {
this.id = id;
this.service = service;
this.md = md;
this.header = header;
this.param = param;
this.cellScanner = cellScanner;
this.connection = connection;
this.timestamp = System.currentTimeMillis();
this.response = null;
this.responder = responder;
this.isError = false;
this.size = size;
this.tinfo = tinfo;
this.user = connection == null? null: connection.user; // FindBugs: NP_NULL_ON_SOME_PATH
this.remoteAddress = remoteAddress;
this.retryImmediatelySupported =
connection == null? null: connection.retryImmediatelySupported;
}
示例2: testRpcScheduler
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
@Ignore
@Test
public void testRpcScheduler() throws IOException, InterruptedException {
PriorityFunction qosFunction = mock(PriorityFunction.class);
Abortable abortable = new AbortServer();
RpcScheduler scheduler = new SimpleRpcScheduler(CONF, 2, 0, 0, qosFunction, abortable, 0);
RpcServer rpcServer = new TestRpcServer(scheduler);
RpcClientImpl client = new RpcClientImpl(CONF, HConstants.CLUSTER_ID_DEFAULT);
try {
rpcServer.start();
MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
PayloadCarryingRpcController controller =
new PayloadCarryingRpcController(CellUtil.createCellScanner(ImmutableList.of(CELL)));
InetSocketAddress address = rpcServer.getListenerAddress();
if (address == null) {
throw new IOException("Listener channel is closed");
}
client.call(controller, md, param, md.getOutputType().toProto(), User.getCurrent(),
address, new MetricsConnection.CallStats());
} catch (Throwable e) {
assert(abortable.isAborted() == true);
} finally {
rpcServer.stop();
}
}
示例3: testNoCodec
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
/**
* Ensure we do not HAVE TO HAVE a codec.
* @throws InterruptedException
* @throws IOException
*/
@Test
public void testNoCodec() throws InterruptedException, IOException {
Configuration conf = HBaseConfiguration.create();
AbstractRpcClient client = createRpcClientNoCodec(conf);
TestRpcServer rpcServer = new TestRpcServer();
try {
rpcServer.start();
MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
final String message = "hello";
EchoRequestProto param = EchoRequestProto.newBuilder().setMessage(message).build();
InetSocketAddress address = rpcServer.getListenerAddress();
if (address == null) {
throw new IOException("Listener channel is closed");
}
Pair<Message, CellScanner> r =
client.call(null, md, param, md.getOutputType().toProto(), User.getCurrent(), address,
new MetricsConnection.CallStats());
assertTrue(r.getSecond() == null);
// Silly assertion that the message is in the returned pb.
assertTrue(r.getFirst().toString().contains(message));
} finally {
client.close();
rpcServer.stop();
}
}
示例4: testRTEDuringConnectionSetup
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
@Test
public void testRTEDuringConnectionSetup() throws Exception {
Configuration conf = HBaseConfiguration.create();
TestRpcServer rpcServer = new TestRpcServer();
AbstractRpcClient client = createRpcClientRTEDuringConnectionSetup(conf);
try {
rpcServer.start();
MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
InetSocketAddress address = rpcServer.getListenerAddress();
if (address == null) {
throw new IOException("Listener channel is closed");
}
client.call(null, md, param, null, User.getCurrent(), address,
new MetricsConnection.CallStats());
fail("Expected an exception to have been thrown!");
} catch (Exception e) {
LOG.info("Caught expected exception: " + e.toString());
assertTrue(StringUtils.stringifyException(e).contains("Injected fault"));
} finally {
client.close();
rpcServer.stop();
}
}
示例5: registerGpbMsgDesc
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
public void registerGpbMsgDesc(FileDescriptor fileDescriptor) {
if (fileDescriptor == null) return;
// service
for (ServiceDescriptor service : fileDescriptor.getServices()) {
for (MethodDescriptor method : service.getMethods()) {
if (gpbMsgDescMap.containsKey(method.getName())) {
LOG.error("[Gpb] the method [" + method.getName() + "] already registered.");
}
registerGpbMessage(method.getInputType());
methodInputTypeMap.put(method.getName(), method.getInputType().getName());
}
}
// message
for (Descriptor descriptor : fileDescriptor.getMessageTypes()) {
registerGpbMessage(descriptor);
}
}
示例6: testUnpack
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
@Test
public void testUnpack() throws InvalidProtocolBufferException {
for (Descriptors.ServiceDescriptor serviceDescriptor : FyChessSi.getDescriptor().getServices()) {
MethodDescriptor methodByName = serviceDescriptor.findMethodByName("onEnterRoom");
if (methodByName != null) {
GpbMessageDesc method = new GpbMessageDesc(methodByName);
//
VoEnterRoom message = VoEnterRoom.newBuilder()
.setRoomId(999)
.setSeat(8)
.build();
Message unpack = method.unpack(message.toByteString());
Message pack = method.pack(new Object[]{
999, 8, 10001L, "xx"
});
System.out.println();
}
}
}
示例7: forwardToService
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
private void forwardToService(SocketRpcProtos.Request rpcRequest,
RpcCallback<Message> callback, Service service,
RpcController socketController) throws RpcException {
// Get matching method
MethodDescriptor method = getMethod(rpcRequest,
service.getDescriptorForType());
// Create request for method
Message request = getRequestProto(rpcRequest,
service.getRequestPrototype(method));
// Call method
try {
service.callMethod(method, socketController, request, callback);
} catch (RuntimeException e) {
throw new RpcException(ErrorReason.RPC_ERROR,
"Error running method " + method.getFullName(), e);
}
}
示例8: callBlockingMethod
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
@Override
public Message callBlockingMethod(MethodDescriptor method,
RpcController controller, Message request, Message responsePrototype)
throws ServiceException {
// Must pass in a SocketRpcController
SocketRpcController socketController = (SocketRpcController) controller;
final Connection connection = createConnection(socketController);
try {
sendRpcRequest(method, socketController, request, connection);
Response rpcResponse = receiveRpcResponse(socketController, connection);
return handleRpcResponse(responsePrototype, rpcResponse,
socketController);
} finally {
close(connection);
}
}
示例9: sendRpcRequest
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
private void sendRpcRequest(MethodDescriptor method,
SocketRpcController socketController, Message request,
Connection connection) throws ServiceException {
// Check request
if (!request.isInitialized()) {
handleError(socketController, ErrorReason.INVALID_REQUEST_PROTO,
"Request is uninitialized", null);
}
// Create RPC request protobuf
SocketRpcProtos.Request rpcRequest = SocketRpcProtos.Request.newBuilder()
.setRequestProto(request.toByteString())
.setServiceName(method.getService().getFullName())
.setMethodName(method.getName())
.build();
// Send request
try {
connection.sendProtoMessage(rpcRequest);
} catch (IOException e) {
handleError(socketController, ErrorReason.IO_ERROR, String.format(
"Error writing over connection %s", connection), e);
}
}
示例10: Call
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
Call(int id, final BlockingService service, final MethodDescriptor md, RequestHeader header,
Message param, CellScanner cellScanner, Connection connection, Responder responder,
long size, TraceInfo tinfo) {
this.id = id;
this.service = service;
this.md = md;
this.header = header;
this.param = param;
this.cellScanner = cellScanner;
this.connection = connection;
this.timestamp = System.currentTimeMillis();
this.response = null;
this.delayResponse = false;
this.responder = responder;
this.isError = false;
this.size = size;
this.tinfo = tinfo;
}
示例11: testRpcScheduler
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
@Ignore
@Test
public void testRpcScheduler() throws IOException, InterruptedException {
PriorityFunction qosFunction = mock(PriorityFunction.class);
Abortable abortable = new AbortServer();
RpcScheduler scheduler = new SimpleRpcScheduler(CONF, 2, 0, 0, qosFunction, abortable, 0);
RpcServer rpcServer = new TestRpcServer(scheduler);
RpcClientImpl client = new RpcClientImpl(CONF, HConstants.CLUSTER_ID_DEFAULT);
try {
rpcServer.start();
MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
client.call(null, md, param, CellUtil.createCellScanner(ImmutableList.of(CELL)), md
.getOutputType().toProto(), User.getCurrent(), rpcServer.getListenerAddress(), 0);
} catch (Throwable e) {
assert(abortable.isAborted() == true);
} finally {
rpcServer.stop();
}
}
示例12: doSimpleTest
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
private void doSimpleTest(final Configuration conf, final RpcClientImpl client)
throws InterruptedException, IOException {
TestRpcServer rpcServer = new TestRpcServer();
List<Cell> cells = new ArrayList<Cell>();
int count = 3;
for (int i = 0; i < count; i++) cells.add(CELL);
try {
rpcServer.start();
InetSocketAddress address = rpcServer.getListenerAddress();
MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
Pair<Message, CellScanner> r = client.call(null, md, param, CellUtil.createCellScanner(cells),
md.getOutputType().toProto(), User.getCurrent(), address, 0);
int index = 0;
while (r.getSecond().advance()) {
assertTrue(CELL.equals(r.getSecond().current()));
index++;
}
assertEquals(count, index);
} finally {
client.close();
rpcServer.stop();
}
}
示例13: testRpcScheduler
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
/** Tests that the rpc scheduler is called when requests arrive. */
@Test
public void testRpcScheduler() throws IOException, InterruptedException {
RpcScheduler scheduler = spy(new FifoRpcScheduler(CONF, 1));
RpcServer rpcServer = new TestRpcServer(scheduler);
verify(scheduler).init((RpcScheduler.Context) anyObject());
RpcClientImpl client = new RpcClientImpl(CONF, HConstants.CLUSTER_ID_DEFAULT);
try {
rpcServer.start();
verify(scheduler).start();
MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
for (int i = 0; i < 10; i++) {
client.call(null, md, param, CellUtil.createCellScanner(ImmutableList.of(CELL)),
md.getOutputType().toProto(), User.getCurrent(), rpcServer.getListenerAddress(), 0);
}
verify(scheduler, times(10)).dispatch((CallRunner) anyObject());
} finally {
rpcServer.stop();
verify(scheduler).stop();
}
}
示例14: testNewReflectiveBlockingService
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
public void testNewReflectiveBlockingService() throws ServiceException {
ServiceWithNoOuter.BlockingInterface impl =
control.createMock(ServiceWithNoOuter.BlockingInterface.class);
RpcController controller = control.createMock(RpcController.class);
BlockingService service =
ServiceWithNoOuter.newReflectiveBlockingService(impl);
MethodDescriptor fooMethod =
ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
TestAllTypes expectedResponse = TestAllTypes.getDefaultInstance();
EasyMock.expect(impl.foo(EasyMock.same(controller), EasyMock.same(request)))
.andReturn(expectedResponse);
control.replay();
Message response =
service.callBlockingMethod(fooMethod, controller, request);
assertEquals(expectedResponse, response);
control.verify();
}
示例15: doSimpleTest
import com.google.protobuf.Descriptors.MethodDescriptor; //導入依賴的package包/類
private void doSimpleTest(final Configuration conf, final RpcClient client)
throws InterruptedException, IOException {
TestRpcServer rpcServer = new TestRpcServer();
List<Cell> cells = new ArrayList<Cell>();
int count = 3;
for (int i = 0; i < count; i++) cells.add(CELL);
try {
rpcServer.start();
InetSocketAddress address = rpcServer.getListenerAddress();
MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
Pair<Message, CellScanner> r = client.call(md, param, CellUtil.createCellScanner(cells),
md.getOutputType().toProto(), User.getCurrent(), address, 0);
int index = 0;
while (r.getSecond().advance()) {
assertTrue(CELL.equals(r.getSecond().current()));
index++;
}
assertEquals(count, index);
} finally {
client.stop();
rpcServer.stop();
}
}