-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aindriu Lavelle <aindriu.lavelle@aiven.io>
- Loading branch information
1 parent
1d74693
commit 1bc8ce6
Showing
12 changed files
with
173 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
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
72 changes: 72 additions & 0 deletions
72
s3-source-connector/src/main/java/io/aiven/kafka/connect/s3/source/utils/RingBuffer.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,72 @@ | ||
/* | ||
* Copyright 2025 Aiven Oy | ||
* | ||
* Licensed 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 io.aiven.kafka.connect.s3.source.utils; | ||
|
||
import java.util.Collection; | ||
|
||
import org.apache.commons.collections.buffer.CircularFifoBuffer; | ||
|
||
public class RingBuffer { | ||
final private CircularFifoBuffer list; | ||
|
||
/** | ||
* Create a Ring Buffer of a maximum Size | ||
* | ||
* @param size | ||
* The size that the linked list should be. | ||
*/ | ||
public RingBuffer(final int size) { | ||
this.list = new CircularFifoBuffer(size); | ||
} | ||
|
||
/** | ||
* Create a Ring Buffer from an existing collection | ||
* | ||
* @param collection | ||
* An existing collection of values | ||
*/ | ||
public RingBuffer(final Collection<Object> collection) { | ||
this.list = new CircularFifoBuffer(collection); | ||
} | ||
|
||
/** | ||
* Add a new item if it is not already present in the ring buffer to the ring buffer and removes the last entry from | ||
* the linked list. Null values are ignored. | ||
* | ||
* @param item | ||
* Item T which is to be added to the Queue | ||
*/ | ||
public void enqueue(final Object item) { | ||
if (item != null) { | ||
list.add(item); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Get the last value in the Ring buffer | ||
* | ||
* @return A value T from the last place in the list, returns null if list is not full. | ||
*/ | ||
public String getLast() { | ||
return list.isFull() ? (String) list.get() : null; | ||
} | ||
|
||
public boolean contains(final Object item) { | ||
return list.contains(item); | ||
} | ||
} |
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
Oops, something went wrong.