Verified Owner
Top Description Fields Constructors Methods
org.jabref.logic.shared.notifications

public Class NotificationListener

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable
Annotations
@NullMarked
Imports
java.sql.Connection, .SQLException, org.jabref.logic.shared.DBMSSynchronizer, .DatabaseConnection, com.google.gson.Gson, .GsonBuilder, .JsonSyntaxException, org.jspecify.annotations.NullMarked, .Nullable, org.postgresql.PGConnection, .PGNotification, org.slf4j.Logger, .LoggerFactory

A listener for PostgreSQL database notifications.

Opens - and on failures reopens - its own database connection, because polling for notifications blocks the connection it runs on. Reconnecting is retried for as long as the library is open: every successful reconnect is followed by a full pull, so an outage costs nothing but delay.

Field Summary

Modifier and TypeField and Description
private volatile @Nullable Connection
private final DatabaseConnection
private final DBMSSynchronizer
private final Gson
private static final Logger
private static final long
private volatile @Nullable PGConnection
private final String
private volatile boolean

Constructor Summary

AccessConstructor and Description
public
NotificationListener(DBMSSynchronizer dbmsSynchronizer, DatabaseConnection dbmsConnection, String processorId)

Method Summary

Modifier and TypeMethod and Description
private void
private PGConnection
private void
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

public void
start()

Registers the notification subscription.

public void
stop()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionback to summary
private volatile @Nullable Connection connection
dbmsConnectionback to summary
private final DatabaseConnection dbmsConnection
dbmsSynchronizerback to summary
private final DBMSSynchronizer dbmsSynchronizer
gsonback to summary
private final Gson gson
LOGGERback to summary
private static final Logger LOGGER
MAX_RECONNECT_DELAY_MILLISback to summary
private static final long MAX_RECONNECT_DELAY_MILLIS
pgConnectionback to summary
private volatile @Nullable PGConnection pgConnection
processorIdback to summary
private final String processorId
stopback to summary
private volatile boolean stop

Constructor Detail

NotificationListenerback to summary
public NotificationListener(DBMSSynchronizer dbmsSynchronizer, DatabaseConnection dbmsConnection, String processorId)

Method Detail

closeConnectionback to summary
private void closeConnection()
connectback to summary
private PGConnection connect() throws SQLException
handleNotificationback to summary
private void handleNotification(PGNotification notification)
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
startback to summary
public void start() throws SQLException

Registers the notification subscription. Called before the polling starts, so that no notification sent right after this method returns can be missed.

stopback to summary
public void stop()