@@ -37,21 +37,31 @@ public class AruUtil {
3737
3838 private static final String BUG_SEARCH_URL = ARU_REST_URL + "/search?bug=%s" ;
3939
40- private static int REST_RETRIES = 10 ;
41- private static int REST_INTERVAL = 500 ;
40+ private int restRetries = 10 ;
41+ private int restInterval = 500 ;
4242
43- static {
44- // static block to parst environment variable overrides for REST call defaults
43+ /**
44+ * Get ARU HTTP helper instance.
45+ * @return ARU helper.
46+ */
47+ public static AruUtil rest () {
48+ if (instance == null ) {
49+ instance = new AruUtil ();
50+ }
51+ return instance ;
52+ }
53+
54+ protected AruUtil () {
4555 final String retriesEnvVar = "WLSIMG_REST_RETRY_MAX" ;
4656 final String retriesString = System .getenv (retriesEnvVar );
4757 try {
4858 if (retriesString != null ) {
49- REST_RETRIES = Integer .parseInt (retriesString );
50- if (REST_RETRIES < 1 ) {
51- REST_RETRIES = 10 ;
52- logger .severe ("IMG-0109" , retriesEnvVar , retriesString , 1 , REST_RETRIES );
59+ restRetries = Integer .parseInt (retriesString );
60+ if (restRetries < 1 ) {
61+ restRetries = 10 ;
62+ logger .severe ("IMG-0109" , retriesEnvVar , retriesString , 1 , restRetries );
5363 }
54- logger .fine ("Retry max set to {0}" , REST_RETRIES );
64+ logger .fine ("Retry max set to {0}" , restRetries );
5565 }
5666 } catch (NumberFormatException nfe ) {
5767 logger .warning ("IMG-0108" , retriesEnvVar , retriesString );
@@ -61,33 +71,18 @@ public class AruUtil {
6171 final String waitString = System .getenv (waitEnvVar );
6272 try {
6373 if (waitString != null ) {
64- REST_INTERVAL = Integer .parseInt (waitString );
65- if (REST_INTERVAL < 0 ) {
66- REST_INTERVAL = 500 ;
67- logger .severe ("IMG-0109" , waitEnvVar , waitString , 0 , REST_INTERVAL );
74+ restInterval = Integer .parseInt (waitString );
75+ if (restInterval < 0 ) {
76+ restInterval = 500 ;
77+ logger .severe ("IMG-0109" , waitEnvVar , waitString , 0 , restInterval );
6878 }
69- logger .fine ("Retry interval set to {0}" , REST_INTERVAL );
79+ logger .fine ("Retry interval set to {0}" , restInterval );
7080 }
7181 } catch (NumberFormatException nfe ) {
7282 logger .warning ("IMG-0108" , waitEnvVar , waitString );
7383 }
7484 }
7585
76- /**
77- * Get ARU HTTP helper instance.
78- * @return ARU helper.
79- */
80- public static AruUtil rest () {
81- if (instance == null ) {
82- instance = new AruUtil ();
83- }
84- return instance ;
85- }
86-
87- protected AruUtil () {
88- // hide constructor
89- }
90-
9186 /**
9287 * Get list of PSU available for each of the ARU products for the given FMW install type.
9388 *
@@ -482,24 +477,44 @@ public String downloadAruPatch(AruPatch aruPatch, String targetDir, String usern
482477 return filename ;
483478 }
484479
480+ /**
481+ * The maximum number of retries that will be attempted when trying to reach the ARU REST API method.
482+ * This value can be set by using the environment variable WLSIMG_REST_RETRY_MAX.
483+ *
484+ * @return The maximum number of retries to attempt.
485+ */
486+ public int getMaxRetries () {
487+ return restRetries ;
488+ }
489+
490+ /**
491+ * The time between each ARU REST retry.
492+ * This value can be set by using the environment variable WLSIMG_REST_RETRY_INTERVAL.
493+ *
494+ * @return The time to wait between each ARU REST API attempt during the retry loop.
495+ */
496+ public int getRetryInterval () {
497+ return restInterval ;
498+ }
499+
485500 private interface CallToRetry {
486501 Document process () throws IOException , XPathExpressionException , AruException ;
487502 }
488503
489504 // create an environment variable that can override the tries count (undocumented)
490505 private static Document retry (CallToRetry call ) throws AruException , RetryFailedException {
491- for (int i = 0 ; i < REST_RETRIES ; i ++) {
506+ for (int i = 0 ; i < rest (). getMaxRetries () ; i ++) {
492507 try {
493508 return call .process ();
494509 } catch (UnknownHostException e ) {
495510 throw new AruException (e .getLocalizedMessage (), e );
496511 } catch (IOException | XPathExpressionException e ) {
497- logger .info ("IMG-0106" , e .getMessage (), (i + 1 ), REST_RETRIES );
512+ logger .info ("IMG-0106" , e .getMessage (), (i + 1 ), rest (). getMaxRetries () );
498513 }
499514 try {
500- if (REST_INTERVAL > 0 ) {
501- logger .finer ("Waiting {0} ms before retry..." , REST_INTERVAL );
502- Thread .sleep (REST_INTERVAL );
515+ if (rest (). getRetryInterval () > 0 ) {
516+ logger .finer ("Waiting {0} ms before retry..." , rest (). getRetryInterval () );
517+ Thread .sleep (rest (). getRetryInterval () );
503518 }
504519 } catch (InterruptedException wakeAndAbort ) {
505520 logger .warning ("Process interrupted!" );
0 commit comments