下面列出了com.codahale.metrics.graphite.GraphiteSender#com.codahale.metrics.graphite.PickledGraphite 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public GraphiteSender get() {
HostAndPort hostAndPort = configuration.getAddress();
String host = hostAndPort.getHost();
int port = hostAndPort.getPortOrDefault(2003);
switch (configuration.getProtocol()) {
case PICKLE:
return new PickledGraphite(
host,
port,
SocketFactory.getDefault(),
configuration.getCharset(),
configuration.getPickleBatchSize());
case TCP:
return new Graphite(host, port, SocketFactory.getDefault(), configuration.getCharset());
case UDP:
return new GraphiteUDP(host, port);
default:
throw new IllegalArgumentException("Unknown Graphite protocol \"" + configuration.getProtocol() + "\"");
}
}
@Test
public void getReturnsGraphitePickledGraphite() throws Exception {
final MetricsGraphiteReporterConfiguration configuration = new MetricsGraphiteReporterConfiguration() {
@Override
public GraphiteProtocol getProtocol() {
return GraphiteProtocol.PICKLE;
}
};
final GraphiteSenderProvider provider = new GraphiteSenderProvider(configuration);
final GraphiteSender graphiteSender = provider.get();
assertTrue(graphiteSender instanceof PickledGraphite);
assertFalse(graphiteSender.isConnected());
}