11package com .gitbitex .matchingengine ;
22
33import com .gitbitex .AppProperties ;
4- import com .gitbitex .matchingengine .command .*;
5- import com .gitbitex .matchingengine .snapshot .EngineSnapshotManager ;
4+ import com .gitbitex .matchingengine .command .Command ;
65import com .gitbitex .middleware .kafka .KafkaConsumerThread ;
76import lombok .extern .slf4j .Slf4j ;
87import org .apache .kafka .clients .consumer .ConsumerRebalanceListener ;
1716public class MatchingEngineThread extends KafkaConsumerThread <String , Command >
1817 implements ConsumerRebalanceListener {
1918 private final AppProperties appProperties ;
20- private final EngineSnapshotManager engineSnapshotManager ;
21- private final MessageSender messageSender ;
19+ private final MatchingEngineLoader matchingEngineLoader ;
2220 private MatchingEngine matchingEngine ;
2321
24- public MatchingEngineThread (KafkaConsumer <String , Command > consumer , EngineSnapshotManager engineSnapshotManager , MessageSender messageSender ,
22+ public MatchingEngineThread (KafkaConsumer <String , Command > consumer , MatchingEngineLoader matchingEngineLoader ,
2523 AppProperties appProperties ) {
2624 super (consumer , logger );
2725 this .appProperties = appProperties ;
28- this .engineSnapshotManager = engineSnapshotManager ;
29- this . messageSender = messageSender ;
26+ this .matchingEngineLoader = matchingEngineLoader ;
27+
3028 }
3129
3230 @ Override
@@ -40,7 +38,10 @@ public void onPartitionsRevoked(Collection<TopicPartition> partitions) {
4038 public void onPartitionsAssigned (Collection <TopicPartition > partitions ) {
4139 for (TopicPartition partition : partitions ) {
4240 logger .info ("partition assigned: {}" , partition .toString ());
43- matchingEngine = new MatchingEngine (engineSnapshotManager , messageSender );
41+ matchingEngine = matchingEngineLoader .getPreperedMatchingEngine ();
42+ if (matchingEngine == null ) {
43+ throw new RuntimeException ("no prepared matching engine" );
44+ }
4445 if (matchingEngine .getStartupCommandOffset () != null ) {
4546 logger .info ("seek to offset: {}" , matchingEngine .getStartupCommandOffset () + 1 );
4647 consumer .seek (partition , matchingEngine .getStartupCommandOffset () + 1 );
0 commit comments