|
| 1 | +/* |
| 2 | + * Copyright 2023 NAVER Corp. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.navercorp.pinpoint.realtime.collector.atc.config; |
| 17 | + |
| 18 | +import com.navercorp.pinpoint.collector.cluster.route.StreamRouteHandler; |
| 19 | +import com.navercorp.pinpoint.realtime.ActiveThreadCountSupplyTopic; |
| 20 | +import com.navercorp.pinpoint.realtime.collector.atc.redis.ActiveThreadCountDemandListener; |
| 21 | +import com.navercorp.pinpoint.realtime.collector.atc.service.ATCRequestService; |
| 22 | +import com.navercorp.pinpoint.realtime.collector.atc.service.netty.ATCPacketDeserializer; |
| 23 | +import com.navercorp.pinpoint.realtime.collector.atc.service.netty.NettyATCRequestService; |
| 24 | +import com.navercorp.pinpoint.realtime.collector.atc.service.redis.RedisATCPublisher; |
| 25 | +import com.navercorp.pinpoint.thrift.io.DeserializerFactory; |
| 26 | +import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer; |
| 27 | +import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; |
| 28 | +import com.navercorp.pinpoint.thrift.io.SerializerFactory; |
| 29 | +import org.springframework.beans.factory.annotation.Qualifier; |
| 30 | +import org.springframework.beans.factory.annotation.Value; |
| 31 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
| 32 | +import org.springframework.context.annotation.Bean; |
| 33 | +import org.springframework.context.annotation.Configuration; |
| 34 | +import org.springframework.context.annotation.Import; |
| 35 | +import org.springframework.data.redis.connection.RedisConnectionFactory; |
| 36 | +import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
| 37 | + |
| 38 | +/** |
| 39 | + * @author youngjin.kim2 |
| 40 | + */ |
| 41 | +@Configuration |
| 42 | +@Import(RedisCollectorConfig.class) |
| 43 | +public class RealtimeCollectorConfig { |
| 44 | + |
| 45 | + @Value("${pinpoint.collector.realtime.atc.demand.maxAgeMs:12500}") |
| 46 | + long demandMaxAgeMs; |
| 47 | + |
| 48 | + @Value("${pinpoint.collector.realtime.atc.throttle.termMillis:100}") |
| 49 | + long throttleTermMillis; |
| 50 | + |
| 51 | + @Bean |
| 52 | + @ConditionalOnBean(RedisConnectionFactory.class) |
| 53 | + ActiveThreadCountSupplyTopic activeThreadCountSupplyTopic(RedisConnectionFactory redisConnectionFactory) { |
| 54 | + return new ActiveThreadCountSupplyTopic(redisConnectionFactory); |
| 55 | + } |
| 56 | + |
| 57 | + @Bean |
| 58 | + @ConditionalOnBean(ActiveThreadCountSupplyTopic.class) |
| 59 | + RedisATCPublisher redisActiveThreadCountPublisher(ActiveThreadCountSupplyTopic topic) { |
| 60 | + return new RedisATCPublisher(topic, throttleTermMillis); |
| 61 | + } |
| 62 | + |
| 63 | + @Bean |
| 64 | + @ConditionalOnBean(name = "commandHeaderTBaseDeserializerFactory") |
| 65 | + ATCPacketDeserializer atcPacketDeserializer( |
| 66 | + @Qualifier("commandHeaderTBaseDeserializerFactory") |
| 67 | + DeserializerFactory<HeaderTBaseDeserializer> deserializerFactory |
| 68 | + ) { |
| 69 | + return new ATCPacketDeserializer(deserializerFactory); |
| 70 | + } |
| 71 | + |
| 72 | + @Bean |
| 73 | + @ConditionalOnBean(value = { StreamRouteHandler.class }, name = "commandHeaderTBaseSerializerFactory") |
| 74 | + ATCRequestService atcService( |
| 75 | + StreamRouteHandler streamRouteHandler, |
| 76 | + @Qualifier("commandHeaderTBaseSerializerFactory") |
| 77 | + SerializerFactory<HeaderTBaseSerializer> serializerFactory, |
| 78 | + ATCPacketDeserializer deserializer |
| 79 | + ) { |
| 80 | + return new NettyATCRequestService(streamRouteHandler, serializerFactory, deserializer); |
| 81 | + } |
| 82 | + |
| 83 | + @Bean |
| 84 | + @ConditionalOnBean({ RedisMessageListenerContainer.class }) |
| 85 | + ActiveThreadCountDemandListener activeThreadCountDemandListener( |
| 86 | + RedisMessageListenerContainer container, |
| 87 | + ATCRequestService atcRequestService, |
| 88 | + RedisATCPublisher publisher |
| 89 | + ) { |
| 90 | + return new ActiveThreadCountDemandListener(container, atcRequestService, publisher, demandMaxAgeMs); |
| 91 | + } |
| 92 | + |
| 93 | +} |
0 commit comments