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


Java StreamObserver.onNext方法代码示例

本文整理汇总了Java中io.grpc.stub.StreamObserver.onNext方法的典型用法代码示例。如果您正苦于以下问题:Java StreamObserver.onNext方法的具体用法?Java StreamObserver.onNext怎么用?Java StreamObserver.onNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.grpc.stub.StreamObserver的用法示例。


在下文中一共展示了StreamObserver.onNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: manyToOne

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Test
public void manyToOne() {
    AtomicBoolean called = new AtomicBoolean(false);
    GreeterGrpc.GreeterStub stub = GreeterGrpc.newStub(channel);

    StreamObserver<HelloRequest> requestStream = stub.sayHelloReqStream(new LambdaStreamObserver<>(
            response -> {
                assertThat(response.getMessage()).isEqualTo("Hello A and B and C");
                called.set(true);
            }
    ));

    requestStream.onNext(HelloRequest.newBuilder().setName("A").build());
    requestStream.onNext(HelloRequest.newBuilder().setName("B").build());
    requestStream.onNext(HelloRequest.newBuilder().setName("C").build());
    requestStream.onCompleted();

    await().atMost(1, TimeUnit.SECONDS).untilTrue(called);
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:20,代码来源:StandardClientReactiveServerInteropTest.java

示例2: downloadProductImage

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void downloadProductImage(DownloadProductImageRequest request, StreamObserver<DataChunk> responseObserver) {
  try {
    BufferedInputStream imageStream = new BufferedInputStream(
        productImageSeeker.seekProductImage(request.getProductId())
    );
    int bufferSize = 256 * 1024;// 256k
    byte[] buffer = new byte[bufferSize];
    int length;
    while ((length = imageStream.read(buffer, 0, bufferSize)) != -1) {
      responseObserver.onNext(
          DataChunk.newBuilder().setData(ByteString.copyFrom(buffer, 0, length)).build()
      );
    }
    responseObserver.onCompleted();
    imageStream.close();
    counter.labels("downloadProductImage", "success");
  } catch (Exception e) {
    counter.labels("downloadProductImage", "failed");
    log.error("error on read product image", e);
    responseObserver.onError(e);
  }

}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:25,代码来源:ProductReadService.java

示例3: createTblPriv

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void createTblPriv(MetaProto.TblPrivParam tblPriv,
                          StreamObserver<StatusProto.ResponseStatus> responseStreamObserver)
{
    TransactionController txController = null;
    try {
        txController = ConnectionPool.INSTANCE().getTxController();
        ActionResponse input = new ActionResponse();
        input.setParam(tblPriv);
        input.setProperties("dbName", tblPriv.getDbName());
        input.setProperties("tblName", tblPriv.getTblName());
        input.setProperties("userName", tblPriv.getUserName());
        txController.setAutoCommit(false);
        txController.addAction(new GetDatabaseIdAction());
        txController.addAction(new GetTableIdAction());
        txController.addAction(new GetUserIdAction());
        txController.addAction(new CreateTblPrivAction());
        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,代码行数:33,代码来源:MetaService.java

示例4: failPlease

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void failPlease(FailWithProbabilityOrSucceedEchoRequest request,
                       StreamObserver<EchoResponse> responseObserver) {
    EchoRequest echoRequest = request.getEchoRequest();
    int failProbability = request.getFailProbability();
    Preconditions.checkArgument(failProbability >= 0 && failProbability <= 100,
            "fail probability not [" + failProbability + "] not in range [0, 100] inclusive");
    logger.info("fail please - p(" + failProbability + " / 100)" + " echo: " + echoRequest.getEcho()
            + " with " + "repetitions: " + echoRequest.getRepeatEcho() + " received at "
            + DATE_FORMAT.format(new Date(System.currentTimeMillis())));

    int randomFail = RANDOM.nextInt(100);
    if (randomFail < failProbability) {
        Status status = Status.INTERNAL;
        status = status.withCause(new FailPleaseException("Looks like you hit jackpot - we failed!"));
        responseObserver.onError(status.asRuntimeException());
    } else {
        responseObserver.onNext(buildEchoResponseFromEchoRequest(echoRequest));
        responseObserver.onCompleted();
    }
}
 
开发者ID:mavrukin,项目名称:grpc-base-gradle,代码行数:22,代码来源:SimpleServiceImpl.java

示例5: refresh

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void refresh(RefreshRequest request, StreamObserver<Empty> responseObserver) {
	// TODO Auto-generated method stub
	String serviceName=request.getServiceName();
	ArrayList<HostInfo> hostInfos=new ArrayList<HostInfo>();
	logger.info("Refresh host infos:"+serviceName+" Begin");
	for(Object object:request.getHostInfosList())
	{
		HostInfo hostInfo=(HostInfo) object;
		hostInfos.add(hostInfo);
		logger.info(HostInfoFormatter.getFormatString(hostInfo));
	}
	LoadBalance.refreshHostInfos(serviceName, hostInfos);
	logger.info("Refresh host infos:"+serviceName+" End");
	Empty result=Empty.newBuilder().build();
	responseObserver.onNext(result);
	responseObserver.onCompleted();
}
 
开发者ID:laddcn,项目名称:grpcx,代码行数:19,代码来源:ConsumerRefreshService.java

示例6: bodistream

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@RequestMapping("/bodistream")
public HelloReply bodistream(@RequestParam(value = "name", required = false) String name) {
  HelloRequest request = new HelloRequest();
  request.setName(name);
  StreamObserver<com.quancheng.examples.model.hello.HelloRequest> requestObserver =
      helloService.sayHelloBidiStream(responseObserver());
  try {
    for (int i = 0; i < 10; i++) {
      requestObserver.onNext(request);
    }
  } catch (Exception e) {
    requestObserver.onError(e);
  }
  requestObserver.onCompleted();
  return null;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:17,代码来源:ProxyServiceController.java

示例7: register

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void register(Application request, StreamObserver<ApplicationMapping> responseObserver) {
    logger.debug("receive application register.");
    ApplicationMapping.Builder builder = ApplicationMapping.newBuilder();
    for (String applicationCode : request.getApplicationCodeList()) {
        if (applicationCode.startsWith("localhost") || applicationCode.startsWith("127.0.0.1")){
            continue;
        }
        Integer applicationId = applicationMapping.get(applicationCode);
        if (applicationId == null) {
            applicationId = currentId.incrementAndGet();
            applicationMapping.put(applicationCode, applicationId);
            ValidateData.INSTANCE.getRegistryItem().registryApplication(new RegistryItem.Application(applicationCode,
                applicationId));
        }

        builder.addApplication(KeyWithIntegerValue.newBuilder().setKey(applicationCode).setValue(applicationId));
    }
    responseObserver.onNext(builder.build());
    responseObserver.onCompleted();
}
 
开发者ID:SkywalkingTest,项目名称:skywalking-mock-collector,代码行数:22,代码来源:MockApplicationRegisterService.java

示例8: getStore

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
public void getStore(GetStoreRequest request, StreamObserver<GetStoreResponse> resp) {
  try {
    resp.onNext(getStoreResp.removeFirst().get());
    resp.onCompleted();
  } catch (Exception e) {
    resp.onError(Status.INTERNAL.asRuntimeException());
  }
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:9,代码来源:PDMockServer.java

示例9: createTable

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
    public void createTable(MetaProto.TblParam tblParam,
                            StreamObserver<StatusProto.ResponseStatus> responseStreamObserver)
    {
        TransactionController txController = null;
        try {
            txController = ConnectionPool.INSTANCE().getTxController();
            ActionResponse input = new ActionResponse();
            input.setParam(tblParam);
            input.setProperties("userName", tblParam.getUserName());
            input.setProperties("dbName", tblParam.getDbName());
            input.setProperties("sfName", tblParam.getStorageFormatName());
            input.setProperties("funcName", tblParam.getFuncName());
            txController.setAutoCommit(false);
            txController.addAction(new GetUserIdAction());
            txController.addAction(new GetDatabaseIdAction());
            txController.addAction(new GetStorageFormatIdAction());
            txController.addAction(new GetFuncIdAction());
            txController.addAction(new CreateTableAction());
            txController.addAction(new GetTableIdAction());
            txController.addAction(new CreateColumnAction());
//            txController.addAction(new CreateTblFuncAction());
            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,代码行数:38,代码来源:MetaService.java

示例10: contextTransfersOneHopSync

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Test
public void contextTransfersOneHopSync() throws Exception {
    Metadata.Key<String> ctxKey = Metadata.Key.of("ctx-context-key", Metadata.ASCII_STRING_MARSHALLER);
    String expectedCtxValue = "context-value";
    AtomicReference<String> ctxValue = new AtomicReference<>();

    // Service
    GreeterGrpc.GreeterImplBase svc = new GreeterGrpc.GreeterImplBase() {
        @Override
        public void sayHello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) {
            ctxValue.set(AmbientContext.current().get(ctxKey));
            responseObserver.onNext(HelloResponse.newBuilder().setMessage("Hello " + request.getName()).build());
            responseObserver.onCompleted();
        }
    };

    // Plumbing
    serverRule1.getServiceRegistry().addService(ServerInterceptors
            .intercept(svc, new AmbientContextServerInterceptor("ctx-")));

    GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc
            .newBlockingStub(serverRule1.getChannel())
            .withInterceptors(new AmbientContextClientInterceptor("ctx-"));

    // Test
    AmbientContext.initialize(Context.current()).run(() -> {
        AmbientContext.current().put(ctxKey, expectedCtxValue);
        stub.sayHello(HelloRequest.newBuilder().setName("world").build());
    });

    assertThat(ctxValue.get()).isEqualTo(expectedCtxValue);
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:33,代码来源:AmbientContextTransferTest.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: perSessionShouldFailMissingTransportFilter

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Test
public void perSessionShouldFailMissingTransportFilter() throws Exception {
    class TestService extends GreeterGrpc.GreeterImplBase {
        @Override
        public void sayHello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) {
            responseObserver.onNext(HelloResponse.newBuilder().setMessage(Integer.toString(System.identityHashCode(this))).build());
            responseObserver.onCompleted();
        }
    }

    ClientSessionTransportFilter tf = new ClientSessionTransportFilter();
    Server server = InProcessServerBuilder.forName("perSessionShouldInstantiateOneInstancePerSession")
            .addService(new PerSessionService<>(() -> new TestService(), tf))
            .build()
            .start();

    ManagedChannel channel = InProcessChannelBuilder.forName("perSessionShouldInstantiateOneInstancePerSession")
            .usePlaintext(true)
            .build();
    GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel);

    try {
        assertThatThrownBy(() -> stub.sayHello(HelloRequest.getDefaultInstance()).getMessage()).isInstanceOf(StatusRuntimeException.class);
    } finally {
        channel.shutdown();
        server.shutdown();
    }
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:29,代码来源:PerSessionServiceTest.java

示例13: listBooks

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public synchronized void listBooks(
    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);
  }

  ImmutableList<Book> books =
      cursor
          .values()
          .stream()
          .limit(request.getPageSize() > 0 ? request.getPageSize() : DEFAULT_PAGE_SIZE)
          .collect(ImmutableList.toImmutableList());

  // Return one page of results.
  ListBooksResponse.Builder responseBuilder = ListBooksResponse.newBuilder().addAllBooks(books);
  // Set next page token to resume iteration in the next request.
  if (cursor.values().size() > books.size()) {
    String nextPageToken = encodePageToken(books.get(books.size() - 1).getId());
    responseBuilder.setNextPageToken(nextPageToken);
  }

  responseObserver.onNext(responseBuilder.build());
  responseObserver.onCompleted();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:30,代码来源:BookService.java

示例14: 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

示例15: linkVanished

import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void linkVanished(LinkVanishedMsg request,
                         StreamObserver<Void> responseObserver) {
    try {
        onLinksVanished(request, responseObserver);
        // If onNext call was not mandatory, it can be removed.
        responseObserver.onNext(Void.getDefaultInstance());
        responseObserver.onCompleted();
    } catch (Exception e) {
        log.error("Exception caught", e);
        responseObserver.onError(e);
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:14,代码来源:LinkProviderServiceServerProxy.java


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