Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SharedCommunicationObjects {
public OkHttpClient okHttpClient;
public HttpUrl agentUrl;
public Monitoring monitoring;
private DDAgentFeaturesDiscovery featuresDiscovery;
private volatile DDAgentFeaturesDiscovery featuresDiscovery;
private ConfigurationPoller configurationPoller;

public SharedCommunicationObjects() {
Expand Down Expand Up @@ -139,28 +139,34 @@ public void setFeaturesDiscovery(DDAgentFeaturesDiscovery featuresDiscovery) {
}

public DDAgentFeaturesDiscovery featuresDiscovery(Config config) {
if (featuresDiscovery == null) {
createRemaining(config);
featuresDiscovery =
new DDAgentFeaturesDiscovery(
okHttpClient,
monitoring,
agentUrl,
config.isTraceAgentV05Enabled(),
config.isTracerMetricsEnabled());

if (paused) {
// defer remote discovery until remote I/O is allowed
} else {
if (AGENT_THREAD_GROUP.equals(Thread.currentThread().getThreadGroup())) {
featuresDiscovery.discover(); // safe to run on same thread
} else {
// avoid performing blocking I/O operation on application thread
AgentTaskScheduler.INSTANCE.execute(featuresDiscovery::discover);
DDAgentFeaturesDiscovery ret = featuresDiscovery;
if (ret == null) {
synchronized (this) {
if (featuresDiscovery == null) {
createRemaining(config);
ret =
new DDAgentFeaturesDiscovery(
okHttpClient,
monitoring,
agentUrl,
config.isTraceAgentV05Enabled(),
config.isTracerMetricsEnabled());

if (paused) {
// defer remote discovery until remote I/O is allowed
} else {
if (AGENT_THREAD_GROUP.equals(Thread.currentThread().getThreadGroup())) {
ret.discover(); // safe to run on same thread
} else {
// avoid performing blocking I/O operation on application thread
AgentTaskScheduler.INSTANCE.execute(ret::discover);
}
}
featuresDiscovery = ret;
}
}
}
return featuresDiscovery;
return ret;
}

private static final class FixedConfigUrlSupplier implements Supplier<String> {
Expand Down