11package reciter .scopus .retriever ;
22
3+ import java .io .IOException ;
34import java .util .ArrayList ;
45import java .util .Iterator ;
56import java .util .List ;
6- import java .util .concurrent .Callable ;
77import java .util .concurrent .ExecutorService ;
88import java .util .concurrent .Executors ;
9+ import java .util .concurrent .TimeUnit ;
910
1011import org .slf4j .Logger ;
1112import org .slf4j .LoggerFactory ;
1213
14+ import com .github .rholder .retry .Retryer ;
15+ import com .github .rholder .retry .Retryer .RetryerCallable ;
16+ import com .github .rholder .retry .RetryerBuilder ;
17+ import com .github .rholder .retry .StopStrategies ;
18+ import com .github .rholder .retry .WaitStrategies ;
19+ import com .google .common .base .Predicates ;
20+
1321import reciter .model .scopus .ScopusArticle ;
1422import reciter .scopus .callable .ScopusUriParserCallable ;
1523import reciter .scopus .querybuilder .ScopusXmlQuery ;
@@ -29,6 +37,11 @@ public class ScopusArticleRetriever {
2937 */
3038 protected static final int SCOPUS_MAX_THRESHOLD = 25 ;
3139
40+ /**
41+ * @param pmids scopus query could be DOI, scopusDocId, PMID
42+ * @param type to query scopus like DOI(), SCOPUS-ID(), PMID() etc.
43+ * @return
44+ */
3245 public List <ScopusArticle > retrieveScopus (List <Object > pmids , String type ) {
3346 slf4jLogger .info ("Pmids:" + pmids );
3447 List <String > pmidQueries = new ArrayList <>();
@@ -62,16 +75,25 @@ public List<ScopusArticle> retrieveScopus(List<Object> pmids, String type) {
6275 }
6376 }
6477
65- List <Callable <List <ScopusArticle >>> callables = new ArrayList <>();
78+ List <RetryerCallable <List <ScopusArticle >>> callables = new ArrayList <RetryerCallable <List <ScopusArticle >>>();
79+ Retryer <List <ScopusArticle >> retryer = RetryerBuilder .<List <ScopusArticle >>newBuilder ()
80+ .retryIfResult (Predicates .<List <ScopusArticle >>isNull ())
81+ .retryIfExceptionOfType (IOException .class )
82+ .retryIfRuntimeException ()
83+ .withWaitStrategy (WaitStrategies .fibonacciWait (100L , 2L , TimeUnit .MINUTES ))
84+ .withStopStrategy (StopStrategies .stopAfterAttempt (10 ))
85+ .build ();
6686
6787 for (String query : pmidQueries ) {
6888 ScopusXmlQuery scopusXmlQuery = new ScopusXmlQuery .ScopusXmlQueryBuilder (query , SCOPUS_MAX_THRESHOLD ).build ();
6989 String scopusUrl = scopusXmlQuery .getQueryUrl ();
7090 ScopusUriParserCallable scopusUriParserCallable = new ScopusUriParserCallable (new ScopusXmlHandler (), scopusUrl );
71- callables .add (scopusUriParserCallable );
91+ RetryerCallable <List <ScopusArticle >> retryerCallable = retryer .wrap (scopusUriParserCallable );
92+ callables .add (retryerCallable );
93+ //callables.add(scopusUriParserCallable);
7294 }
7395
74- List <List <ScopusArticle >> list = new ArrayList <>();
96+ List <List <ScopusArticle >> list = new ArrayList <List < ScopusArticle > >();
7597
7698 int numAvailableProcessors = Runtime .getRuntime ().availableProcessors ();
7799 ExecutorService executor = Executors .newFixedThreadPool (numAvailableProcessors );
0 commit comments