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

com.undefinedlabs.scope.rules.proto.HelloServiceImpl Maven / Gradle / Ivy

package com.undefinedlabs.scope.rules.proto;

import io.grpc.Status;
import io.grpc.stub.StreamObserver;

public class HelloServiceImpl extends HelloServiceGrpc.HelloServiceImplBase {

    @Override
    public void helloUnitarySuccessSync(final HelloRequest request, final StreamObserver responseObserver) {
        this.helloUnitarySuccess(request, responseObserver);
    }

    @Override
    public void helloUnitarySuccessFutureDirect(final HelloRequest request, final StreamObserver responseObserver) {
        this.helloUnitarySuccess(request, responseObserver);
    }

    @Override
    public void helloUnitarySuccessFutureCallback(final HelloRequest request, final StreamObserver responseObserver) {
        this.helloUnitarySuccess(request, responseObserver);
    }

    @Override
    public void helloUnitarySuccessAsync(final HelloRequest request, final StreamObserver responseObserver) {
        this.helloUnitarySuccess(request, responseObserver);
    }

    @Override
    public void helloUnitaryFailureSync(HelloRequest request, StreamObserver responseObserver) {
        this.helloUnitaryFailure(request, responseObserver);
    }

    @Override
    public void helloUnitaryFailureFutureDirect(HelloRequest request, StreamObserver responseObserver) {
        this.helloUnitaryFailure(request, responseObserver);
    }

    @Override
    public void helloUnitaryFailureFutureCallback(HelloRequest request, StreamObserver responseObserver) {
        this.helloUnitaryFailure(request, responseObserver);
    }

    @Override
    public void helloUnitaryFailureAsync(HelloRequest request, StreamObserver responseObserver) {
        this.helloUnitaryFailure(request, responseObserver);
    }

    @Override
    public void helloServerStreamingSuccessSync(HelloRequest request, StreamObserver responseObserver) {
        this.helloServerStreamingSuccess(request, responseObserver);
    }

    @Override
    public void helloServerStreamingSuccessAsync(HelloRequest request, StreamObserver responseObserver) {
        this.helloServerStreamingSuccess(request, responseObserver);
    }

    @Override
    public void helloServerStreamFailureSync(HelloRequest request, StreamObserver responseObserver) {
        this.helloServerStreamFailure(request, responseObserver);
    }

    @Override
    public void helloServerStreamFailureAsync(HelloRequest request, StreamObserver responseObserver) {
        this.helloServerStreamFailure(request, responseObserver);
    }

    @Override
    public StreamObserver helloClientStreamingSuccessSync(final StreamObserver responseObserver) {
       return this.helloClientStreamingSuccess(responseObserver);
    }

    @Override
    public StreamObserver helloClientStreamingSuccessAsync(final StreamObserver responseObserver) {
        return this.helloClientStreamingSuccess(responseObserver);
    }

    @Override
    public StreamObserver helloClientStreamingFailureSync(final StreamObserver responseObserver) {
        return this.helloClientStreamingFailure(responseObserver);
    }

    @Override
    public StreamObserver helloClientStreamingFailureAsync(final StreamObserver responseObserver) {
        return this.helloClientStreamingFailure(responseObserver);
    }

    @Override
    public StreamObserver helloBiDirStreamingSuccessSync(final StreamObserver responseObserver) {
        return this.helloBiDirStreamingSuccess(responseObserver);
    }

    @Override
    public StreamObserver helloBiDirStreamingSuccessAsync(final StreamObserver responseObserver) {
        return this.helloBiDirStreamingSuccess(responseObserver);
    }

    @Override
    public StreamObserver helloBiDirStreamingFailureSync(final StreamObserver responseObserver) {
        return this.helloBiDirStreamingFailure(responseObserver);
    }

    @Override
    public StreamObserver helloBiDirStreamingFailureAsync(final StreamObserver responseObserver) {
        return this.helloBiDirStreamingFailure(responseObserver);
    }

    private void helloUnitarySuccess(final HelloRequest request, final StreamObserver responseObserver) {
        final String greeting = new StringBuilder()
                .append("Hello, ")
                .append(request.getFirstName())
                .append(" ")
                .append(request.getLastName())
                .toString();

        final HelloResponse response = HelloResponse.newBuilder()
                .setGreeting(greeting)
                .build();

        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }

    private void helloUnitaryFailure(HelloRequest request, StreamObserver responseObserver) {
        responseObserver.onError(Status.INTERNAL
                .withDescription("sampleException")
                .withCause(new RuntimeException("sampleException"))
                .asRuntimeException());
    }

    private void helloServerStreamingSuccess(HelloRequest request, StreamObserver responseObserver) {
        final String greeting = new StringBuilder()
                .append("Hello, ")
                .append(request.getFirstName())
                .append(" ")
                .append(request.getLastName())
                .toString();

        final HelloResponse response = HelloResponse.newBuilder()
                .setGreeting(greeting)
                .build();

        for(int i=0; i <= 3; i++){
            responseObserver.onNext(response);
        }

        responseObserver.onCompleted();
    }

    private void helloServerStreamFailure(HelloRequest request, StreamObserver responseObserver) {
        final String greeting = new StringBuilder()
                .append("Hello, ")
                .append(request.getFirstName())
                .append(" ")
                .append(request.getLastName())
                .toString();

        final HelloResponse response = HelloResponse.newBuilder()
                .setGreeting(greeting)
                .build();

        for(int i=0; i <= 3; i++){
            responseObserver.onNext(response);
        }

        responseObserver.onError(Status.INTERNAL
                .withDescription("sampleException")
                .withCause(new RuntimeException("sampleException"))
                .asRuntimeException());
        responseObserver.onCompleted();
    }

    private StreamObserver helloClientStreamingSuccess(final StreamObserver responseObserver) {
        return new StreamObserver() {
            @Override
            public void onNext(HelloRequest request) {
                final String greeting = new StringBuilder()
                        .append("Hello, ")
                        .append(request.getFirstName())
                        .append(" ")
                        .append(request.getLastName())
                        .toString();

                final HelloResponse response = HelloResponse.newBuilder()
                        .setGreeting(greeting)
                        .build();

                responseObserver.onNext(response);
                responseObserver.onCompleted();
            }

            @Override
            public void onError(Throwable t) {
                //N/A
            }

            @Override
            public void onCompleted() {
                responseObserver.onCompleted();
            }
        };
    }

    private StreamObserver helloClientStreamingFailure(final StreamObserver responseObserver) {
        return new StreamObserver() {
            @Override
            public void onNext(HelloRequest request) {
                responseObserver.onError(Status.INTERNAL
                        .withDescription("sampleException")
                        .withCause(new RuntimeException("sampleException"))
                        .asRuntimeException());
                //responseObserver.onCompleted();
            }

            @Override
            public void onError(Throwable t) {
                //N/A
            }

            @Override
            public void onCompleted() {
                responseObserver.onCompleted();
            }
        };
    }

    private StreamObserver helloBiDirStreamingSuccess(final StreamObserver responseObserver) {
        return new StreamObserver() {
            @Override
            public void onNext(HelloRequest request) {
                final String greeting = new StringBuilder()
                        .append("Hello, ")
                        .append(request.getFirstName())
                        .append(" ")
                        .append(request.getLastName())
                        .toString();

                final HelloResponse response = HelloResponse.newBuilder()
                        .setGreeting(greeting)
                        .build();

                responseObserver.onNext(response);
            }

            @Override
            public void onError(Throwable t) {
                //N/A
            }

            @Override
            public void onCompleted() {
                responseObserver.onCompleted();
            }
        };
    }

    private StreamObserver helloBiDirStreamingFailure(final StreamObserver responseObserver) {
        return new StreamObserver() {
            @Override
            public void onNext(HelloRequest request) {
                responseObserver.onError(Status.INTERNAL
                        .withDescription("sampleException")
                        .withCause(new RuntimeException("sampleException"))
                        .asRuntimeException());
                //responseObserver.onCompleted();
            }

            @Override
            public void onError(Throwable t) {
                //N/A
            }

            @Override
            public void onCompleted() {
                responseObserver.onCompleted();
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy