-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract command writing from the GrpcToLogStreamGateway
The GrpcToLogStreamGateway should not have to worry about any concurrency issues. By extracting the command writing to a separate class we have this logic isolated.
- Loading branch information
1 parent
acaa2a8
commit 40b73c1
Showing
3 changed files
with
55 additions
and
38 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
engine/src/main/java/io/camunda/zeebe/process/test/engine/CommandWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under | ||
* one or more contributor license agreements. See the NOTICE file distributed | ||
* with this work for additional information regarding copyright ownership. | ||
* Licensed under the Zeebe Community License 1.1. You may not use this file | ||
* except in compliance with the Zeebe Community License 1.1. | ||
*/ | ||
|
||
package io.camunda.zeebe.process.test.engine; | ||
|
||
import io.camunda.zeebe.logstreams.log.LogStreamRecordWriter; | ||
import io.camunda.zeebe.protocol.impl.record.RecordMetadata; | ||
import io.camunda.zeebe.util.buffer.BufferWriter; | ||
|
||
/** | ||
* This record is responsible for writing the commands to the {@link LogStreamRecordWriter} in a | ||
* thread-safe way. | ||
*/ | ||
record CommandWriter(LogStreamRecordWriter writer) { | ||
|
||
void writeCommandWithKey( | ||
final Long key, final BufferWriter bufferWriter, final RecordMetadata recordMetadata) { | ||
synchronized (writer) { | ||
writer.reset(); | ||
writer.key(key).metadataWriter(recordMetadata).valueWriter(bufferWriter).tryWrite(); | ||
} | ||
} | ||
|
||
void writeCommandWithoutKey( | ||
final BufferWriter bufferWriter, final RecordMetadata recordMetadata) { | ||
synchronized (writer) { | ||
writer.reset(); | ||
writer.keyNull().metadataWriter(recordMetadata).valueWriter(bufferWriter).tryWrite(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters