-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
StatDataSenderProvider.java
107 lines (91 loc) · 4.72 KB
/
StatDataSenderProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright 2018 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.profiler.context.provider;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.navercorp.pinpoint.bootstrap.config.ThriftTransportConfig;
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.common.util.Assert;
import com.navercorp.pinpoint.profiler.context.module.SpanStatClientFactory;
import com.navercorp.pinpoint.profiler.context.module.StatConverter;
import com.navercorp.pinpoint.profiler.context.thrift.BypassMessageConverter;
import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter;
import com.navercorp.pinpoint.profiler.sender.DataSender;
import com.navercorp.pinpoint.profiler.sender.MessageSerializer;
import com.navercorp.pinpoint.profiler.sender.TcpDataSender;
import com.navercorp.pinpoint.profiler.sender.ThriftMessageSerializer;
import com.navercorp.pinpoint.profiler.sender.UdpDataSenderFactory;
import com.navercorp.pinpoint.rpc.client.PinpointClientFactory;
import org.apache.thrift.TBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Taejin Koo
*/
public class StatDataSenderProvider implements Provider<DataSender> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private static final String UDP_EXECUTOR_NAME = "Pinpoint-UdpStatDataExecutor";
private final Provider<PinpointClientFactory> clientFactoryProvider;
private final String ip;
private final int port;
private final int writeQueueSize;
private final int timeout;
private final int sendBufferSize;
private final String ioType;
private final String transportType;
private final MessageConverter<TBase<?, ?>> messageConverter;
@Inject
public StatDataSenderProvider(ProfilerConfig profilerConfig, @SpanStatClientFactory Provider<PinpointClientFactory> clientFactoryProvider, @StatConverter MessageConverter<TBase<?, ?>> messageConverter) {
Assert.requireNonNull(profilerConfig, "profilerConfig must not be null");
this.clientFactoryProvider = Assert.requireNonNull(clientFactoryProvider, "clientFactoryProvider must not be null");
ThriftTransportConfig thriftTransportConfig = profilerConfig.getThriftTransportConfig();
this.ip = thriftTransportConfig.getCollectorStatServerIp();
this.port = thriftTransportConfig.getCollectorStatServerPort();
this.writeQueueSize = thriftTransportConfig.getStatDataSenderWriteQueueSize();
this.timeout = thriftTransportConfig.getStatDataSenderSocketTimeout();
this.sendBufferSize = thriftTransportConfig.getStatDataSenderSocketSendBufferSize();
this.ioType = thriftTransportConfig.getStatDataSenderSocketType();
this.transportType = thriftTransportConfig.getStatDataSenderTransportType();
this.messageConverter = messageConverter;
}
@Override
public DataSender get() {
if ("TCP".equalsIgnoreCase(transportType)) {
if ("OIO".equalsIgnoreCase(ioType)) {
logger.warn("TCP transport not support OIO type.(only support NIO)");
}
PinpointClientFactory pinpointClientFactory = clientFactoryProvider.get();
MessageSerializer<byte[]> messageSerializer = new ThriftMessageSerializer(messageConverter);
return new TcpDataSender("StatDataSender", ip, port, pinpointClientFactory, messageSerializer);
} else {
UdpDataSenderFactory factory = new UdpDataSenderFactory(ip, port, UDP_EXECUTOR_NAME, writeQueueSize, timeout, sendBufferSize, messageConverter);
return factory.create(ioType);
}
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("StatDataSenderProvider{");
sb.append("ip='").append(ip).append('\'');
sb.append(", port=").append(port);
sb.append(", writeQueueSize=").append(writeQueueSize);
sb.append(", timeout=").append(timeout);
sb.append(", sendBufferSize=").append(sendBufferSize);
sb.append(", ioType='").append(ioType).append('\'');
sb.append(", transportType='").append(transportType).append('\'');
sb.append('}');
return sb.toString();
}
}