@@ -37,21 +37,31 @@ public class AruUtil {
37
37
38
38
private static final String BUG_SEARCH_URL = ARU_REST_URL + "/search?bug=%s" ;
39
39
40
- private static int REST_RETRIES = 10 ;
41
- private static int REST_INTERVAL = 500 ;
40
+ private int restRetries = 10 ;
41
+ private int restInterval = 500 ;
42
42
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 () {
45
55
final String retriesEnvVar = "WLSIMG_REST_RETRY_MAX" ;
46
56
final String retriesString = System .getenv (retriesEnvVar );
47
57
try {
48
58
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 );
53
63
}
54
- logger .fine ("Retry max set to {0}" , REST_RETRIES );
64
+ logger .fine ("Retry max set to {0}" , restRetries );
55
65
}
56
66
} catch (NumberFormatException nfe ) {
57
67
logger .warning ("IMG-0108" , retriesEnvVar , retriesString );
@@ -61,33 +71,18 @@ public class AruUtil {
61
71
final String waitString = System .getenv (waitEnvVar );
62
72
try {
63
73
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 );
68
78
}
69
- logger .fine ("Retry interval set to {0}" , REST_INTERVAL );
79
+ logger .fine ("Retry interval set to {0}" , restInterval );
70
80
}
71
81
} catch (NumberFormatException nfe ) {
72
82
logger .warning ("IMG-0108" , waitEnvVar , waitString );
73
83
}
74
84
}
75
85
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
-
91
86
/**
92
87
* Get list of PSU available for each of the ARU products for the given FMW install type.
93
88
*
@@ -482,24 +477,44 @@ public String downloadAruPatch(AruPatch aruPatch, String targetDir, String usern
482
477
return filename ;
483
478
}
484
479
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
+
485
500
private interface CallToRetry {
486
501
Document process () throws IOException , XPathExpressionException , AruException ;
487
502
}
488
503
489
504
// create an environment variable that can override the tries count (undocumented)
490
505
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 ++) {
492
507
try {
493
508
return call .process ();
494
509
} catch (UnknownHostException e ) {
495
510
throw new AruException (e .getLocalizedMessage (), e );
496
511
} 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 () );
498
513
}
499
514
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 () );
503
518
}
504
519
} catch (InterruptedException wakeAndAbort ) {
505
520
logger .warning ("Process interrupted!" );
0 commit comments