1313import javax .annotation .Nullable ;
1414
1515import static com .alibaba .dcm .internal .InetAddressCacheUtilCommons .NEVER_EXPIRATION ;
16+ import static com .alibaba .dcm .internal .JavaVersionUtil .isJdkAtMost8 ;
1617
1718
1819/**
@@ -35,7 +36,7 @@ public class DnsCacheManipulator {
3536 */
3637 public static void setDnsCache (@ Nonnull String host , @ Nonnull String ... ips ) {
3738 try {
38- if (JavaVersionUtil . CURRENT_JAVA_VERSION . isLessThenOrEqual ( JavaVersion . JDK8 . getVersionNum () )) {
39+ if (isJdkAtMost8 ( )) {
3940 InetAddressCacheUtilForJdk8Minus .setInetAddressCache (host , ips , NEVER_EXPIRATION );
4041 } else {
4142 InetAddressCacheUtilForJdk9Plus .setInetAddressCache (host , ips , NEVER_EXPIRATION );
@@ -57,7 +58,7 @@ public static void setDnsCache(@Nonnull String host, @Nonnull String... ips) {
5758 */
5859 public static void setDnsCache (long expireMillis , @ Nonnull String host , @ Nonnull String ... ips ) {
5960 try {
60- if (JavaVersionUtil . CURRENT_JAVA_VERSION . isLessThenOrEqual ( JavaVersion . JDK8 . getVersionNum () )) {
61+ if (isJdkAtMost8 ( )) {
6162 InetAddressCacheUtilForJdk8Minus .setInetAddressCache (host , ips , expireMillis );
6263 } else {
6364 //need nanos to mills
@@ -143,7 +144,7 @@ public static void loadDnsCacheConfig(@Nonnull String propertiesFileName) {
143144 @ Nullable
144145 public static DnsCacheEntry getDnsCache (@ Nonnull String host ) {
145146 try {
146- if (JavaVersionUtil . CURRENT_JAVA_VERSION . isLessThenOrEqual ( JavaVersion . JDK8 . getVersionNum () )) {
147+ if (isJdkAtMost8 ( )) {
147148 return InetAddressCacheUtilForJdk8Minus .getInetAddressCache (host );
148149 } else {
149150 return InetAddressCacheUtilForJdk9Plus .getInetAddressCache (host );
@@ -177,7 +178,7 @@ public static List<DnsCacheEntry> getAllDnsCache() {
177178 @ Nonnull
178179 public static List <DnsCacheEntry > listDnsCache () {
179180 try {
180- if (JavaVersionUtil . CURRENT_JAVA_VERSION . isLessThenOrEqual ( JavaVersion . JDK8 . getVersionNum () )) {
181+ if (isJdkAtMost8 ( )) {
181182 return InetAddressCacheUtilForJdk8Minus .listInetAddressCache ().getCache ();
182183 } else {
183184 return InetAddressCacheUtilForJdk9Plus .listInetAddressCache ().getCache ();
@@ -197,7 +198,7 @@ public static List<DnsCacheEntry> listDnsCache() {
197198 @ Nonnull
198199 public static DnsCache getWholeDnsCache () {
199200 try {
200- if (JavaVersionUtil . CURRENT_JAVA_VERSION . isLessThenOrEqual ( JavaVersion . JDK8 . getVersionNum () )) {
201+ if (isJdkAtMost8 ( )) {
201202 return InetAddressCacheUtilForJdk8Minus .listInetAddressCache ();
202203 } else {
203204 return InetAddressCacheUtilForJdk9Plus .listInetAddressCache ();
@@ -216,7 +217,7 @@ public static DnsCache getWholeDnsCache() {
216217 */
217218 public static void removeDnsCache (@ Nonnull String host ) {
218219 try {
219- if (JavaVersionUtil . CURRENT_JAVA_VERSION . isLessThenOrEqual ( JavaVersion . JDK8 . getVersionNum () )) {
220+ if (isJdkAtMost8 ( )) {
220221 InetAddressCacheUtilForJdk8Minus .removeInetAddressCache (host );
221222 } else {
222223 InetAddressCacheUtilForJdk9Plus .removeInetAddressCache (host );
@@ -234,7 +235,7 @@ public static void removeDnsCache(@Nonnull String host) {
234235 */
235236 public static void clearDnsCache () {
236237 try {
237- if (JavaVersionUtil . CURRENT_JAVA_VERSION . isLessThenOrEqual ( JavaVersion . JDK8 . getVersionNum () )) {
238+ if (isJdkAtMost8 ( )) {
238239 InetAddressCacheUtilForJdk8Minus .clearInetAddressCache ();
239240 } else {
240241 InetAddressCacheUtilForJdk9Plus .clearInetAddressCache ();
0 commit comments