@@ -395,7 +395,7 @@ private static boolean isBasic(OperationMode mode) {
395
395
return mode == OperationMode .BASIC ;
396
396
}
397
397
398
- /** A wrapper for the license mode and state , to allow atomically swapping. */
398
+ /** A wrapper for the license mode, state, and expiration date , to allow atomically swapping. */
399
399
private static class Status {
400
400
401
401
/** The current "mode" of the license (ie license type). */
@@ -404,7 +404,7 @@ private static class Status {
404
404
/** True if the license is active, or false if it is expired. */
405
405
final boolean active ;
406
406
407
- /** The current expiration date of the license; Long.MAX_VALUE if not avILble yet. */
407
+ /** The current expiration date of the license; Long.MAX_VALUE if not available yet. */
408
408
final long licenseExpiryDate ;
409
409
410
410
Status (OperationMode mode , boolean active , long licenseExpiryDate ) {
@@ -522,8 +522,7 @@ public boolean checkFeature(Feature feature) {
522
522
maxEpochAccumulator .accumulate (epochMillisProvider .getAsLong ());
523
523
}
524
524
525
- if (feature .minimumOperationMode .compareTo (OperationMode .BASIC ) > 0
526
- && now > status .licenseExpiryDate - GRACE_PERIOD_DURATION .getMillis ()) {
525
+ if (feature .minimumOperationMode .compareTo (OperationMode .BASIC ) > 0 && isLicenseExpiring (now )) {
527
526
HeaderWarning .addWarning ("Your license will expire in [{}] days. " +
528
527
"Contact your administrator or update your license for continued use of features" ,
529
528
TimeUnit .MILLISECONDS .toDays (status .licenseExpiryDate - now ));
@@ -645,6 +644,22 @@ public boolean isAllowedByLicense(OperationMode minimumMode, boolean needActive)
645
644
});
646
645
}
647
646
647
+ /**
648
+ * Test whether current license expires in less than {@code GRACE_PERIOD_DURATION}.
649
+ *
650
+ * @param now Current time in milliseconds
651
+ *
652
+ * @return true if current license expires in less than {@code GRACE_PERIOD_DURATION}, otherwise false
653
+ */
654
+ public boolean isLicenseExpiring (long now ) {
655
+ return checkAgainstStatus (status -> {
656
+ if (now > status .licenseExpiryDate - GRACE_PERIOD_DURATION .getMillis ()) {
657
+ return true ;
658
+ }
659
+ return false ;
660
+ });
661
+ }
662
+
648
663
/**
649
664
* A convenient method to test whether a feature is by license status.
650
665
* @see #isAllowedByLicense(OperationMode, boolean)
0 commit comments