Skip to content

Commit

Permalink
[#noissue] Refactor DataSender
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jan 17, 2025
1 parent 8f5093b commit bca406d
Show file tree
Hide file tree
Showing 51 changed files with 205 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.navercorp.pinpoint.common.profiler.message.DataSender;
import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender;
import com.navercorp.pinpoint.loader.service.AnnotationKeyRegistryService;
import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService;
import com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService;
Expand Down Expand Up @@ -71,10 +70,10 @@ private OrderedSpanRecorder findRecorder(Injector injector) {
}

private TestDataSender findTestTcpDataSender(Injector injector) {
TypeLiteral<EnhancedDataSender<MetaDataType>> dataSenderTypeLiteral = new TypeLiteral<EnhancedDataSender<MetaDataType>>() {
TypeLiteral<DataSender<MetaDataType>> dataSenderTypeLiteral = new TypeLiteral<DataSender<MetaDataType>>() {
};
Key<EnhancedDataSender<MetaDataType>> dataSenderKey = Key.get(dataSenderTypeLiteral);
EnhancedDataSender<MetaDataType> dataSender = injector.getInstance(dataSenderKey);
Key<DataSender<MetaDataType>> dataSenderKey = Key.get(dataSenderTypeLiteral);
DataSender<MetaDataType> dataSender = injector.getInstance(dataSenderKey);
if (dataSender instanceof TestDataSender) {
return (TestDataSender) dataSender;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.navercorp.pinpoint.profiler.test;

import com.navercorp.pinpoint.common.profiler.message.AsyncDataSender;
import com.navercorp.pinpoint.common.profiler.message.DataConsumer;
import com.navercorp.pinpoint.common.profiler.message.DefaultResultResponse;
import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender;
import com.navercorp.pinpoint.common.profiler.message.ResultResponse;
import com.navercorp.pinpoint.profiler.metadata.MetaDataType;

Expand All @@ -11,18 +11,18 @@

public class AsyncDataSenderDelegator implements AsyncDataSender<MetaDataType, ResultResponse> {

private final EnhancedDataSender<MetaDataType> dataSender;
private final DataConsumer<MetaDataType> dataSender;

private final ResultResponse success = new DefaultResultResponse(true, "success");
private final ResultResponse failed = new DefaultResultResponse(false, "failed");

public AsyncDataSenderDelegator(EnhancedDataSender<MetaDataType> dataSender) {
public AsyncDataSenderDelegator(DataConsumer<MetaDataType> dataSender) {
this.dataSender = Objects.requireNonNull(dataSender, "dataSender");
}

@Override
public CompletableFuture<ResultResponse> request(MetaDataType data) {
if (this.dataSender.request(data)) {
if (this.dataSender.send(data)) {
return CompletableFuture.completedFuture(success);
} else {
return CompletableFuture.completedFuture(failed);
Expand All @@ -35,7 +35,7 @@ public boolean send(MetaDataType data) {
}

@Override
public void stop() {
public void close() {
// empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Listener<T> getListener() {
}

@Override
public void stop() {
public void close() {
}

public interface Listener<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.navercorp.pinpoint.profiler.test;

import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor;
import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender;
import com.navercorp.pinpoint.common.profiler.message.DataConsumer;
import com.navercorp.pinpoint.profiler.cache.Result;
import com.navercorp.pinpoint.profiler.cache.SimpleCache;
import com.navercorp.pinpoint.profiler.metadata.ApiMetaData;
Expand All @@ -33,10 +33,10 @@ public class MockApiMetaDataService implements ApiMetaDataService {

private final SimpleCache<String, Integer> apiCache = SimpleCache.newIdCache();

private final EnhancedDataSender<MetaDataType> enhancedDataSender;
private final DataConsumer<MetaDataType> dataSender;

public MockApiMetaDataService(EnhancedDataSender<MetaDataType> enhancedDataSender) {
this.enhancedDataSender = Objects.requireNonNull(enhancedDataSender, "enhancedDataSender");
public MockApiMetaDataService(DataConsumer<MetaDataType> dataSender) {
this.dataSender = Objects.requireNonNull(dataSender, "dataSender");
}

@Override
Expand All @@ -49,7 +49,7 @@ public int cacheApi(final MethodDescriptor methodDescriptor) {
final ApiMetaData apiMetadata = new ApiMetaData(result.getId(), methodDescriptor.getApiDescriptor(),
methodDescriptor.getLineNumber(), methodDescriptor.getType());

this.enhancedDataSender.request(apiMetadata);
this.dataSender.send(apiMetadata);

return result.getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender;
import com.navercorp.pinpoint.common.profiler.message.DataSender;
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService;
import com.navercorp.pinpoint.profiler.metadata.MetaDataType;

Expand All @@ -29,17 +29,17 @@
*/
public class MockApiMetaDataServiceProvider implements Provider<ApiMetaDataService> {

private final Provider<EnhancedDataSender<MetaDataType>> enhancedDataSenderProvider;
private final Provider<DataSender<MetaDataType>> dataSenderProvider;

@Inject
public MockApiMetaDataServiceProvider(Provider<EnhancedDataSender<MetaDataType>> enhancedDataSenderProvider) {
this.enhancedDataSenderProvider = Objects.requireNonNull(enhancedDataSenderProvider, "enhancedDataSenderProvider");
public MockApiMetaDataServiceProvider(Provider<DataSender<MetaDataType>> dataSenderProvider) {
this.dataSenderProvider = Objects.requireNonNull(dataSenderProvider, "dataSenderProvider");
}

@Override
public ApiMetaDataService get() {
final EnhancedDataSender<MetaDataType> enhancedDataSender = this.enhancedDataSenderProvider.get();
return new MockApiMetaDataService(enhancedDataSender);
final DataSender<MetaDataType> dataSender = this.dataSenderProvider.get();
return new MockApiMetaDataService(dataSender);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.inject.Module;
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.bootstrap.interceptor.registry.InterceptorRegistryAdaptor;
import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender;
import com.navercorp.pinpoint.common.profiler.message.DataSender;
import com.navercorp.pinpoint.common.profiler.message.LoggingDataSender;
import com.navercorp.pinpoint.profiler.AgentInformation;
import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext;
Expand Down Expand Up @@ -58,7 +58,7 @@ protected void configure() {

bind(AgentInformation.class).toInstance(new TestAgentInformation());
bind(StorageFactory.class).toInstance(new LogStorageFactory());
bind(EnhancedDataSender.class).toInstance(new LoggingDataSender<>());
bind(DataSender.class).toInstance(new LoggingDataSender<>());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.navercorp.pinpoint.common.profiler.message.DataSender;
import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender;
import com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataRegistryService;
import com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService;
import com.navercorp.pinpoint.profiler.context.SpanType;
Expand Down Expand Up @@ -65,10 +64,10 @@ protected void configure() {

bind(StorageFactory.class).to(TestSpanStorageFactory.class);

EnhancedDataSender<MetaDataType> enhancedDataSender = newTcpDataSender();
logger.debug("enhancedDataSender:{}", enhancedDataSender);
TypeLiteral<EnhancedDataSender<MetaDataType>> dataSenderTypeLiteral = new TypeLiteral<EnhancedDataSender<MetaDataType>>() {};
bind(dataSenderTypeLiteral).toInstance(enhancedDataSender);
DataSender<MetaDataType> metadataDataSender = newTcpDataSender();
logger.debug("metadataDataSender:{}", metadataDataSender);
TypeLiteral<DataSender<MetaDataType>> dataSenderTypeLiteral = new TypeLiteral<DataSender<MetaDataType>>() {};
bind(dataSenderTypeLiteral).toInstance(metadataDataSender);

ServerMetaDataRegistryService serverMetaDataRegistryService = newServerMetaDataRegistryService();
bind(ServerMetaDataRegistryService.class).toInstance(serverMetaDataRegistryService);
Expand All @@ -88,7 +87,7 @@ private DataSender<SpanType> newUdpSpanDataSender() {
return sender;
}

private EnhancedDataSender<MetaDataType> newTcpDataSender() {
private DataSender<MetaDataType> newTcpDataSender() {
return new TestDataSender();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.navercorp.pinpoint.profiler.test;

import com.google.common.primitives.UnsignedBytes;
import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender;
import com.navercorp.pinpoint.common.profiler.message.DataSender;
import com.navercorp.pinpoint.profiler.metadata.ApiMetaData;
import com.navercorp.pinpoint.profiler.metadata.MetaDataType;
import com.navercorp.pinpoint.profiler.metadata.SqlMetaData;
Expand All @@ -37,7 +37,7 @@
* @author Jongho Moon
* @author jaehong.kim
*/
public class TestDataSender implements EnhancedDataSender<MetaDataType> {
public class TestDataSender implements DataSender<MetaDataType> {

private final List<Object> datas = Collections.synchronizedList(new ArrayList<>());

Expand Down Expand Up @@ -132,23 +132,10 @@ private String toJavaMethodDescriptor(ApiMetaData apiMetaData) {
}

@Override
public void stop() {
public void close() {
// do nothing
}

@Override
public boolean request(MetaDataType data) {
addData(data);
return true;
}

@Override
public boolean request(MetaDataType data, int retry) {
addData(data);
return true;
}


public String getApiDescription(int id) {
return syncGet(apiIdMap, id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.inject.name.Names;
import com.navercorp.pinpoint.common.profiler.message.AsyncDataSender;
import com.navercorp.pinpoint.common.profiler.message.DataSender;
import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender;
import com.navercorp.pinpoint.common.profiler.message.ResultResponse;
import com.navercorp.pinpoint.profiler.context.SpanType;
import com.navercorp.pinpoint.profiler.context.module.AgentDataSender;
Expand Down Expand Up @@ -71,14 +70,14 @@ protected void configure() {
bind(statDataSenderKey).toInstance(statDataSender);
expose(statDataSenderKey);

EnhancedDataSender<MetaDataType> enhancedDataSender = new TestDataSender();
logger.debug("enhancedDataSender:{}", enhancedDataSender);
TypeLiteral<EnhancedDataSender<MetaDataType>> dataSenderTypeLiteral = new TypeLiteral<EnhancedDataSender<MetaDataType>>() {
DataSender<MetaDataType> testDataSender = new TestDataSender();
logger.debug("testDataSender:{}", testDataSender);
TypeLiteral<DataSender<MetaDataType>> dataSenderTypeLiteral = new TypeLiteral<DataSender<MetaDataType>>() {
};
bind(dataSenderTypeLiteral).toInstance(enhancedDataSender);
bind(dataSenderTypeLiteral).toInstance(testDataSender);
expose(dataSenderTypeLiteral);

AsyncDataSender<MetaDataType, ResultResponse> asyncDataSender = new AsyncDataSenderDelegator(enhancedDataSender);
AsyncDataSender<MetaDataType, ResultResponse> asyncDataSender = new AsyncDataSenderDelegator(testDataSender);
logger.debug("asyncDataSender:{}", asyncDataSender);
TypeLiteral<AsyncDataSender<MetaDataType, ResultResponse>> asyncDataSenderTypeLiteral = new TypeLiteral<AsyncDataSender<MetaDataType, ResultResponse>>() {
};
Expand All @@ -90,10 +89,10 @@ protected void configure() {
bind(agentDataSender).to(asyncDataSenderTypeLiteral).in(Scopes.SINGLETON);
expose(agentDataSender);

logger.debug("enhancedDataSender:{}", enhancedDataSender);
TypeLiteral<EnhancedDataSender<MetaDataType>> enhancedDataSenderTypeLiteral = new TypeLiteral<EnhancedDataSender<MetaDataType>>() {
logger.debug("testDataSender:{}", testDataSender);
TypeLiteral<DataSender<MetaDataType>> metadataDataSenderTypeLiteral = new TypeLiteral<DataSender<MetaDataType>>() {
};
Key<EnhancedDataSender<MetaDataType>> metadataDataSender = Key.get(enhancedDataSenderTypeLiteral, MetadataDataSender.class);
Key<DataSender<MetaDataType>> metadataDataSender = Key.get(metadataDataSenderTypeLiteral, MetadataDataSender.class);
bind(metadataDataSender).to(dataSenderTypeLiteral).in(Scopes.SINGLETON);
expose(metadataDataSender);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.navercorp.pinpoint.profiler.context.exception.storage;

import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender;
import com.navercorp.pinpoint.common.profiler.message.DataConsumer;
import com.navercorp.pinpoint.common.util.CollectionUtils;
import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionMetaData;
import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionMetaDataFactory;
Expand All @@ -37,12 +37,12 @@ public class BufferedExceptionStorage implements ExceptionStorage {
private static final boolean isDebug = logger.isDebugEnabled();

private final ArrayBuffer<ExceptionWrapper> buffer;
private final EnhancedDataSender<MetaDataType> dataSender;
private final DataConsumer<MetaDataType> dataSender;
private final ExceptionMetaDataFactory factory;

public BufferedExceptionStorage(
int bufferSize,
EnhancedDataSender<MetaDataType> dataSender,
DataConsumer<MetaDataType> dataSender,
ExceptionMetaDataFactory exceptionMetaDataFactory
) {
this.dataSender = Objects.requireNonNull(dataSender, "dataSender");
Expand Down Expand Up @@ -73,7 +73,7 @@ private void sendExceptionMetaData(List<ExceptionWrapper> exceptionWrappers) {
if (isDebug) {
logger.debug("Flush {}", exceptionMetaData);
}
final boolean success = this.dataSender.request(exceptionMetaData);
final boolean success = this.dataSender.send(exceptionMetaData);
if (!success) {
// Do not call exceptionMetaData.toString()
logger.debug("send fail");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.navercorp.pinpoint.profiler.context.exception.storage;

import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender;
import com.navercorp.pinpoint.common.profiler.message.DataConsumer;
import com.navercorp.pinpoint.profiler.context.exception.model.ExceptionMetaDataFactory;
import com.navercorp.pinpoint.profiler.metadata.MetaDataType;

Expand All @@ -26,10 +26,10 @@
*/
public class ExceptionStorageFactory {

private final EnhancedDataSender<MetaDataType> dataSender;
private final DataConsumer<MetaDataType> dataSender;
private final int bufferSize;

public ExceptionStorageFactory(EnhancedDataSender<MetaDataType> dataSender, int bufferSize) {
public ExceptionStorageFactory(DataConsumer<MetaDataType> dataSender, int bufferSize) {
this.dataSender = Objects.requireNonNull(dataSender, "dataSender");
this.bufferSize = bufferSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.common.profiler.message.AsyncDataSender;
import com.navercorp.pinpoint.common.profiler.message.DataSender;
import com.navercorp.pinpoint.common.profiler.message.EnhancedDataSender;
import com.navercorp.pinpoint.common.profiler.message.MessageConverter;
import com.navercorp.pinpoint.common.profiler.message.ResultResponse;
import com.navercorp.pinpoint.grpc.client.HeaderFactory;
Expand Down Expand Up @@ -174,9 +173,9 @@ private void bindAgentDataSender() {
bind(agentDataSender).toProvider(AgentGrpcDataSenderProvider.class).in(Scopes.SINGLETON);
expose(agentDataSender);

TypeLiteral<EnhancedDataSender<MetaDataType>> metaDataSenderTypeLiteral = new TypeLiteral<EnhancedDataSender<MetaDataType>>() {
TypeLiteral<DataSender<MetaDataType>> metaDataSenderTypeLiteral = new TypeLiteral<DataSender<MetaDataType>>() {
};
Key<EnhancedDataSender<MetaDataType>> metadataDataSender = Key.get(metaDataSenderTypeLiteral, MetadataDataSender.class);
Key<DataSender<MetaDataType>> metadataDataSender = Key.get(metaDataSenderTypeLiteral, MetadataDataSender.class);
bind(metadataDataSender).toProvider(MetadataGrpcDataSenderProvider.class).in(Scopes.SINGLETON);
expose(metadataDataSender);
}
Expand Down
Loading

0 comments on commit bca406d

Please sign in to comment.