pandaapo commented on code in PR #4650:
URL: https://github.com/apache/eventmesh/pull/4650#discussion_r1448568552


##########
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:
   Through this 
[explanation](https://github.com/apache/eventmesh/pull/4650#discussion_r1445852935),
 I believe you understand the functionality of `offSet` now. If you strongly 
wish to utilize `RecordPartition` or `RecordOffset` to implement the 
functionality of `offSet`, you can share your proposed approach here first.
   
   Assuming this is the content of a file, and Source Connector starts reading 
from "A" and stops when it reaches "K". 
   ```
   ABCDEDFG,
   HIJKLMN,
   OPQRST.
   ```
   Your approach needs to consider some scenarios, such as:
   (1) After restarting Source Connector, how can it start reading from "L"?
   
   (2) Before Source Connector is restarted, the content of the file is 
modified as follows. How should it be appropriately handled after restarting 
Source Connector? read from "L", "A" or other position?
   ```
   ABCDEDFG 123456,
   HIJKLMN,
   OPQRST.
   ```
   or
   ```
   ABC,
   HIJKLMN,
   OPQRST.
   ```



-- 
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]

Reply via email to