2016-09-16 4 views
2

나는 cyclops-react를 async-retry와 함께 사용하기 시작했습니다. 나는 아직도 그걸로 길을 잃었습니다.cyclops-react와 async-retry : 타임 아웃시 재 시도하는 방법?

나는 SimpleReact를 사용하여 서버에서 타임 아웃을 시뮬레이션하지만 난 결코 이런 일에 시간 제한받지 해요 : 거기에 어떤 누락

private List<Object> executeParallel() { 
    List<Object> result = new SimpleReact(mainThreadPool) 
      .of(getSupplier()) 
      .withRetrier(new AsyncRetryExecutor(retryThreadPool) 
        .abortIf((t) -> !TimeoutException.class.isAssignableFrom(t.getClass())) 
      ) 
      .retry(retrySupplier()) 
      .block() 
      .collect(Collectors.toList()); 
    return result; 
} 

private Supplier getSupplier() { 
    return() -> someOperationThatTimesOut(); 
} 

private Function<Supplier, Object> retrySupplier() { 
    return supplier -> supplier.get(); 
} 

를?

+0

안녕하세요 호르헤, 이에 대한 자세한 답변을 추가하겠습니다.하지만 타임 아웃 할 수있는 기능은 재시도 연산자에 제공되어야합니다. –

답변

1

이 버전은

AtomicInteger count = new AtomicInteger(0); 

@Test 
public void executeParallel() { 
    List<Object> result = new SimpleReact(Executors.newFixedThreadPool(1)) 
      .of(getSupplier()) 
      .withRetrier(new AsyncRetryExecutor(Executors.newScheduledThreadPool(1)) 
      .retry(Supplier::get) 
      .block() 
      .collect(Collectors.toList()); 
    System.out.println(result); 
} 

private Supplier<String> getSupplier() { 
    return() -> { 
     System.out.println("Attempt " + count.incrementAndGet()); 
     if(count.get()<4) 
      throw ExceptionSoftener.throwSoftenedException(new TimeoutException()); 
     return "success"; 
    }; 
} 

작동 내가 당신이 비동기 retrier에 abortIf 필요하지 않습니다 의심

Attempt 1 
Attempt 2 
Attempt 3 
Attempt 4 
[success] 

을 출력 할 것이다, 나는 내부에 무슨 일이 일어나고 있는지 확실하지 않다 someOperationThatTimesOut() - 여기 키가 될 수 있습니다.

+0

응답 해 주셔서 감사합니다. @ john-mcClean. 기본적으로 그렇습니다. 모든 것이 정확했지만 시간 초과가 발생하는 작업은 설정 오류로 인해 시간 초과되지 않았습니다. – Jorge

+0

쿨 - 더 이상의 질문이 있으시면 멀리하십시오! 감사! –