Repository navigation
CAMEL-25728: camel-file - keep a done file with a fixed name for the files a poll left #28035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
davsclaus
merged 2 commits into
apache:main
from
allthingssecurity:camel-file-done-file-kept-while-files-left
Oct 18, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
85 changes: 85 additions & 0 deletions
85
...ts/camel-file/src/main/java/org/apache/camel/component/file/GenericFileKeptDoneFiles.java
This file contains hidden or 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,85 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.component.file; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * The done files with a fixed name (such as {@code doneFileName=ready}) that a consumer keeps because a poll left files | ||
| * of their directory for the next poll. | ||
| * <p/> | ||
| * A file is left when the poll did not take it: beyond {@code maxMessagesPerPoll}, or its processing could not start | ||
| * (for example the read lock was not acquired). The last file of the poll then does not delete the done file, so the | ||
| * next poll consumes the files left, and any other file of the directory, as it does whenever the done file is there. A | ||
| * file that was taken and failed is not left: as before, the done file is deleted after the last file of the poll | ||
| * unless that file failed. | ||
| * <p/> | ||
| * The state is in memory and cleared when the consumer stops. | ||
| */ | ||
| final class GenericFileKeptDoneFiles { | ||
|
|
||
| private final Set<String> kept = new HashSet<>(); | ||
|
|
||
| /** | ||
| * Called once the directory is listed, before the files are consumed: forgets the done files kept by the last poll, | ||
| * as the files of this poll decide again whether they are kept. | ||
| * | ||
| * @param listedDoneFiles the done files of the files this poll found | ||
| * @param listingComplete whether every file was listed; if not (the listing stopped at the limit), a done file not | ||
| * listed is kept, as its files may be among those not listed | ||
| * @return the done files kept for files that are gone (the listing was complete and found none of | ||
| * their files), to delete | ||
| */ | ||
| synchronized List<String> startBatch(Set<String> listedDoneFiles, boolean listingComplete) { | ||
| List<String> answer = null; | ||
| if (listingComplete) { | ||
| for (String doneFileName : kept) { | ||
| if (!listedDoneFiles.contains(doneFileName)) { | ||
| if (answer == null) { | ||
| answer = new ArrayList<>(); | ||
| } | ||
| answer.add(doneFileName); | ||
| } | ||
| } | ||
| kept.clear(); | ||
| } else { | ||
| kept.removeAll(listedDoneFiles); | ||
| } | ||
| return answer; | ||
| } | ||
|
|
||
| /** | ||
| * Keeps the done file, as this poll leaves files of its directory for the next poll. | ||
| */ | ||
| synchronized void keep(String doneFileName) { | ||
| kept.add(doneFileName); | ||
| } | ||
|
|
||
| /** | ||
| * Whether the done file must be kept after the last file of the poll. | ||
| */ | ||
| synchronized boolean isKept(String doneFileName) { | ||
| return kept.contains(doneFileName); | ||
| } | ||
|
|
||
| synchronized void clear() { | ||
| kept.clear(); | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.