当前位置: 首页>>代码示例>>Java>>正文


Java StreamObserver.onCompleted方法代码示例

本文整理汇总了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();
  }
}
 
开发者ID:google,项目名称:rejoiner,代码行数:21,代码来源:HelloWorldServer.java

示例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();
        }
    }
}
 
开发者ID:dbiir,项目名称:paraflow,代码行数:27,代码来源:MetaService.java

示例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();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:26,代码来源:BookService.java

示例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();
}
 
开发者ID:mavrukin,项目名称:grpc-base-gradle,代码行数:14,代码来源:LessSimpleServiceImpl.java

示例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();
}
 
开发者ID:mavrukin,项目名称:grpc-base-gradle,代码行数:8,代码来源:SimpleServiceImpl.java

示例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();
        }
    }
}
 
开发者ID:dbiir,项目名称:paraflow,代码行数:29,代码来源:MetaService.java

示例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();
}
 
开发者ID:laddcn,项目名称:grpcx,代码行数:11,代码来源:RegisterService.java

示例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();
        }
    }
}
 
开发者ID:dbiir,项目名称:paraflow,代码行数:31,代码来源:MetaService.java

示例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();
}
 
开发者ID:SkywalkingTest,项目名称:skywalking-mock-collector,代码行数:10,代码来源:MockInstanceDiscoveryService.java

示例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();
}
 
开发者ID:imrenagi,项目名称:microservice-skeleton,代码行数:10,代码来源:GreeterServiceImpl.java

示例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();
}
 
开发者ID:netifi,项目名称:rpc-thunderdome,代码行数:9,代码来源:GrpcServer.java

示例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();
}
 
开发者ID:altiplanogao,项目名称:rpc-comparison,代码行数:11,代码来源:AskerService.java

示例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();
}
 
开发者ID:laddcn,项目名称:grpcx,代码行数:13,代码来源:AddService.java

示例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();
}
 
开发者ID:grpc-ecosystem,项目名称:grift,代码行数:8,代码来源:HelloWorldServer.java

示例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);
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:41,代码来源:AmbientContextTransferTest.java


注:本文中的io.grpc.stub.StreamObserver.onCompleted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。