Skip to content

Commit

Permalink
[pinpoint-apm#2584] TraceIdFactory dependency cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jun 5, 2017
1 parent 3012f4c commit bad8f09
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,14 @@ public MockTraceContextFactory(ProfilerConfig profilerConfig) {
final int jdbcSqlCacheSize = profilerConfig.getJdbcSqlCacheSize();
this.sqlMetaDataService = new DefaultSqlMetaDataService(agentId, agentStartTime, enhancedDataSender, jdbcSqlCacheSize);


CallStackFactory callStackFactory = new CallStackFactoryV1(64);
TraceIdFactory traceIdFactory = new DefaultTraceIdFactory(agentId, agentStartTime, idGenerator);
TraceIdFactory traceIdFactory = new DefaultTraceIdFactory(agentId, agentStartTime);
SpanFactory spanFactory = new DefaultSpanFactory(applicationName, agentId, agentStartTime, agentServiceType);

RecorderFactory recorderFactory = new DefaultRecorderFactory(stringMetaDataService, sqlMetaDataService);
TraceRootFactory traceRootFactory = newInternalTraceIdFactory(traceIdFactory, idGenerator);

final TraceFactoryProvider traceFactoryBuilder = new TraceFactoryProvider(traceRootFactory, callStackFactory, storageFactory, sampler, idGenerator, traceIdFactory, asyncIdGenerator,
final TraceFactoryProvider traceFactoryBuilder = new TraceFactoryProvider(traceRootFactory, callStackFactory, storageFactory, sampler, idGenerator, asyncIdGenerator,
Providers.of(activeTraceRepository), spanFactory, recorderFactory);
TraceFactory traceFactory = traceFactoryBuilder.get();
this.traceContext = new DefaultTraceContext(profilerConfig, agentInformation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import com.navercorp.pinpoint.bootstrap.context.TraceId;
import com.navercorp.pinpoint.bootstrap.sampler.Sampler;
import com.navercorp.pinpoint.common.annotations.InterfaceAudience;
import com.navercorp.pinpoint.common.util.Assert;
import com.navercorp.pinpoint.profiler.context.id.AsyncIdGenerator;
import com.navercorp.pinpoint.profiler.context.id.DefaultAsyncTraceId;
import com.navercorp.pinpoint.profiler.context.id.IdGenerator;
import com.navercorp.pinpoint.profiler.context.id.StatefulAsyncTraceId;
import com.navercorp.pinpoint.profiler.context.id.TraceRoot;
import com.navercorp.pinpoint.profiler.context.id.TraceRootFactory;
import com.navercorp.pinpoint.profiler.context.id.ListenableAsyncState;
import com.navercorp.pinpoint.profiler.context.id.TraceIdFactory;
import com.navercorp.pinpoint.profiler.context.recorder.RecorderFactory;
import com.navercorp.pinpoint.profiler.context.storage.AsyncStorage;
import com.navercorp.pinpoint.profiler.context.storage.Storage;
Expand All @@ -56,45 +56,18 @@ public class DefaultBaseTraceFactory implements BaseTraceFactory {
private final TraceRootFactory traceRootFactory;


public DefaultBaseTraceFactory(TraceRootFactory traceRootFactory, CallStackFactory callStackFactory, StorageFactory storageFactory, Sampler sampler, TraceIdFactory traceIdFactory, IdGenerator idGenerator, AsyncIdGenerator asyncIdGenerator,
public DefaultBaseTraceFactory(TraceRootFactory traceRootFactory, CallStackFactory callStackFactory, StorageFactory storageFactory, Sampler sampler, IdGenerator idGenerator, AsyncIdGenerator asyncIdGenerator,
SpanFactory spanFactory, RecorderFactory recorderFactory) {
if (traceRootFactory == null) {
throw new NullPointerException("traceRootFactory must not be null");
}
if (callStackFactory == null) {
throw new NullPointerException("callStackFactory must not be null");
}
if (storageFactory == null) {
throw new NullPointerException("storageFactory must not be null");
}
if (sampler == null) {
throw new NullPointerException("sampler must not be null");
}
if (idGenerator == null) {
throw new NullPointerException("idGenerator must not be null");
}
if (traceIdFactory == null) {
throw new NullPointerException("traceIdFactory must not be null");
}
if (asyncIdGenerator == null) {
throw new NullPointerException("asyncIdGenerator must not be null");
}
if (spanFactory == null) {
throw new NullPointerException("spanFactory must not be null");
}
if (recorderFactory == null) {
throw new NullPointerException("recorderFactory must not be null");
}

this.traceRootFactory = traceRootFactory;
this.callStackFactory = callStackFactory;
this.storageFactory = storageFactory;
this.sampler = sampler;
this.idGenerator = idGenerator;
this.asyncIdGenerator = asyncIdGenerator;
this.traceRootFactory = Assert.requireNonNull(traceRootFactory, "traceRootFactory must not be null");
this.callStackFactory = Assert.requireNonNull(callStackFactory, "callStackFactory must not be null");
this.storageFactory = Assert.requireNonNull(storageFactory, "storageFactory must not be null");
this.sampler = Assert.requireNonNull(sampler, "sampler must not be null");
this.idGenerator = Assert.requireNonNull(idGenerator, "idGenerator must not be null");
this.asyncIdGenerator = Assert.requireNonNull(asyncIdGenerator, "asyncIdGenerator must not be null");

this.spanFactory = spanFactory;
this.recorderFactory = recorderFactory;
this.spanFactory = Assert.requireNonNull(spanFactory, "spanFactory must not be null");
this.recorderFactory = Assert.requireNonNull(recorderFactory, "recorderFactory must not be null");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,20 @@ public class DefaultTraceIdFactory implements TraceIdFactory {

private final String agentId;
private final long agentStartTime;
private final IdGenerator idGenerator;

@Inject
public DefaultTraceIdFactory(@AgentId String agentId, @AgentStartTime long agentStartTime, IdGenerator idGenerator) {
public DefaultTraceIdFactory(@AgentId String agentId, @AgentStartTime long agentStartTime) {
if (agentId == null) {
throw new NullPointerException("agentId must not be null");
}
if (idGenerator == null) {
throw new NullPointerException("idGenerator must not be null");
}

this.agentId = agentId;
this.agentStartTime = agentStartTime;
this.idGenerator = idGenerator;

}

@Override
public TraceId newTraceId() {
final long localTransactionId = idGenerator.nextTransactionId();
public TraceId newTraceId(long localTransactionId) {
final TraceId traceId = new DefaultTraceId(agentId, agentStartTime, localTransactionId);
return traceId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public DefaultTraceRootFactory(@AgentId String agentId, TraceIdFactory traceIdFa

@Override
public TraceRoot newTraceRoot() {
final TraceId traceId = traceIdFactory.newTraceId();
final long localTransactionId = traceId.getTransactionSequence();
final long localTransactionId = idGenerator.nextTransactionId();
final TraceId traceId = traceIdFactory.newTraceId(localTransactionId);
final long startTime = traceStartTime();
return new DefaultTraceRoot(traceId, this.agentId, startTime, localTransactionId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
public interface TraceIdFactory {

TraceId newTraceId();
TraceId newTraceId(long localTransactionId);

TraceId continueTraceId(String transactionId, long parentSpanId, long spanId, short flags);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.navercorp.pinpoint.bootstrap.sampler.Sampler;
import com.navercorp.pinpoint.common.util.Assert;
import com.navercorp.pinpoint.profiler.context.id.AsyncIdGenerator;
import com.navercorp.pinpoint.profiler.context.BaseTraceFactory;
import com.navercorp.pinpoint.profiler.context.CallStackFactory;
Expand All @@ -30,7 +31,6 @@
import com.navercorp.pinpoint.profiler.context.SpanFactory;
import com.navercorp.pinpoint.profiler.context.ThreadLocalTraceFactory;
import com.navercorp.pinpoint.profiler.context.TraceFactory;
import com.navercorp.pinpoint.profiler.context.id.TraceIdFactory;
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceFactory;
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository;
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
Expand All @@ -48,7 +48,6 @@ public class TraceFactoryProvider implements Provider<TraceFactory> {
private final StorageFactory storageFactory;
private final Sampler sampler;
private final IdGenerator idGenerator;
private final TraceIdFactory traceIdFactory;
private final AsyncIdGenerator asyncIdGenerator;

private final ActiveTraceRepository activeTraceRepository;
Expand All @@ -60,57 +59,28 @@ public class TraceFactoryProvider implements Provider<TraceFactory> {


@Inject
public TraceFactoryProvider(TraceRootFactory traceRootFactory, CallStackFactory callStackFactory, StorageFactory storageFactory, Sampler sampler, IdGenerator idGenerator, TraceIdFactory traceIdFactory, AsyncIdGenerator asyncIdGenerator,
public TraceFactoryProvider(TraceRootFactory traceRootFactory, CallStackFactory callStackFactory, StorageFactory storageFactory, Sampler sampler, IdGenerator idGenerator, AsyncIdGenerator asyncIdGenerator,
Provider<ActiveTraceRepository> activeTraceRepositoryProvider, SpanFactory spanFactory, RecorderFactory recorderFactory) {
if (traceRootFactory == null) {
throw new NullPointerException("traceRootFactory must not be null");
}
if (callStackFactory == null) {
throw new NullPointerException("callStackFactory must not be null");
}
if (storageFactory == null) {
throw new NullPointerException("storageFactory must not be null");
}
if (sampler == null) {
throw new NullPointerException("sampler must not be null");
}
if (idGenerator == null) {
throw new NullPointerException("idGenerator must not be null");
}
if (traceIdFactory == null) {
throw new NullPointerException("traceIdFactory must not be null");
}
this.traceRootFactory = Assert.requireNonNull(traceRootFactory, "traceRootFactory must not be null");
this.callStackFactory = Assert.requireNonNull(callStackFactory, "callStackFactory must not be null");
this.storageFactory = Assert.requireNonNull(storageFactory, "storageFactory must not be null");
this.sampler = Assert.requireNonNull(sampler, "sampler must not be null");
this.idGenerator = Assert.requireNonNull(idGenerator, "idGenerator must not be null");
this.asyncIdGenerator = Assert.requireNonNull(asyncIdGenerator, "asyncIdGenerator must not be null");

if (asyncIdGenerator == null) {
throw new NullPointerException("asyncIdGenerator must not be null");
}
if (activeTraceRepositoryProvider == null) {
throw new NullPointerException("activeTraceRepositoryProvider must not be null");
}
if (spanFactory == null) {
throw new NullPointerException("spanFactory must not be null");
}
if (recorderFactory == null) {
throw new NullPointerException("recorderFactory must not be null");
}
this.traceRootFactory = traceRootFactory;
this.callStackFactory = callStackFactory;
this.storageFactory = storageFactory;
this.sampler = sampler;
this.idGenerator = idGenerator;
this.traceIdFactory = traceIdFactory;
this.asyncIdGenerator = asyncIdGenerator;

Assert.requireNonNull(activeTraceRepositoryProvider, "activeTraceRepositoryProvider must not be null");
this.activeTraceRepository = activeTraceRepositoryProvider.get();

this.spanFactory = spanFactory;
this.recorderFactory = recorderFactory;
this.spanFactory = Assert.requireNonNull(spanFactory, "spanFactory must not be null");
this.recorderFactory = Assert.requireNonNull(recorderFactory, "recorderFactory must not be null");

}

@Override
public TraceFactory get() {

BaseTraceFactory baseTraceFactory = new DefaultBaseTraceFactory(traceRootFactory, callStackFactory, storageFactory, sampler, traceIdFactory, idGenerator,
BaseTraceFactory baseTraceFactory = new DefaultBaseTraceFactory(traceRootFactory, callStackFactory, storageFactory, sampler, idGenerator,
asyncIdGenerator, spanFactory, recorderFactory);
if (isDebugEnabled()) {
baseTraceFactory = LoggingBaseTraceFactory.wrap(baseTraceFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ public MockTraceContextFactory(ProfilerConfig profilerConfig) {
this.sqlMetaDataService = new DefaultSqlMetaDataService(agentId, agentStartTime, enhancedDataSender, jdbcSqlCacheSize);

CallStackFactory callStackFactory = new CallStackFactoryV1(64);
TraceIdFactory traceIdFactory = new DefaultTraceIdFactory(agentId, agentStartTime, idGenerator);
TraceIdFactory traceIdFactory = new DefaultTraceIdFactory(agentId, agentStartTime);
SpanFactory spanFactory = new DefaultSpanFactory(applicationName, agentId, agentStartTime, agentServiceType);

RecorderFactory recorderFactory = new DefaultRecorderFactory(stringMetaDataService, sqlMetaDataService);
TraceRootFactory traceRootFactory = newInternalTraceIdFactory(traceIdFactory, idGenerator);

final TraceFactoryProvider traceFactoryBuilder = new TraceFactoryProvider(traceRootFactory, callStackFactory, storageFactory, sampler, idGenerator, traceIdFactory, asyncIdGenerator,
final TraceFactoryProvider traceFactoryBuilder = new TraceFactoryProvider(traceRootFactory, callStackFactory, storageFactory, sampler, idGenerator, asyncIdGenerator,
Providers.of(activeTraceRepository), spanFactory, recorderFactory);
TraceFactory traceFactory = traceFactoryBuilder.get();
this.traceContext = new DefaultTraceContext(profilerConfig, agentInformation,
Expand Down

0 comments on commit bad8f09

Please sign in to comment.