-
Notifications
You must be signed in to change notification settings - Fork 26.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add delay export test case #3447
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ | |
import org.apache.dubbo.common.utils.ConfigUtils; | ||
import org.apache.dubbo.common.utils.NamedThreadFactory; | ||
import org.apache.dubbo.common.utils.StringUtils; | ||
import org.apache.dubbo.common.utils.CollectionUtils; | ||
import org.apache.dubbo.config.annotation.Service; | ||
import org.apache.dubbo.config.context.ConfigManager; | ||
import org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker; | ||
|
@@ -56,8 +55,6 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.apache.dubbo.common.Constants.LOCALHOST_VALUE; | ||
|
@@ -102,11 +99,6 @@ public class ServiceConfig<T> extends AbstractServiceConfig { | |
*/ | ||
private static final Map<String, Integer> RANDOM_PORT_MAP = new HashMap<String, Integer>(); | ||
|
||
/** | ||
* A delayed exposure service timer | ||
*/ | ||
private static final ScheduledExecutorService delayExportExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("DubboServiceDelayExporter", true)); | ||
|
||
/** | ||
* The urls of the services exported | ||
*/ | ||
|
@@ -341,7 +333,15 @@ public synchronized void export() { | |
} | ||
|
||
if (delay != null && delay > 0) { | ||
delayExportExecutor.schedule(this::doExport, delay, TimeUnit.MILLISECONDS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes,This is another way to fix this . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
you are right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes. |
||
new NamedThreadFactory("DubboServiceDelayExporter", true).newThread(() -> { | ||
try { | ||
logger.info("Dubbo service " + interfaceClass.getName() + " will delay export for " + delay + " ms"); | ||
TimeUnit.MILLISECONDS.sleep(delay); | ||
doExport(); | ||
} catch (InterruptedException e) { | ||
logger.error("Expected error occured when export " + interfaceClass.getName(), e); | ||
} | ||
}).start(); | ||
} else { | ||
doExport(); | ||
} | ||
|
@@ -779,7 +779,7 @@ private void createProviderIfAbsent() { | |
if (provider != null) { | ||
return; | ||
} | ||
setProvider ( | ||
setProvider( | ||
ConfigManager.getInstance() | ||
.getDefaultProvider() | ||
.orElseGet(() -> { | ||
|
@@ -810,15 +810,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 Arrays.asList(protocolConfig); | ||
}) | ||
); | ||
setProtocols( | ||
ConfigManager.getInstance().getDefaultProtocols() | ||
.filter(CollectionUtils::isNotEmpty) | ||
.orElseGet(() -> { | ||
ProtocolConfig protocolConfig = new ProtocolConfig(); | ||
protocolConfig.refresh(); | ||
return Arrays.asList(protocolConfig); | ||
}) | ||
); | ||
} | ||
} else { | ||
String[] arr = Constants.COMMA_SPLIT_PATTERN.split(protocolIds); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this delayExportExecutor is a global delay exposed component. I don't think we can delete this field.
Since
ServiceConfig
exists, we can export the service at runtime, so we can't determine ifdelayExportExecutor
will still be used. In addition, maintaining an object in memory does not have a big impact.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree with @carryxyh , all ServiceConfig holds the same delayExportExecutor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My fault, I didn't notice that it was static.