From 29004b1723d77cdc39c852388049239e6f84a1dd Mon Sep 17 00:00:00 2001 From: huaifeng Date: Tue, 30 Apr 2019 10:24:25 +0800 Subject: [PATCH 1/3] fixed provider set delay NullPointerException --- .../src/main/java/org/apache/dubbo/config/ServiceConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index 602b5d4f467..ef84cdaa626 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -360,6 +360,7 @@ private boolean shouldDelay() { if (delay == null && provider != null) { delay = provider.getDelay(); } + this.delay = delay; return delay != null && delay > 0; } From 95b394a6033e5a787e70fbdb1a3dd3b0dbc0aeb4 Mon Sep 17 00:00:00 2001 From: huaifeng Date: Tue, 30 Apr 2019 15:43:30 +0800 Subject: [PATCH 2/3] add getActualDelay method --- .../apache/dubbo/config/ServiceConfig.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index ef84cdaa626..e2a35157c4c 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -335,12 +335,24 @@ public synchronized void export() { } if (shouldDelay()) { - delayExportExecutor.schedule(this::doExport, delay, TimeUnit.MILLISECONDS); + delayExportExecutor.schedule(this::doExport, getActualDelay(), TimeUnit.MILLISECONDS); } else { doExport(); } } + /** + * Get the actual value for delay + * @return + */ + private long getActualDelay() { + Integer delay = getDelay(); + if (delay == null && provider != null) { + delay = provider.getDelay(); + } + return delay; + } + private boolean shouldExport() { Boolean shouldExport = getExport(); if (shouldExport == null && provider != null) { @@ -360,7 +372,6 @@ private boolean shouldDelay() { if (delay == null && provider != null) { delay = provider.getDelay(); } - this.delay = delay; return delay != null && delay > 0; } @@ -805,7 +816,7 @@ private void createProviderIfAbsent() { if (provider != null) { return; } - setProvider ( + setProvider( ConfigManager.getInstance() .getDefaultProvider() .orElseGet(() -> { @@ -836,15 +847,15 @@ private void convertProtocolIdsToProtocols() { if (StringUtils.isEmpty(protocolIds)) { if (CollectionUtils.isEmpty(protocols)) { - setProtocols( - ConfigManager.getInstance().getDefaultProtocols() - .filter(CollectionUtils::isNotEmpty) - .orElseGet(() -> { - ProtocolConfig protocolConfig = new ProtocolConfig(); - protocolConfig.refresh(); - return new ArrayList<>(Arrays.asList(protocolConfig)); - }) - ); + setProtocols( + ConfigManager.getInstance().getDefaultProtocols() + .filter(CollectionUtils::isNotEmpty) + .orElseGet(() -> { + ProtocolConfig protocolConfig = new ProtocolConfig(); + protocolConfig.refresh(); + return new ArrayList<>(Arrays.asList(protocolConfig)); + }) + ); } } else { String[] arr = Constants.COMMA_SPLIT_PATTERN.split(protocolIds); From e29a33eece66c50148a6af9bb6015976f1b34507 Mon Sep 17 00:00:00 2001 From: huaifeng Date: Tue, 30 Apr 2019 15:50:13 +0800 Subject: [PATCH 3/3] simple --- .../apache/dubbo/config/ServiceConfig.java | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index e2a35157c4c..ef84cdaa626 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -335,24 +335,12 @@ public synchronized void export() { } if (shouldDelay()) { - delayExportExecutor.schedule(this::doExport, getActualDelay(), TimeUnit.MILLISECONDS); + delayExportExecutor.schedule(this::doExport, delay, TimeUnit.MILLISECONDS); } else { doExport(); } } - /** - * Get the actual value for delay - * @return - */ - private long getActualDelay() { - Integer delay = getDelay(); - if (delay == null && provider != null) { - delay = provider.getDelay(); - } - return delay; - } - private boolean shouldExport() { Boolean shouldExport = getExport(); if (shouldExport == null && provider != null) { @@ -372,6 +360,7 @@ private boolean shouldDelay() { if (delay == null && provider != null) { delay = provider.getDelay(); } + this.delay = delay; return delay != null && delay > 0; } @@ -816,7 +805,7 @@ private void createProviderIfAbsent() { if (provider != null) { return; } - setProvider( + setProvider ( ConfigManager.getInstance() .getDefaultProvider() .orElseGet(() -> { @@ -847,15 +836,15 @@ private void convertProtocolIdsToProtocols() { if (StringUtils.isEmpty(protocolIds)) { if (CollectionUtils.isEmpty(protocols)) { - setProtocols( - ConfigManager.getInstance().getDefaultProtocols() - .filter(CollectionUtils::isNotEmpty) - .orElseGet(() -> { - ProtocolConfig protocolConfig = new ProtocolConfig(); - protocolConfig.refresh(); - return new ArrayList<>(Arrays.asList(protocolConfig)); - }) - ); + setProtocols( + ConfigManager.getInstance().getDefaultProtocols() + .filter(CollectionUtils::isNotEmpty) + .orElseGet(() -> { + ProtocolConfig protocolConfig = new ProtocolConfig(); + protocolConfig.refresh(); + return new ArrayList<>(Arrays.asList(protocolConfig)); + }) + ); } } else { String[] arr = Constants.COMMA_SPLIT_PATTERN.split(protocolIds);