Skip to content

Commit

Permalink
after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Smelov committed Feb 1, 2024
1 parent 3d17317 commit 335d8ae
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/main/java/com/exactpro/th2/act/ActHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ public void sendMessage(PlaceMessageRequest request, StreamObserver<SendMessageR
public void multiSendMessage(MultiSendRequest request, StreamObserver<SendMessageResponse> responseObserver) {
long startPlaceMessage = System.currentTimeMillis();
try {
var messages = request.getMessagesList();
if (messages.isEmpty()) {
throw new IllegalArgumentException("Empty message list is not allowed");
}

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Sending message request: " + shortDebugString(request));
}
Expand All @@ -283,7 +288,7 @@ public void multiSendMessage(MultiSendRequest request, StreamObserver<SendMessag
}

try {
multiSendMessage(request.getMessagesList(), parentId);
multiSendMessage(messages, parentId);
} catch (Exception ex) {
createAndStoreErrorEvent("sendMessage", ex.getMessage(), Instant.now(), parentId);
throw ex;
Expand Down Expand Up @@ -476,7 +481,7 @@ private EventID createAndStoreParentEvent(PlaceMessageRequestOrBuilder request,
com.exactpro.th2.common.grpc.Event protoEvent = event.toProto(request.getParentEventId());
//FIXME process response
try {
eventBatchMessageRouter.send(EventBatch.newBuilder().addEvents(event.toProto(request.getParentEventId())).build(), "publish", "event");
eventBatchMessageRouter.send(EventBatch.newBuilder().addEvents(event.toProto(request.getParentEventId())).build());
LOGGER.debug("createAndStoreParentEvent for {} in {} ms", actName, System.currentTimeMillis() - startTime);
return protoEvent.getId();
} catch (IOException e) {
Expand All @@ -492,12 +497,12 @@ private EventID createAndStoreParentEvent(MultiSendRequest request, String actNa
.description(request.getDescription())
.type(actName)
.status(status)
.endTimestamp(); // FIXME set properly as is in the last child
.endTimestamp();

com.exactpro.th2.common.grpc.Event protoEvent = event.toProto(request.getParentEventId());
//FIXME process response
try {
eventBatchMessageRouter.send(EventBatch.newBuilder().addEvents(event.toProto(request.getParentEventId())).build(), "publish", "event");
eventBatchMessageRouter.send(EventBatch.newBuilder().addEvents(event.toProto(request.getParentEventId())).build());
LOGGER.debug("createAndStoreParentEvent for {} in {} ms", actName, System.currentTimeMillis() - startTime);
return protoEvent.getId();
} catch (IOException e) {
Expand All @@ -517,7 +522,7 @@ private EventID createAndStoreParentEvent(SendRawMessageRequest request, String
com.exactpro.th2.common.grpc.Event protoEvent = event.toProto(request.getParentEventId());
//FIXME process response
try {
eventBatchMessageRouter.send(EventBatch.newBuilder().addEvents(event.toProto(request.getParentEventId())).build(), "publish", "event");
eventBatchMessageRouter.send(EventBatch.newBuilder().addEvents(event.toProto(request.getParentEventId())).build());
LOGGER.debug("createAndStoreParentEvent for {} in {} ms", actName, System.currentTimeMillis() - startTime);
return protoEvent.getId();
} catch (IOException e) {
Expand Down Expand Up @@ -636,19 +641,15 @@ private void sendMessage(Message message, EventID parentEventId) throws IOExcept
EventBatch eventBatch = EventBatch.newBuilder()
.addEvents(createSendMessageEvent(parsedMessage, parentEventId))
.build();
eventBatchMessageRouter.send(eventBatch, "publish", "event");
eventBatchMessageRouter.send(eventBatch);
} finally {
LOGGER.debug("Sending the message ended");
}
}

private void multiSendMessage(List<Message> messages, EventID parentEventId) throws IOException {
try {
LOGGER.debug("Sending the message started");

if (messages.isEmpty()) {
throw new IllegalArgumentException("Empty message list is not allowed");
}
LOGGER.debug("Sending the message list started");

final var firstMessageId = messages.get(0).getMetadata().getId();
final var bookName = firstMessageId.getBookName();
Expand All @@ -668,14 +669,8 @@ private void multiSendMessage(List<Message> messages, EventID parentEventId) thr
);

messageRouter.send(batch, SEND_QUEUE_ATTRIBUTE);
//TODO remove after solving issue TH2-217
//TODO process response
/* EventBatch eventBatch = EventBatch.newBuilder()
.addEvents(createSendMessageEvent(parsedMessage, parentEventId))
.build();
eventBatchMessageRouter.send(eventBatch, "publish", "event");*/
} finally {
LOGGER.debug("Sending the message ended");
LOGGER.debug("Sending the message list completed");
}
}

Expand All @@ -696,7 +691,7 @@ private void sendRawMessage(com.exactpro.th2.common.grpc.RawMessage rawMessage,
EventBatch eventBatch = EventBatch.newBuilder()
.addEvents(createSendRawMessageEvent(transportRawMessage, parentEventId))
.build();
eventBatchMessageRouter.send(eventBatch, "publish", "event");
eventBatchMessageRouter.send(eventBatch);
} finally {
LOGGER.debug("Sending the message ended");
}
Expand Down Expand Up @@ -737,7 +732,7 @@ private void storeEvent(com.exactpro.th2.common.grpc.Event eventRequest) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Try to store event: {}", toDebugMessage(eventRequest));
}
eventBatchMessageRouter.send(EventBatch.newBuilder().addEvents(eventRequest).build(), "publish", "event");
eventBatchMessageRouter.send(EventBatch.newBuilder().addEvents(eventRequest).build());
} catch (Exception e) {
LOGGER.error("Could not store event", e);
}
Expand Down

0 comments on commit 335d8ae

Please sign in to comment.