All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.java.ServiceGrpcServerInsert.template Maven / Gradle / Ivy

The newest version!

    @Override
    public void execute@service_name@(@service_request@ request, StreamObserver<@service_response@> responseObserver) {
        IMetricSummary metric = Metrics.getInstance().mTraffic;
        boolean isOK = false;
        long s = System.currentTimeMillis();

        AbstractBackendController.ReqRes<@service_request@, @service_response@> reqres =
            new AbstractBackendController.ReqRes<>(request);

        List pipelines = BackendControllerFactory.getInstance().pipelines;
        ServiceContext context = new ServiceContext();
        try {
            if (pipelines != null) {
                for (AbstractBackendController pipeline : pipelines)
                    pipeline.onRequest@service_name@(reqres, null, context);
            }
            LOG.info("@service_name@ Manual mode: " + context.manualOverride );


            if ( ! context.manualOverride && reqres.response == null) {
               @grpc_impl@ @service_name@(null, reqres, null, context);
            }

            if (pipelines != null && reqres.response == null  ) {
                for (AbstractBackendController pipeline : pipelines)
                    pipeline.onResponse@service_name@(reqres, null, context);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
            if (pipelines != null) {
                for (AbstractBackendController pipeline : pipelines)
                    pipeline.onError@service_name@(reqres, null, context, ex);
            }
        }

        if ( null == reqres.response)  reqres.response = @[email protected]().setStatus(
            Status.newBuilder().setStatus(StatusCode.UNKNOWN_ERROR).addErrorMessages("Null response").build()).build();


        responseObserver.onNext(reqres.response);
        responseObserver.onCompleted();
        isOK = reqres.response.getStatus().getStatus() == StatusCode.SUCCESS;
        metric.observe( ( System.currentTimeMillis() - s), "@service_name@", (isOK) ? "OK" : "KO" );

    }

      @Override
      public void execute@service_name@Bulk(Bulk@service_request@ requestA, StreamObserver responseObserver) {

          IMetricSummary metric = Metrics.getInstance().mTraffic;
          boolean isOK = false;
          long s = System.currentTimeMillis();

          AbstractBackendController.ReqRes reqres =
              new AbstractBackendController.ReqRes<>(requestA);

          List pipelines = BackendControllerFactory.getInstance().pipelines;
          ServiceContext context = new ServiceContext();
          try {
              if (pipelines != null) {
                  for (AbstractBackendController pipeline : pipelines)
                      pipeline.onRequestBulk@service_name@(reqres, null, context);
              }
              LOG.info("@service_name@Bulk Manual mode: " + context.manualOverride );

              if ( ! context.manualOverride && reqres.response == null) {
                  @grpc_impl@@service_name@Bulk(null, reqres, null, context);
              }

              if (pipelines != null  ) {
                  for (AbstractBackendController pipeline : pipelines)
                      pipeline.onResponseBulk@service_name@(reqres, null, context);
              }

          } catch (Exception ex) {
                ex.printStackTrace();
                if (pipelines != null) {
                    for (AbstractBackendController pipeline : pipelines)
                        pipeline.onErrorBulk@service_name@(reqres, null, context, ex);
                }
          }

          if ( null == reqres.response)  reqres.response = Bulk@[email protected]().setStatus(
                Status.newBuilder().setStatus(StatusCode.UNKNOWN_ERROR).addErrorMessages("Null response reveived").build()).build();


          responseObserver.onNext(reqres.response);
          responseObserver.onCompleted();
          isOK = reqres.response.getStatus().getStatus() == StatusCode.SUCCESS;
          metric.observe( ( System.currentTimeMillis() - s), "@service_name@Bulk" , (isOK) ? "OK" : "KO" );

      }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy