|
| 1 | +package com.navercorp.pinpoint.collector.config; |
| 2 | + |
| 3 | +import com.navercorp.pinpoint.collector.cluster.ClusterPoint; |
| 4 | +import com.navercorp.pinpoint.collector.cluster.ClusterPointLocator; |
| 5 | +import com.navercorp.pinpoint.collector.cluster.ClusterPointRepository; |
| 6 | +import com.navercorp.pinpoint.collector.cluster.ClusterPointRouter; |
| 7 | +import com.navercorp.pinpoint.collector.cluster.route.DefaultRouteHandler; |
| 8 | +import com.navercorp.pinpoint.collector.cluster.route.RequestEvent; |
| 9 | +import com.navercorp.pinpoint.collector.cluster.route.ResponseEvent; |
| 10 | +import com.navercorp.pinpoint.collector.cluster.route.RouteFilterChain; |
| 11 | +import com.navercorp.pinpoint.collector.cluster.route.StreamEvent; |
| 12 | +import com.navercorp.pinpoint.collector.cluster.route.StreamRouteCloseEvent; |
| 13 | +import com.navercorp.pinpoint.collector.cluster.route.StreamRouteHandler; |
| 14 | +import com.navercorp.pinpoint.collector.manage.ClusterManager; |
| 15 | +import com.navercorp.pinpoint.common.server.cluster.zookeeper.ZookeeperClusterConfiguration; |
| 16 | +import com.navercorp.pinpoint.thrift.io.DeserializerFactory; |
| 17 | +import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer; |
| 18 | +import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; |
| 19 | +import com.navercorp.pinpoint.thrift.io.SerializerFactory; |
| 20 | +import org.apache.logging.log4j.LogManager; |
| 21 | +import org.apache.logging.log4j.Logger; |
| 22 | +import org.springframework.beans.factory.annotation.Qualifier; |
| 23 | +import org.springframework.beans.factory.annotation.Value; |
| 24 | +import org.springframework.context.annotation.Bean; |
| 25 | +import org.springframework.context.annotation.Configuration; |
| 26 | + |
| 27 | +/** |
| 28 | + * @author Woonduk Kang(emeroad) |
| 29 | + */ |
| 30 | +@Configuration |
| 31 | +public class ClusterConfiguration { |
| 32 | + |
| 33 | + private final Logger logger = LogManager.getLogger(ClusterConfiguration.class); |
| 34 | + |
| 35 | + public ClusterConfiguration() { |
| 36 | + logger.info("Install {}", ClusterConfiguration.class.getSimpleName()); |
| 37 | + } |
| 38 | + |
| 39 | + @Bean |
| 40 | + public ClusterPointRepository targetClusterPointRepository() { |
| 41 | + return new ClusterPointRepository(); |
| 42 | + } |
| 43 | + |
| 44 | + @Bean |
| 45 | + public DefaultRouteHandler defaultRouteHandler( |
| 46 | + @Qualifier("targetClusterPointRepository") ClusterPointLocator<ClusterPoint<?>> targetClusterPointLocator, |
| 47 | + @Qualifier("requestFilterChain") RouteFilterChain<RequestEvent> requestFilterChain, |
| 48 | + @Qualifier("responseFilterChain") RouteFilterChain<ResponseEvent> responseFilterChain) { |
| 49 | + return new DefaultRouteHandler(targetClusterPointLocator, requestFilterChain, responseFilterChain); |
| 50 | + } |
| 51 | + |
| 52 | + @Bean |
| 53 | + public StreamRouteHandler streamRouteHandler( |
| 54 | + @Qualifier("targetClusterPointRepository") ClusterPointLocator<ClusterPoint<?>> targetClusterPointLocator, |
| 55 | + @Qualifier("streamCreateFilterChain") RouteFilterChain<StreamEvent> streamCreateFilterChain, |
| 56 | + @Qualifier("streamResponseFilterChain") RouteFilterChain<ResponseEvent> responseFilterChain, |
| 57 | + @Qualifier("streamCloseFilterChain") RouteFilterChain<StreamRouteCloseEvent> streamCloseFilterChain, |
| 58 | + @Qualifier("commandHeaderTBaseSerializerFactory") SerializerFactory<HeaderTBaseSerializer> commandSerializerFactory) { |
| 59 | + return new StreamRouteHandler(targetClusterPointLocator, streamCreateFilterChain, responseFilterChain, streamCloseFilterChain, commandSerializerFactory); |
| 60 | + } |
| 61 | + |
| 62 | + @Bean |
| 63 | + public ClusterPointRouter clusterPointRouter( |
| 64 | + @Qualifier("targetClusterPointRepository") ClusterPointRepository<ClusterPoint<?>> targetClusterPointRepository, |
| 65 | + @Qualifier("defaultRouteHandler") DefaultRouteHandler defaultRouteHandler, |
| 66 | + @Qualifier("streamRouteHandler") StreamRouteHandler streamRouteHandler, |
| 67 | + @Qualifier("commandHeaderTBaseSerializerFactory") SerializerFactory<HeaderTBaseSerializer> commandSerializerFactory, |
| 68 | + @Qualifier("commandHeaderTBaseDeserializerFactory") DeserializerFactory<HeaderTBaseDeserializer> commandDeserializerFactory) { |
| 69 | + return new ClusterPointRouter(targetClusterPointRepository, defaultRouteHandler, streamRouteHandler, commandSerializerFactory, commandDeserializerFactory); |
| 70 | + } |
| 71 | + |
| 72 | + @Bean |
| 73 | + public ClusterManager clusterManager(@Qualifier("collectorClusterConfig") CollectorClusterConfig collectorClusterConfig, |
| 74 | + ClusterPointRepository targetClusterPointRepository) { |
| 75 | + return new ClusterManager(collectorClusterConfig, targetClusterPointRepository); |
| 76 | + } |
| 77 | + |
| 78 | + |
| 79 | + @Bean |
| 80 | + public CollectorClusterConfig collectorClusterConfig( |
| 81 | + @Qualifier("clusterConfiguration") ZookeeperClusterConfiguration clusterConfiguration, |
| 82 | + @Value("${cluster.listen.ip:}") String clusterListenIp, |
| 83 | + @Value("${cluster.listen.port:-1}") int clusterListenPort) { |
| 84 | + return new CollectorClusterConfig(clusterConfiguration, clusterListenIp, clusterListenPort); |
| 85 | + } |
| 86 | +} |
0 commit comments