25
25
import java .util .List ;
26
26
import java .util .UUID ;
27
27
import java .util .concurrent .CompletableFuture ;
28
+ import java .util .concurrent .ExecutionException ;
28
29
import java .util .concurrent .Executor ;
29
30
import java .util .stream .Collectors ;
30
31
@@ -37,6 +38,8 @@ public final class BackEnd extends AbstractBehavior<BackEnd.Request> {
37
38
private static final Logger LOGGER = LogManager .getLogger (BackEnd .class );
38
39
private static final String SINGLE_TIMER_TIMEOUT_KEY = "SingleTimerTimeOutKey" ;
39
40
static MyKafkaProducer <String , Notification > topicNotifications ;
41
+
42
+ static MyKafkaProducer <String , InteractionEnvelop > matchingInteractions ;
40
43
private final Executor ec ;
41
44
private LibMPI libMPI = null ;
42
45
@@ -52,6 +55,12 @@ private BackEnd(final ActorContext<Request> context) {
52
55
new StringSerializer (),
53
56
new JsonPojoSerializer <>(),
54
57
AppConfig .KAFKA_CLIENT_ID_NOTIFICATIONS );
58
+
59
+ matchingInteractions = new MyKafkaProducer <>(AppConfig .KAFKA_BOOTSTRAP_SERVERS ,
60
+ GlobalConstants .TOPIC_INTERACTION_LINKER_MATCHING ,
61
+ new StringSerializer (),
62
+ new JsonPojoSerializer <>(),
63
+ AppConfig .KAFKA_CLIENT_ID_NOTIFICATIONS );
55
64
}
56
65
57
66
private BackEnd (
@@ -144,9 +153,11 @@ private Behavior<Request> crUpdateField(final CrUpdateFieldRequest req) {
144
153
return Behaviors .same ();
145
154
}
146
155
147
- private Behavior <Request > runStartStopHooks (final RunStartStopHooksRequest req ) {
156
+ private Behavior <Request > runStartStopHooks (final RunStartStopHooksRequest req ) throws ExecutionException , InterruptedException {
148
157
List <MpiGeneralError > hookRunErrors = List .of ();
149
158
159
+ matchingInteractions .produceSync (req .key , req .batchInteraction );
160
+
150
161
if (req .batchInteraction .contentType () == BATCH_START_SENTINEL ) {
151
162
hookRunErrors = libMPI .beforeLinkingHook ();
152
163
} else if (req .batchInteraction .contentType () == BATCH_END_SENTINEL ) {
@@ -172,7 +183,8 @@ private Behavior<Request> syncLinkInteractionHandler(final SyncLinkInteractionRe
172
183
request .link .matchThreshold () == null
173
184
? AppConfig .LINKER_MATCH_THRESHOLD
174
185
: request .link .matchThreshold (),
175
- request .link .stan ());
186
+ request .link .stan (),
187
+ null );
176
188
request .replyTo .tell (new SyncLinkInteractionResponse (request .link .stan (),
177
189
listLinkInfo .isLeft ()
178
190
? listLinkInfo .getLeft ()
@@ -183,20 +195,30 @@ private Behavior<Request> syncLinkInteractionHandler(final SyncLinkInteractionRe
183
195
return Behaviors .same ();
184
196
}
185
197
186
- private Behavior <Request > asyncLinkInteractionHandler (final AsyncLinkInteractionRequest req ) {
198
+ private Behavior <Request > asyncLinkInteractionHandler (final AsyncLinkInteractionRequest req ) throws ExecutionException , InterruptedException {
187
199
if (req .batchInteraction .contentType () != InteractionEnvelop .ContentType .BATCH_INTERACTION ) {
188
200
return Behaviors .withTimers (timers -> {
189
201
timers .startSingleTimer (SINGLE_TIMER_TIMEOUT_KEY , TeaTimeRequest .INSTANCE , Duration .ofSeconds (5 ));
190
202
req .replyTo .tell (new AsyncLinkInteractionResponse (null ));
191
203
return Behaviors .same ();
192
204
});
193
205
}
206
+
194
207
final var linkInfo =
195
208
LinkerDWH .linkInteraction (libMPI ,
196
209
req .batchInteraction .interaction (),
197
210
null ,
198
211
AppConfig .LINKER_MATCH_THRESHOLD ,
199
- req .batchInteraction .stan ());
212
+ req .batchInteraction .stan (),
213
+ (final Interaction interaction ) -> {
214
+ try {
215
+ BackEnd .matchingInteractions .produceSync (req .key , req .batchInteraction );
216
+ } catch (ExecutionException e ) {
217
+ throw new RuntimeException (e );
218
+ } catch (InterruptedException e ) {
219
+ throw new RuntimeException (e );
220
+ }
221
+ });
200
222
if (linkInfo .isLeft ()) {
201
223
req .replyTo .tell (new AsyncLinkInteractionResponse (linkInfo .getLeft ()));
202
224
} else {
0 commit comments