-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Switch to org.postgresql #4031
Switch to org.postgresql #4031
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,50 @@ | ||
package org.jabref.logic.shared.listener; | ||
|
||
import java.sql.SQLException; | ||
|
||
import org.jabref.logic.shared.DBMSProcessor; | ||
import org.jabref.logic.shared.DBMSSynchronizer; | ||
|
||
import com.impossibl.postgres.api.jdbc.PGNotificationListener; | ||
import org.postgresql.PGConnection; | ||
import org.postgresql.PGNotification; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* A listener for PostgreSQL database notifications. | ||
*/ | ||
public class PostgresSQLNotificationListener implements PGNotificationListener { | ||
public class PostgresSQLNotificationListener extends Thread { | ||
|
||
private final DBMSSynchronizer dbmsSynchronizer; | ||
private static final Logger LOGGER = LoggerFactory.getLogger(PostgresSQLNotificationListener.class); | ||
|
||
private final DBMSSynchronizer dbmsSynchronizer; | ||
private final PGConnection pgConnection; | ||
|
||
public PostgresSQLNotificationListener(DBMSSynchronizer dbmsSynchronizer) { | ||
public PostgresSQLNotificationListener(DBMSSynchronizer dbmsSynchronizer, PGConnection pgConnection) { | ||
this.dbmsSynchronizer = dbmsSynchronizer; | ||
this.pgConnection = pgConnection; | ||
} | ||
|
||
@Override | ||
public void notification(int processId, String channel, String payload) { | ||
if (!payload.equals(DBMSProcessor.PROCESSOR_ID)) { | ||
dbmsSynchronizer.pullChanges(); | ||
public void run() { | ||
try { | ||
//noinspection InfiniteLoopStatement | ||
while (true) { | ||
PGNotification notifications[] = pgConnection.getNotifications(); | ||
|
||
if (notifications != null) { | ||
for (PGNotification notification : notifications) { | ||
if (!notification.getName().equals(DBMSProcessor.PROCESSOR_ID)) { | ||
dbmsSynchronizer.pullChanges(); | ||
} | ||
} | ||
} | ||
|
||
// Wait a while before checking again for new notifications | ||
Thread.sleep(500); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't the driver support push notifications? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Frm the official doc it supports it: |
||
} | ||
} catch (SQLException | InterruptedException exception) { | ||
LOGGER.error("Error while listening for updates to PostgresSQL", exception); | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the above comment, which contradicts the new code.
Has someone tested the new implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try to test it this evening. I think I have a pg sql db somewhere lying around