Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Synchronous call to hash()
- public HashOutput hash(HashInput hashInput) {
- return syncPasswordService.hash(hashInput);
- }
- // Asynchronous call to hash()
- public HashOutput hashAsync(HashInput hashInput) {
- final HashOutput[] result = new HashOutput[1];
- StreamObserver<HashOutput> responseObserver = new StreamObserver<HashOutput>() {
- @Override
- public void onNext(HashOutput output) {
- logger.info("Received hash: " + output);
- result[0] = output;
- }
- @Override
- public void onError(Throwable throwable) {
- Status status = Status.fromThrowable(throwable);
- logger.log(Level.WARNING, "RPC Error: {0}", status);
- }
- @Override
- public void onCompleted() {
- logger.info("Finished receiving HashOutput");
- }
- };
- try {
- logger.info("Requesting HashOutput");
- asyncPasswordService.hash(hashInput, responseObserver);
- logger.info("Returned from requesting HashOutput");
- } catch (StatusRuntimeException ex) {
- logger.log(Level.WARNING, "RPC failed: {0}", ex.getStatus());
- return null;
- }
- return result[0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement