Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. public boolean isDjpDisconnected() {
  2. CompletableFuture<String> timeStamp = djpService.getTimeStamp();
  3.  
  4. try {
  5. return timeStamp.get(3, TimeUnit.SECONDS).isEmpty();
  6. } catch (InterruptedException | ExecutionException | TimeoutException e) {
  7. log.warn("DJP connection can't be established", e.getCause());
  8. // dari sonar saranin handlenya gini
  9. // Thread.currentThread().interrupt();
  10. // tapi masalahnya exceptionnya itu kena di async thread punya si completableFuture,
  11. // bukan di thread yang manggil method isDjpDisconnected() ini
  12. // si async thread completableFuture jadinya masih di interruptedException, alias ngegantung gitu
  13. // ga pernah masuk ke .handle() maupun .whenComplete()
  14. return true;
  15. }
  16. }
  17.  
  18.  
  19. @Override
  20. public CompletableFuture<String> getTimeStamp() {
  21.  
  22. return CompletableFuture
  23. .supplyAsync(() -> postRequest(
  24. djpGatewayConfig.getTimestampPath(),
  25. null,
  26. String.class
  27. ), taskExecutor)
  28. // ga masuk ke handle() sini waktu 3 exception di atas kejadian
  29. .handle(mappingError("getTimeStamp"));
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement