Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1.     @Override
  2.     public boolean matchesSafely(Callable action) {
  3.         T callResult;
  4.         boolean matched = false;
  5.         StopWatch timer = new StopWatch();
  6.  
  7.         timer.start();
  8.         try {
  9.             while (timer.getTime() <= maxWaitTime) {
  10.                 try {
  11.                     callResult = (T) action.call();
  12.                     matched = callResultMatcher.matches(callResult);
  13.                     if (matched) {
  14.                         return matched;
  15.                     }
  16.                 } catch (Exception e) {
  17.                     log.warning("An error occurred while calling an action: " + e.getMessage());
  18.                 }
  19.  
  20.                 try {
  21.                     Thread.sleep(checkInterval);
  22.                 } catch (InterruptedException e) {
  23.                     e.printStackTrace();
  24.                 }
  25.             }
  26.         } finally {
  27.             timer.stop();
  28.         }
  29.  
  30.         return matched;
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement