本文整理汇总了Java中com.google.protobuf.RpcChannel类的典型用法代码示例。如果您正苦于以下问题:Java RpcChannel类的具体用法?Java RpcChannel怎么用?Java RpcChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RpcChannel类属于com.google.protobuf包,在下文中一共展示了RpcChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: coprocessorService
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
private <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
ServiceCaller<S, R> callable, RegionInfo region, byte[] row) {
RegionCoprocessorRpcChannelImpl channel = new RegionCoprocessorRpcChannelImpl(conn, tableName,
region, row, rpcTimeoutNs, operationTimeoutNs);
S stub = stubMaker.apply(channel);
CompletableFuture<R> future = new CompletableFuture<>();
ClientCoprocessorRpcController controller = new ClientCoprocessorRpcController();
callable.call(stub, controller, resp -> {
if (controller.failed()) {
future.completeExceptionally(controller.getFailed());
} else {
future.complete(resp);
}
});
return future;
}
示例2: coprocessorService
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
@Override
public <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
ServiceCaller<S, R> callable) {
MasterCoprocessorRpcChannelImpl channel =
new MasterCoprocessorRpcChannelImpl(this.<Message> newMasterCaller());
S stub = stubMaker.apply(channel);
CompletableFuture<R> future = new CompletableFuture<>();
ClientCoprocessorRpcController controller = new ClientCoprocessorRpcController();
callable.call(stub, controller, resp -> {
if (controller.failed()) {
future.completeExceptionally(controller.getFailed());
} else {
future.complete(resp);
}
});
return future;
}
示例3: testAsyncConnectionSetup
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
@Test
public void testAsyncConnectionSetup() throws Exception {
TestRpcServer rpcServer = new TestRpcServer();
AsyncRpcClient client = createRpcClient(CONF);
try {
rpcServer.start();
InetSocketAddress address = rpcServer.getListenerAddress();
if (address == null) {
throw new IOException("Listener channel is closed");
}
MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
RpcChannel channel =
client.createRpcChannel(ServerName.valueOf(address.getHostName(), address.getPort(),
System.currentTimeMillis()), User.getCurrent(), 0);
final AtomicBoolean done = new AtomicBoolean(false);
channel.callMethod(md, new PayloadCarryingRpcController(), param, md.getOutputType()
.toProto(), new RpcCallback<Message>() {
@Override
public void run(Message parameter) {
done.set(true);
}
});
TEST_UTIL.waitFor(1000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return done.get();
}
});
} finally {
client.close();
rpcServer.stop();
}
}
示例4: doTest
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
private void doTest(RpcServer rpcServer) throws InterruptedException,
ServiceException, IOException {
BlockingRpcChannel blockingChannel = RpcChannels
.newBlockingRpcChannel(clientConnectionFactory);
RpcChannel channel = RpcChannels.newRpcChannel(clientConnectionFactory,
threadPool);
BlockingInterface blockingStub = TestService
.newBlockingStub(blockingChannel);
TestService stub = TestService.newStub(channel);
try {
rpcServer.startServer();
Thread.sleep(500);
doRpc(stub);
doBlockingRpc(blockingStub);
doBlockingRpc(blockingStub);
doRpc(stub);
} finally {
Thread.sleep(500);
System.out.println("Closing Client");
if (clientConnectionFactory instanceof Closeable) {
((PersistentRpcConnectionFactory) clientConnectionFactory).close();
}
Thread.sleep(100);
System.out.println("Closing Server");
rpcServer.shutDown();
}
}
示例5: onLocateComplete
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
private <S, R> void onLocateComplete(Function<RpcChannel, S> stubMaker,
ServiceCaller<S, R> callable, CoprocessorCallback<R> callback,
List<HRegionLocation> locs, byte[] endKey, boolean endKeyInclusive,
AtomicBoolean locateFinished, AtomicInteger unfinishedRequest, HRegionLocation loc,
Throwable error) {
if (error != null) {
callback.onError(error);
return;
}
unfinishedRequest.incrementAndGet();
RegionInfo region = loc.getRegion();
if (locateFinished(region, endKey, endKeyInclusive)) {
locateFinished.set(true);
} else {
conn.getLocator()
.getRegionLocation(tableName, region.getEndKey(), RegionLocateType.CURRENT,
operationTimeoutNs)
.whenComplete((l, e) -> onLocateComplete(stubMaker, callable, callback, locs, endKey,
endKeyInclusive, locateFinished, unfinishedRequest, l, e));
}
coprocessorService(stubMaker, callable, region, region.getStartKey()).whenComplete((r, e) -> {
if (e != null) {
callback.onRegionError(region, e);
} else {
callback.onRegionComplete(region, r);
}
if (unfinishedRequest.decrementAndGet() == 0 && locateFinished.get()) {
callback.onComplete();
}
});
}
示例6: connectExportedProtobufAddress
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
private AddressBookProtos.AddressBookService connectExportedProtobufAddress(ExportDeclaration declaration) throws EndpointException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, BinderException {
ProtobufferExportDeclarationWrapper pojo = ProtobufferExportDeclarationWrapper.create(declaration);
Bus cxfbus = BusFactory.getThreadDefaultBus();
BindingFactoryManager mgr = cxfbus.getExtension(BindingFactoryManager.class);
mgr.registerBindingFactory(ProtobufBindingFactory.PROTOBUF_BINDING_ID, new ProtobufBindingFactory(cxfbus));
Class<?> bufferService = AddressBookProtos.AddressBookService.class;
Class<?> bufferMessage = AddressBookProtos.AddressBookServiceMessage.class;
Class<? extends Message> generic = bufferMessage.asSubclass(Message.class);
RpcChannel channel = new SimpleRpcChannel(pojo.getAddress(), generic);
Method method = bufferService.getMethod("newStub", RpcChannel.class);
Object service = method.invoke(bufferService, channel);
AddressBookProtos.AddressBookService addressBook = (AddressBookProtos.AddressBookService) service;
return addressBook;
}
示例7: testRTEDuringAsyncConnectionSetup
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
@Test
public void testRTEDuringAsyncConnectionSetup() throws Exception {
TestRpcServer rpcServer = new TestRpcServer();
AsyncRpcClient client = createRpcClientRTEDuringConnectionSetup(CONF);
try {
rpcServer.start();
InetSocketAddress address = rpcServer.getListenerAddress();
if (address == null) {
throw new IOException("Listener channel is closed");
}
MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
RpcChannel channel =
client.createRpcChannel(ServerName.valueOf(address.getHostName(), address.getPort(),
System.currentTimeMillis()), User.getCurrent(), 0);
final AtomicBoolean done = new AtomicBoolean(false);
PayloadCarryingRpcController controller = new PayloadCarryingRpcController();
controller.notifyOnFail(new RpcCallback<IOException>() {
@Override
public void run(IOException e) {
done.set(true);
LOG.info("Caught expected exception: " + e.toString());
assertTrue(StringUtils.stringifyException(e).contains("Injected fault"));
}
});
channel.callMethod(md, controller, param, md.getOutputType().toProto(),
new RpcCallback<Message>() {
@Override
public void run(Message parameter) {
done.set(true);
fail("Expected an exception to have been thrown!");
}
});
TEST_UTIL.waitFor(1000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return done.get();
}
});
} finally {
client.close();
rpcServer.stop();
}
}
示例8: newServiceStub
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T extends Service> T newServiceStub(Class<T> service, RpcChannel channel)
throws Exception {
return (T)Methods.call(service, null, "newStub",
new Class[]{ RpcChannel.class }, new Object[]{ channel });
}
示例9: CoprocessorServiceBuilderImpl
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
public CoprocessorServiceBuilderImpl(Function<RpcChannel, S> stubMaker,
ServiceCaller<S, R> callable, CoprocessorCallback<R> callback) {
this.stubMaker = Preconditions.checkNotNull(stubMaker, "stubMaker is null");
this.callable = Preconditions.checkNotNull(callable, "callable is null");
this.callback = Preconditions.checkNotNull(callback, "callback is null");
}
示例10: coprocessorService
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
@Override
public <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
ServiceCaller<S, R> callable) {
return wrap(rawAdmin.coprocessorService(stubMaker, callable));
}
示例11: coprocessorService
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
@Override
public <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
ServiceCaller<S, R> callable, byte[] row) {
return wrap(rawTable.coprocessorService(stubMaker, callable, row));
}
示例12: createRpcChannel
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
/**
* Creates a "channel" that can be used by a protobuf service. Useful setting up
* protobuf stubs.
*
* @param sn server name describing location of server
* @param user which is to use the connection
* @param rpcTimeout default rpc operation timeout
*
* @return A rpc channel that goes via this rpc client instance.
*/
public RpcChannel createRpcChannel(final ServerName sn, final User user, int rpcTimeout) {
return new RpcChannelImplementation(this, sn, user, rpcTimeout);
}
示例13: newRpcChannel
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
/**
* Create a {@link RpcChannel} that uses the given
* {@link RpcConnectionFactory} to connect to the RPC server and the given
* {@link Executor} to listen for the RPC response after sending the request.
* RPCs made using this {@link RpcChannel} will not block the thread calling
* the RPC method. Use {@link #newBlockingRpcChannel(RpcConnectionFactory)} if
* you want the RPC method to block.
* <p>
* This channel doesn't call the callback if the server-side implementation
* did not call the callback. If any error occurs, it will call the callback
* with null and update the controller with the error.
*/
public static RpcChannel newRpcChannel(
RpcConnectionFactory connectionFactory, Executor executor) {
return new RpcChannelImpl(connectionFactory, executor);
}
示例14: coprocessorService
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
/**
* Execute the given coprocessor call on the region which contains the given {@code row}.
* <p>
* The {@code stubMaker} is just a delegation to the {@code newStub} call. Usually it is only a
* one line lambda expression, like:
*
* <pre>
* <code>
* channel -> xxxService.newStub(channel)
* </code>
* </pre>
*
* @param stubMaker a delegation to the actual {@code newStub} call.
* @param callable a delegation to the actual protobuf rpc call. See the comment of
* {@link ServiceCaller} for more details.
* @param row The row key used to identify the remote region location
* @param <S> the type of the asynchronous stub
* @param <R> the type of the return value
* @return the return value of the protobuf rpc call, wrapped by a {@link CompletableFuture}.
* @see ServiceCaller
*/
<S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
ServiceCaller<S, R> callable, byte[] row);
示例15: coprocessorService
import com.google.protobuf.RpcChannel; //导入依赖的package包/类
/**
* Execute the given coprocessor call on the master.
* <p>
* The {@code stubMaker} is just a delegation to the {@code newStub} call. Usually it is only a
* one line lambda expression, like:
*
* <pre>
* <code>
* channel -> xxxService.newStub(channel)
* </code>
* </pre>
* @param stubMaker a delegation to the actual {@code newStub} call.
* @param callable a delegation to the actual protobuf rpc call. See the comment of
* {@link ServiceCaller} for more details.
* @param <S> the type of the asynchronous stub
* @param <R> the type of the return value
* @return the return value of the protobuf rpc call, wrapped by a {@link CompletableFuture}.
* @see ServiceCaller
*/
<S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker,
ServiceCaller<S, R> callable);