-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed connector to stop reading data if there are no updates within…
… 1 second (#2) * Changed connector to stop reading data if there are no updates within 1 second * Added batching of checkpoints
- Loading branch information
1 parent
ebd18eb
commit 6214533
Showing
6 changed files
with
124 additions
and
135 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
53 changes: 53 additions & 0 deletions
53
src/main/java/com/singlestore/fivetran/connector/TimedResultSet.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,53 @@ | ||
package com.singlestore.fivetran.connector; | ||
|
||
import java.sql.ResultSet; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TimedResultSet implements AutoCloseable { | ||
|
||
private final ResultSet resultSet; | ||
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); | ||
|
||
private TimedResultSet(ResultSet resultSet) { | ||
this.resultSet = resultSet; | ||
} | ||
|
||
public static TimedResultSet from(ResultSet resultSet) { | ||
return new TimedResultSet(resultSet); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
try { | ||
executor.shutdownNow(); | ||
|
||
if (!resultSet.isClosed()) { | ||
((com.singlestore.jdbc.Connection) resultSet.getStatement() | ||
.getConnection()).cancelCurrentQuery(); | ||
} | ||
} catch (Exception ignored) { | ||
} | ||
} | ||
|
||
public ResultSet getResultSet() { | ||
return resultSet; | ||
} | ||
|
||
public Boolean next() throws InterruptedException, ExecutionException { | ||
Future<Boolean> future = executor.submit(resultSet::next); | ||
try { | ||
// Get the result with a timeout of 1 second | ||
return future.get(1, TimeUnit.SECONDS); | ||
} catch (TimeoutException e) { | ||
future.cancel(true); | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.