本文整理汇总了Java中io.grpc.stub.StreamObserver.onCompleted方法的典型用法代码示例。如果您正苦于以下问题:Java StreamObserver.onCompleted方法的具体用法?Java StreamObserver.onCompleted怎么用?Java StreamObserver.onCompleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.stub.StreamObserver
的用法示例。
在下文中一共展示了StreamObserver.onCompleted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sayHelloStreaming
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void sayHelloStreaming(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
try {
logger.info("Saying hi");
responseObserver.onNext(
HelloReply.newBuilder().setMessage("Hello " + req.getName()).build());
Thread.sleep(100);
logger.info("Saying hi");
responseObserver.onNext(
HelloReply.newBuilder().setMessage("Hello " + req.getName() + "!").build());
Thread.sleep(100);
logger.info("Saying hi");
responseObserver.onNext(
HelloReply.newBuilder().setMessage("Hello " + req.getName() + "!!").build());
} catch (InterruptedException e) {
responseObserver.onError(e);
} finally {
responseObserver.onCompleted();
}
}
示例2: createStorageFormat
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void createStorageFormat(MetaProto.StorageFormatParam storageFormat,
StreamObserver<StatusProto.ResponseStatus> responseStreamObserver)
{
TransactionController txController = null;
try {
txController = ConnectionPool.INSTANCE().getTxController();
ActionResponse input = new ActionResponse();
input.setParam(storageFormat);
txController.setAutoCommit(false);
txController.addAction(new CreateStorageFormatAction());
txController.commit(input);
responseStreamObserver.onNext(MetaConstants.OKStatus);
responseStreamObserver.onCompleted();
}
catch (ParaFlowException e) {
responseStreamObserver.onNext(e.getResponseStatus());
responseStreamObserver.onCompleted();
e.handle();
}
finally {
if (txController != null) {
txController.close();
}
}
}
示例3: streamBooks
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public synchronized void streamBooks(
ListBooksRequest request, StreamObserver<ListBooksResponse> responseObserver) {
NavigableMap<String, Book> cursor = booksById;
// Resume iteration from the page token.
if (!request.getPageToken().isEmpty()) {
String pageToken = decodePageToken(request.getPageToken());
cursor = cursor.tailMap(pageToken, false);
}
cursor
.values()
.stream()
.limit(request.getPageSize() > 0 ? request.getPageSize() : DEFAULT_PAGE_SIZE)
.forEach(
book ->
responseObserver.onNext(
ListBooksResponse.newBuilder()
.addBooks(book)
.setNextPageToken(encodePageToken(book.getId()))
.build()));
responseObserver.onCompleted();
}
示例4: blockForMillis
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void blockForMillis(BlockForMillisRequest request,
StreamObserver<Empty> responseObserver) {
logger.info("blocking for millis [" + request.getMillis() + "] request received at "
+ SimpleServiceImpl.DATE_FORMAT.format(new Date(System.currentTimeMillis())));
try {
Thread.sleep(request.getMillis());
responseObserver.onNext(Empty.getDefaultInstance());
} catch (InterruptedException e) {
responseObserver.onError(e);
}
responseObserver.onCompleted();
}
示例5: noop
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void noop(Empty request, StreamObserver<Empty> responseObserver) {
logger.info("no-op request received at " + DATE_FORMAT.format(
new Date(System.currentTimeMillis())));
responseObserver.onNext(Empty.getDefaultInstance());
responseObserver.onCompleted();
}
示例6: createDatabase
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void createDatabase(MetaProto.DbParam dbParam,
StreamObserver<StatusProto.ResponseStatus> responseStreamObserver)
{
TransactionController txController = null;
try {
txController = ConnectionPool.INSTANCE().getTxController();
ActionResponse input = new ActionResponse();
input.setParam(dbParam);
input.setProperties("userName", dbParam.getUserName());
txController.setAutoCommit(false);
txController.addAction(new GetUserIdAction());
txController.addAction(new CreateDatabaseAction());
txController.commit(input);
responseStreamObserver.onNext(MetaConstants.OKStatus);
responseStreamObserver.onCompleted();
}
catch (ParaFlowException e) {
responseStreamObserver.onNext(e.getResponseStatus());
responseStreamObserver.onCompleted();
e.handle();
}
finally {
if (txController != null) {
txController.close();
}
}
}
示例7: removeService
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void removeService(ServiceRequest request, StreamObserver<Empty> responseObserver) {
// TODO Auto-generated method stub
String serviceName=request.getServiceName();
HostInfo hostInfo=request.getHostInfo();
Register.removeService(serviceName, hostInfo);
Empty result=Empty.newBuilder().build();
responseObserver.onNext(result);
responseObserver.onCompleted();
}
示例8: createBlockIndex
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void createBlockIndex(MetaProto.BlockIndexParam blockIndex,
StreamObserver<StatusProto.ResponseStatus> responseStreamObserver)
{
TransactionController txController = null;
try {
txController = ConnectionPool.INSTANCE().getTxController();
ActionResponse input = new ActionResponse();
input.setParam(blockIndex);
input.setProperties("dbName", blockIndex.getDatabase().getDatabase());
input.setProperties("tblName", blockIndex.getTable().getTable());
txController.setAutoCommit(false);
txController.addAction(new GetDatabaseIdAction());
txController.addAction(new GetTableIdAction());
txController.addAction(new CreateBlockIndexAction());
txController.commit(input);
responseStreamObserver.onNext(MetaConstants.OKStatus);
responseStreamObserver.onCompleted();
}
catch (ParaFlowException e) {
responseStreamObserver.onNext(e.getResponseStatus());
responseStreamObserver.onCompleted();
e.handle();
}
finally {
if (txController != null) {
txController.close();
}
}
}
示例9: register
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void register(ApplicationInstance request, StreamObserver<ApplicationInstanceMapping> responseObserver) {
int instanceId = instanceSequence.incrementAndGet();
ValidateData.INSTANCE.getRegistryItem().registryInstance(new RegistryItem.Instance(request.getApplicationId(), instanceId));
responseObserver.onNext(ApplicationInstanceMapping.newBuilder().setApplicationId(request.getApplicationId())
.setApplicationInstanceId(instanceId).build());
responseObserver.onCompleted();
}
示例10: sayHi
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void sayHi(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
final HelloReply reply = HelloReply.newBuilder()
.setName(request.getName())
.setMessage("Hello " + request.getName())
.build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
示例11: requestReply
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void requestReply(
SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {
SimpleResponse response =
SimpleResponse.newBuilder().setResponseMessage(request.getRequestMessage()).build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
示例12: echo
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void echo(Msgs.EchoIn request, StreamObserver<Msgs.EchoOut> responseObserver) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < request.getTimes(); ++i) {
sb.append(request.getContent());
}
EchoOut out = EchoOut.newBuilder().setReply(sb.toString()).build();
responseObserver.onNext(out);
responseObserver.onCompleted();
}
示例13: add
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void add(RequestInfo request,
StreamObserver<ResponseInfo> responseObserver) {
// TODO Auto-generated method stub
int a=request.getA();
int b=request.getB();
ResponseInfo result=ResponseInfo.newBuilder()
.setC(a+b)
.build();
responseObserver.onNext(result);
responseObserver.onCompleted();
}
示例14: sayHello
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void sayHello(GreeterGrpc.sayHello_args req, StreamObserver<GreeterGrpc.sayHello_result> responseObserver) {
GreeterGrpc.sayHello_result reply = new GreeterGrpc.sayHello_result();
reply.success = new HelloResponse("Hello " + req.request.name);
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
示例15: multipleContextTransfersOneHopSync
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Test
public void multipleContextTransfersOneHopSync() throws Exception {
Metadata.Key<String> ctxKey = Metadata.Key.of("ctx-context-key", Metadata.ASCII_STRING_MARSHALLER);
Metadata.Key<String> l5dKey = Metadata.Key.of("l5d-context-key", Metadata.ASCII_STRING_MARSHALLER);
String expectedCtxValue = "context-value";
AtomicReference<String> ctxValue = new AtomicReference<>();
AtomicReference<String> l5dValue = new AtomicReference<>();
// Service
GreeterGrpc.GreeterImplBase svc = new GreeterGrpc.GreeterImplBase() {
@Override
public void sayHello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) {
ctxValue.set(AmbientContext.current().get(ctxKey));
l5dValue.set(AmbientContext.current().get(l5dKey));
responseObserver.onNext(HelloResponse.newBuilder().setMessage("Hello " + request.getName()).build());
responseObserver.onCompleted();
}
};
// Plumbing
serverRule1.getServiceRegistry().addService(ServerInterceptors.intercept(svc,
new AmbientContextServerInterceptor("ctx-"),
new AmbientContextServerInterceptor("l5d-")));
GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc
.newBlockingStub(serverRule1.getChannel())
.withInterceptors(
new AmbientContextClientInterceptor("ctx-"),
new AmbientContextClientInterceptor("l5d-"));
// Test
AmbientContext.initialize(Context.current()).run(() -> {
AmbientContext.current().put(ctxKey, expectedCtxValue);
AmbientContext.current().put(l5dKey, expectedCtxValue);
stub.sayHello(HelloRequest.newBuilder().setName("world").build());
});
assertThat(ctxValue.get()).isEqualTo(expectedCtxValue);
assertThat(l5dValue.get()).isEqualTo(expectedCtxValue);
}