Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,31 @@ public class AllocateMappedFileService extends ServiceThread {
new PriorityBlockingQueue<>();
private volatile boolean hasException = false;
private DefaultMessageStore messageStore;
private PreprocessHandler preprocessHandler;

public AllocateMappedFileService(DefaultMessageStore messageStore) {
this.messageStore = messageStore;
}

/**
* Set preprocess handler for external extension
*
* @param preprocessHandler the preprocess handler
*/
public void setPreprocessHandler(PreprocessHandler preprocessHandler) {
this.preprocessHandler = preprocessHandler;
}

public MappedFile putRequestAndReturnMappedFile(String nextFilePath, String nextNextFilePath, int fileSize) {
// Execute preprocess logic if handler is set
final PreprocessHandler finalPreprocessHandler = this.preprocessHandler;
if (finalPreprocessHandler != null) {
try {
finalPreprocessHandler.preprocess(nextFilePath, nextNextFilePath, fileSize);
} catch (Throwable t) {
log.warn("Preprocess handler in AllocateMappedFileService execution failed", t);
}
}
int canSubmitRequests = 2;
if (this.messageStore.isTransientStorePoolEnable()) {
if (this.messageStore.getMessageStoreConfig().isFastFailIfNoBufferInStorePool()
Expand Down Expand Up @@ -230,6 +249,21 @@ private boolean mmapOperation() {
return true;
}

/**
* Preprocess handler interface for external extension
*/
@FunctionalInterface
public interface PreprocessHandler {
/**
* Preprocess before allocating mapped file
*
* @param nextFilePath the next file path
* @param nextNextFilePath the next next file path
* @param fileSize the file size
*/
void preprocess(String nextFilePath, String nextNextFilePath, int fileSize);
}

static class AllocateRequest implements Comparable<AllocateRequest> {
// Full file path
private String filePath;
Expand Down
Loading