pandaapo commented on code in PR #4650:
URL: https://github.com/apache/eventmesh/pull/4650#discussion_r1445852935
##########
eventmesh-connectors/eventmesh-connector-file/src/main/java/org/apache/eventmesh/connector/file/source/connector/FileSourceConnector.java:
##########
@@ -73,12 +93,65 @@ public String name() {
@Override
public void stop() {
-
+ try {
+ if (bufferedReader != null) {
+ bufferedReader.close();
+ }
+ } catch (Exception e) {
+ log.error("Error closing resources: {}", e.getMessage());
+ }
}
@Override
public List<ConnectRecord> poll() {
- return null;
+ List<ConnectRecord> connectRecords = new
ArrayList<>(DEFAULT_BATCH_SIZE);
+ try {
+ int bytesRead;
+ long lastOffset = 0;
+ long prevTimeStamp = 0;
+ char[] buffer = new char[1024];
+ while ((bytesRead = bufferedReader.read(buffer)) != -1) {
+ String line = new String(buffer, 0, bytesRead);
+ lastOffset += bytesRead;
+ long timeStamp = System.currentTimeMillis();
+ RecordOffset recordOffset = convertToRecordOffset(lastOffset);
+ RecordPartition recordPartition =
convertToRecordPartition(this.sourceConfig.getConnectorConfig().getTopic(),
fileName);
+ ConnectRecord connectRecord = new
ConnectRecord(recordPartition, recordOffset, timeStamp, line);
+ connectRecords.add(connectRecord);
+ if (timeStamp - prevTimeStamp >
this.sourceConfig.getConnectorConfig().getCommitOffsetIntervalMs()) {
+ this.commitOffset(connectRecord, lastOffset);
Review Comment:
The main purpose of `offSet`: Source Connector periodically persists the
latest `offSet` somewhere (such as Nacos, Consul, ETCD, etc.). Then, if Source
Connector is abruptly interrupted and restarted, it can resume reading from the
position indicated by the recorded `offSet`.
However, for file reading, relying solely on `offSet` is not feasible
because file content does not follow a linear append-only pattern. If file
modifications are considered, using `offset` is more impractical.
Therefore, in this PR, I think the codes related to `offSet` are not
meaningful.
##########
eventmesh-connectors/eventmesh-connector-file/src/main/java/org/apache/eventmesh/connector/file/source/connector/FileSourceConnector.java:
##########
@@ -23,18 +23,35 @@
import org.apache.eventmesh.openconnect.api.connector.SourceConnectorContext;
import org.apache.eventmesh.openconnect.api.source.Source;
import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
-import
org.apache.eventmesh.openconnect.offsetmgmt.api.storage.OffsetStorageReader;
-
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.RecordOffset;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.RecordPartition;
+
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class FileSourceConnector implements Source {
+ private static final int DEFAULT_BATCH_SIZE = 10;
Review Comment:
What is the role of this variable?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]