Re: A method to asynchronously LISTEN ? - Mailing list pgsql-jdbc
From | Philippe Ebersohl |
---|---|
Subject | Re: A method to asynchronously LISTEN ? |
Date | |
Msg-id | 1703112628.790711.1552297274774.JavaMail.zimbra@dalim.com Whole thread Raw |
In response to | Re: A method to asynchronously LISTEN ? (Philippe Ebersohl <philippe.ebersohl@dalim.com>) |
Responses |
Re: A method to asynchronously LISTEN ?
|
List | pgsql-jdbc |
To: "Dave Cramer" <pg@fastcrypt.com>
Cc: "David G. Johnston" <david.g.johnston@gmail.com>, "List" <pgsql-jdbc@postgresql.org>
Sent: Thursday, 28 February, 2019 10:52:44
Subject: Re: A method to asynchronously LISTEN ?
After starting the testNotify() below, we execute from pgadmin : notify mynotification
But the listener is not notified.
Did we miss something ?
public void testNotify() throws SQLException, InterruptedException {
final AtomicBoolean flag = new AtomicBoolean(false);
Statement stmt = conn.createStatement();
((org.postgresql.PGConnection)conn).addNotificationListener(new org.postgresql.PGNotificationListener() {
@Override
public void notification(org.postgresql.PGNotification notification) {
flag.set(true);
System.out.println("Notification received");
}
});
stmt.executeUpdate("LISTEN mynotification");
// stmt.executeUpdate("NOTIFY mynotification");
Thread.sleep(30000);
org.postgresql.PGNotification[] notifications = conn.unwrap(org.postgresql.PGConnection.class).getNotifications();
//assertTrue(flag.get());
//assertNotNull(notifications);
//assertEquals(1, notifications.length);
//assertEquals("mynotification", notifications[0].getName());
//long endMillis = System.currentTimeMillis();
//long runtime = endMillis - startMillis;
//assertNull("There have been notifications, although none have been expected.",notifications);
//assertTrue("We didn't wait long enough! runtime=" + runtime, runtime > 450);
stmt.close();
}
To: "Philippe Ebersohl" <philippe.ebersohl@dalim.com>
Cc: "David G. Johnston" <david.g.johnston@gmail.com>, "List" <pgsql-jdbc@postgresql.org>
Sent: Wednesday, 27 February, 2019 11:53:59
Subject: Re: A method to asynchronously LISTEN ?
Hello,I do not think there is a need for something like conn.listenSync().We were just intrigued about the test.In fact the current proposition should just work fine and we would like to test it.How could we have access to a postgresql-*.jdbc.jar that includes this feature ?Regards,Philippe
From: "David G. Johnston" <david.g.johnston@gmail.com>
To: "Dave Cramer" <pg@fastcrypt.com>
Cc: "Philippe Ebersohl" <philippe.ebersohl@dalim.com>, "List" <pgsql-jdbc@postgresql.org>
Sent: Tuesday, 26 February, 2019 22:17:12
Subject: Re: A method to asynchronously LISTEN ?On Tue, Feb 26, 2019 at 12:04 PM Dave Cramer <pg@fastcrypt.com> wrote:On Tue, 26 Feb 2019 at 12:29, David G. Johnston <david.g.johnston@gmail.com> wrote:The question being asked is whether executeUpdate method performs synchronous execution of the listener function queue during its execution.This after sending the command to the server and the server completing execution of the NOTIFY. This assumes that the server places the notification on the channel for pick-up immediately (which will not be the case within a transaction).While the client is, IIRC, synchronous, thus the local order of operations can be controlled, the server is asynchronous and thus this test is exposed to timing issues. Maybe we need something like conn.listenSync() that blocks until a notification payload is received on the connection...?kind of defeats the asynchronous aspect, no ?You'd still want an asynchronous API for people but JavaScript introduced the "async/await" feature for a reason. In this case making it "sync" instead of coding up wait loop seems desirable. That said its quite possible I'm missing some existing feature as I haven't used this API at all.David J.


pgsql-jdbc by date: