Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. // Synchronous call to hash()
  2. public HashOutput hash(HashInput hashInput) {
  3.     return syncPasswordService.hash(hashInput);
  4. }
  5.  
  6. // Asynchronous call to hash()
  7. public HashOutput hashAsync(HashInput hashInput) {
  8.  
  9.         final HashOutput[] result = new HashOutput[1];
  10.         StreamObserver<HashOutput> responseObserver = new StreamObserver<HashOutput>() {
  11.  
  12.  
  13.             @Override
  14.             public void onNext(HashOutput output) {
  15.                 logger.info("Received hash: " + output);
  16.                 result[0] = output;
  17.             }
  18.  
  19.             @Override
  20.             public void onError(Throwable throwable) {
  21.                 Status status = Status.fromThrowable(throwable);
  22.                 logger.log(Level.WARNING, "RPC Error: {0}", status);
  23.             }
  24.  
  25.             @Override
  26.             public void onCompleted() {
  27.                 logger.info("Finished receiving HashOutput");
  28.             }
  29.         };
  30.  
  31.         try {
  32.             logger.info("Requesting HashOutput");
  33.             asyncPasswordService.hash(hashInput, responseObserver);
  34.             logger.info("Returned from requesting HashOutput");
  35.         } catch (StatusRuntimeException ex) {
  36.             logger.log(Level.WARNING, "RPC failed: {0}", ex.getStatus());
  37.             return null;
  38.         }
  39.         return result[0];
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement