2016-09-16 5 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

こんにちはJorge、私はこれに詳しい回答を追加しますが、タイムアウトできる機能は再試行オペレータに提供する必要があります。 –

答えて

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

クール - もう質問がある場合は消してください!ありがとう! –

関連する問題