|
14 | 14 | package io.streamnative.pulsar.handlers.kop.storage; |
15 | 15 |
|
16 | 16 | import io.netty.channel.ChannelHandlerContext; |
17 | | -import io.netty.util.Recycler; |
18 | 17 | import io.streamnative.pulsar.handlers.kop.KafkaTopicManager; |
19 | 18 | import io.streamnative.pulsar.handlers.kop.PendingTopicFutures; |
20 | 19 | import java.util.Map; |
21 | 20 | import java.util.function.Consumer; |
| 21 | +import lombok.AllArgsConstructor; |
22 | 22 | import lombok.Getter; |
| 23 | +import lombok.extern.slf4j.Slf4j; |
23 | 24 | import org.apache.kafka.common.TopicPartition; |
24 | 25 |
|
25 | 26 | /** |
26 | 27 | * AppendRecordsContext is use for pass parameters to ReplicaManager, to avoid long parameter lists. |
27 | 28 | */ |
| 29 | +@Slf4j |
| 30 | +@AllArgsConstructor |
28 | 31 | @Getter |
29 | 32 | public class AppendRecordsContext { |
30 | | - private static final Recycler<AppendRecordsContext> RECYCLER = new Recycler<AppendRecordsContext>() { |
31 | | - protected AppendRecordsContext newObject(Handle<AppendRecordsContext> handle) { |
32 | | - return new AppendRecordsContext(handle); |
33 | | - } |
34 | | - }; |
35 | | - |
36 | | - private final Recycler.Handle<AppendRecordsContext> recyclerHandle; |
37 | 33 | private KafkaTopicManager topicManager; |
38 | 34 | private Consumer<Integer> startSendOperationForThrottling; |
39 | 35 | private Consumer<Integer> completeSendOperationForThrottling; |
40 | 36 | private Map<TopicPartition, PendingTopicFutures> pendingTopicFuturesMap; |
41 | 37 | private ChannelHandlerContext ctx; |
42 | 38 |
|
43 | | - private AppendRecordsContext(Recycler.Handle<AppendRecordsContext> recyclerHandle) { |
44 | | - this.recyclerHandle = recyclerHandle; |
45 | | - } |
46 | | - |
47 | 39 | // recycler and get for this object |
48 | 40 | public static AppendRecordsContext get(final KafkaTopicManager topicManager, |
49 | 41 | final Consumer<Integer> startSendOperationForThrottling, |
50 | 42 | final Consumer<Integer> completeSendOperationForThrottling, |
51 | 43 | final Map<TopicPartition, PendingTopicFutures> pendingTopicFuturesMap, |
52 | 44 | final ChannelHandlerContext ctx) { |
53 | | - AppendRecordsContext context = RECYCLER.get(); |
54 | | - context.topicManager = topicManager; |
55 | | - context.startSendOperationForThrottling = startSendOperationForThrottling; |
56 | | - context.completeSendOperationForThrottling = completeSendOperationForThrottling; |
57 | | - context.pendingTopicFuturesMap = pendingTopicFuturesMap; |
58 | | - context.ctx = ctx; |
59 | | - |
60 | | - return context; |
61 | | - } |
62 | | - |
63 | | - public void recycle() { |
64 | | - topicManager = null; |
65 | | - startSendOperationForThrottling = null; |
66 | | - completeSendOperationForThrottling = null; |
67 | | - pendingTopicFuturesMap = null; |
68 | | - recyclerHandle.recycle(this); |
69 | | - ctx = null; |
| 45 | + return new AppendRecordsContext(topicManager, |
| 46 | + startSendOperationForThrottling, |
| 47 | + completeSendOperationForThrottling, |
| 48 | + pendingTopicFuturesMap, |
| 49 | + ctx); |
70 | 50 | } |
71 | 51 |
|
72 | 52 | } |
0 commit comments