Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hF4YQ-00086D-LX for pgsql-jdbc@arkaria.postgresql.org; Fri, 12 Apr 2019 22:21:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hF4YM-00058J-7V for pgsql-jdbc@arkaria.postgresql.org; Fri, 12 Apr 2019 22:21:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hF2Oe-0004WX-Ul for pgsql-jdbc@lists.postgresql.org; Fri, 12 Apr 2019 20:03:37 +0000 Received: from mail2.dalim.com ([145.253.191.74]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hF2OV-0006XK-0N for pgsql-jdbc@postgresql.org; Fri, 12 Apr 2019 20:03:34 +0000 Received: from localhost (localhost [127.0.0.1]) by mail2.dalim.com (Postfix) with ESMTP id B056AD6C68; Fri, 12 Apr 2019 22:03:22 +0200 (CEST) Received: from mail2.dalim.com ([127.0.0.1]) by localhost (mail2.dalim.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id THxZZ_CMZaF5; Fri, 12 Apr 2019 22:03:22 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail2.dalim.com (Postfix) with ESMTP id E3732EC009; Fri, 12 Apr 2019 22:03:21 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail2.dalim.com E3732EC009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalim.com; s=C5CD85AE-9875-11E7-8F4E-7B36B4C25526; t=1555099401; bh=llev1MnutBGBLJrJOfluqug4F+JigJQpX0Qkz5fP910=; h=Date:From:To:Message-ID:MIME-Version; b=PyWoVHd0hV6tSjdhOQsv+qiRUwRc0z0ftIVZbZK0vmMkd2L1E3NI7wpfHQYolCVI1 Xoglt2n322n7c+FKcFO72Jm4YBWbMiz85WqZbEry6idlgiNL4YXHbvIzghiY5n7F7H 1+Zcdfs1L9IX4A6zfI+GIwbYPNjL04SPqG9NlHAA= X-Virus-Scanned: amavisd-new at mail2.dalim.com Received: from mail2.dalim.com ([127.0.0.1]) by localhost (mail2.dalim.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id TDnkPrNaVdlt; Fri, 12 Apr 2019 22:03:21 +0200 (CEST) Received: from mail2.dalim.com (localhost [127.0.0.1]) by mail2.dalim.com (Postfix) with ESMTP id 96B1AD6C68; Fri, 12 Apr 2019 22:03:21 +0200 (CEST) Date: Fri, 12 Apr 2019 22:03:21 +0200 (CEST) From: Philippe Ebersohl To: Dave Cramer Cc: List Message-ID: <1325099851.4102688.1555099401456.JavaMail.zimbra@dalim.com> In-Reply-To: References: <1058674020.3669693.1550249725415.JavaMail.zimbra@dalim.com> <1000052273.5516163.1551264468429.JavaMail.zimbra@dalim.com> <15704019.5681554.1551347564337.JavaMail.zimbra@dalim.com> <1703112628.790711.1552297274774.JavaMail.zimbra@dalim.com> Subject: Re: A method to asynchronously LISTEN ? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_13cf5a15-e0ea-4638-b322-7883fd756946" X-Mailer: Zimbra 8.8.11_GA_3780 (ZimbraWebClient - SAF10.1 (Mac)/8.8.11_GA_3780) Thread-Topic: A method to asynchronously LISTEN ? Thread-Index: Ywek0qRdubhofe6U6XD3hfa9V8i/qw== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=_13cf5a15-e0ea-4638-b322-7883fd756946 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Thanks for the update, I forward it to the devs. Best regards, Philippe From: "Dave Cramer" To: "Philippe Ebersohl" Cc: "List" Sent: Wednesday, 10 April, 2019 16:20:39 Subject: Re: A method to asynchronously LISTEN ? Philippe, Here's what's going on. The FE/BE protocol is somewhat synchronous and the NOTIFY is not being read until some other activity occurs on the channel. If you modify your test to do the following it works fine. public void testNotify() throws SQLException, InterruptedException { AtomicBoolean flag = new AtomicBoolean( false ); Statement stmt = conn .createStatement(); ((PGConnection) conn ).addNotificationListener( new PGNotificationListener() { @Override public void notification(PGNotification notification) { System. out .println( "Notification Received" ); flag .set( true ); } }); stmt.executeUpdate( "LISTEN mynotification" ); for ( int i= 0 ;i< 30 ; i++) { stmt.execute( "select 1" ); Thread. sleep ( 1000 ); } stmt.close(); Dave Cramer [ mailto:davec@postgresintl.com | davec@postgresintl.com ] [ http://www.postgresintl.com/ | www.postgresintl.com ] On Wed, 13 Mar 2019 at 10:37, Dave Cramer < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] > wrote: On Mon, 11 Mar 2019 at 05:41, Philippe Ebersohl < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] > wrote: BQ_BEGIN Hello, could you pleas advise what is wrong in our testing ? We retrieved the git sources, build them. Modified the testNotify() as shown below. When performing "NOTIFY mynotification" from an SQL client, we do not see the " Notification received" message as expected. Thank you. Regards, Philippe Ebersohl Hello Phillipe, I will look at this as soon as possible. I am currently busy with other things. Dave Cramer [ mailto:davec@postgresintl.com | davec@postgresintl.com ] [ http://www.postgresintl.com/ | www.postgresintl.com ] BQ_BEGIN From: "Philippe Ebersohl" < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] > To: "Dave Cramer" < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] > Cc: "David G. Johnston" < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] >, "List" < [ mailto:pgsql-jdbc@postgresql.org | pgsql-jdbc@postgresql.org ] > Sent: Thursday, 28 February, 2019 10:52:44 Subject: Re: A method to asynchronously LISTEN ? Hello, we retrieved the sources. 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(); } Regards. Philippe Ebersohl From: "Dave Cramer" < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] > To: "Philippe Ebersohl" < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] > Cc: "David G. Johnston" < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] >, "List" < [ mailto:pgsql-jdbc@postgresql.org | pgsql-jdbc@postgresql.org ] > Sent: Wednesday, 27 February, 2019 11:53:59 Subject: Re: A method to asynchronously LISTEN ? On Wed, 27 Feb 2019 at 05:47, Philippe Ebersohl < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] > wrote: BQ_BEGIN 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 BQ_END I just rebased it over the current code [ https://github.com/pgjdbc/pgjdbc/pull/579 | https://github.com/pgjdbc/pgjdbc/pull/579 ] You should be able to build it manually using the commandline instructions to get the pull git checkout -b davecramer-notify master git pull [ https://github.com/davecramer/pgjdbc.git | https://github.com/davecramer/pgjdbc.git ] notify then use maven to build it Dave Cramer [ mailto:davec@postgresintl.com | davec@postgresintl.com ] [ http://www.postgresintl.com/ | www.postgresintl.com ] BQ_BEGIN From: "David G. Johnston" < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] > To: "Dave Cramer" < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] > Cc: "Philippe Ebersohl" < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] >, "List" < [ mailto:pgsql-jdbc@postgresql.org | 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 < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] > wrote: BQ_BEGIN On Tue, 26 Feb 2019 at 12:29, David G. Johnston < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] > wrote: BQ_BEGIN 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...? BQ_END kind of defeats the asynchronous aspect, no ? BQ_BEGIN BQ_BEGIN BQ_BEGIN BQ_END BQ_END BQ_END BQ_END 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. [ https://euroduo.dalim.com/ ] BQ_END [ https://euroduo.dalim.com/ ] [ https://euroduo.dalim.com/ ] BQ_END BQ_END --=_13cf5a15-e0ea-4638-b322-7883fd756946 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thanks for the update, I forward it to the devs.

Best regards,
Philippe

From: "Dave Cramer" <pg@fastcrypt.= com>
To: "Philippe Ebersohl" <philippe.ebersohl@dalim.com&g= t;
Cc: "List" <pgsql-jdbc@postgresql.org>
Sent: W= ednesday, 10 April, 2019 16:20:39
Subject: Re: A method to asynch= ronously LISTEN ?

Philippe,
Here's what's going on. The FE/BE pr= otocol is somewhat synchronous and the NOTIFY is not being read until some = other activity occurs on the channel.

If you modify your test= to do the following it works fine.

public void testNotify() throws SQLException, InterruptedException {=

AtomicBoolean flag =3D new AtomicBoolean(false);
Statement stmt =3D conn.createStatement();
((PGCo= nnection)conn= ).addNotificationListener(new PGNotificationListener() {
@Override
= public void notification(PGNotification notification) {
System.out.p= rintln("Notification Re= ceived");
flag.set(true); }
});
stmt.executeUpdate("LISTEN mynotification");
for (int i=3D0;i<30; i++) {
= stmt.execute("sel= ect 1");
Thread.sleep(1000);
}
stmt.close();

On Wed, 13 Mar 2019 at 10:37, Dave Cramer <pg@fastcrypt.com> wrote:


On Mon, 11 Mar 2019 at 05:41, Philippe Ebersohl <philippe.ebersohl@dalim.c= om> wrote:
Hello,
could you pleas advise what is wrong in our testing = ?

We retrieved the git sources, build them.
Modifie= d the testNotify() as shown below.
When performing  "NOTIFY&= nbsp;mynotification"  from an SQL client, we do not see  the "Notification received" message as expected.

Thank you.

Reg= ards,

Philippe Ebersohl 

=

Hello Phillipe,

I will look at this= as soon as possible. I am currently busy with other things.

=
Da= ve Cramer

davec@postgresintl.com

 



From: "Philippe Ebersohl" <philippe.ebersohl@dalim.com&g= t;
To: "Dave Cramer" <pg@fastcrypt.com>
Cc: "David G. Johnston" &l= t;david.g.j= ohnston@gmail.com>, "List" <pgsql-jdbc@postgresql.org>
Sent: Thursday, 28 February, 2019 10:52:44
Subject: Re: A method to as= ynchronously LISTEN ?

Hello,
we retrieved the s= ources.


After starting the testNotify() below, we execute from pgadmi= n : notify mynotification

But the listener is not notified.

Did we miss somethin= g ?



public void testNotify() throws SQLException, InterruptedException= {
            final Atomic= Boolean flag =3D new AtomicBoolean(false);
     &nbs= p;      Statement stmt =3D conn.createStatement();
&= nbsp;           ((org.postgresql.PG= Connection)conn).addNotificationListener(new org.postgresql.PGNotificationL= istener() {
           &nbs= p;  @Override
          &nb= sp;   public void notification(org.postgresql.PGNotification noti= fication) {
           &nbs= p;    flag.set(true);

        &nb= sp;           System.out.print= ln("Notification received");

        &nb= sp;     }
        &nbs= p;   });
          &nb= sp; stmt.executeUpdate("LISTEN mynotification");
//    &n= bsp;       stmt.executeUpdate("NOTIFY mynotificati= on");

            Threa= d.sleep(30000);
           =
            org.postgresq= l.PGNotification[] notifications =3D conn.unwrap(org.postgresql.PGConnectio= n.class).getNotifications();
         = ;   //assertTrue(flag.get());
      &= nbsp;     //assertNotNull(notifications);
  &nb= sp;         //assertEquals(1, notifications.l= ength);
            //asser= tEquals("mynotification", notifications[0].getName());
   = ;         //long endMillis =3D System.current= TimeMillis();
            /= /long runtime =3D endMillis - startMillis;
     &nbs= p;      //assertNull("There have been notifications, al= though none have been expected.",notifications);
    &nbs= p;       //assertTrue("We didn't wait long enough!= runtime=3D" + runtime, runtime > 450);

     =        stmt.close();
     &= nbsp;    }


Regards.

Philippe Eber= sohl 





<= div>

On Wed, 27 Feb= 2019 at 05:47, Philippe Ebersohl <philippe.ebersohl@dalim.com> wrote:
<= /div>
Hello,
I d= o 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 te= st it.
How could we have access to a postgresql-*.jdbc.jar that includes this = feature ?

Regards,
Philippe 

I just rebased it over the current code https://github.com/pgjdbc/pgjdbc= /pull/579
You should be able to build it manually using the c= ommandline instructions to get the pull 

git ch= eckout -b davecramer-notify master

then use maven to build it

<= div>
<= span style=3D"font-family:arial,helvetica,sans-serif">

=
From: "David G. Johnston" <david.g.johnston@g= mail.com>
To: "Dave Cramer" <pg@fastcrypt.com>
Cc: "Philipp= e 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:
<= div dir=3D"ltr">

On Tue, 26 Feb 2019 at 12:29, David G. Johnston <david.g.johnst= on@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 th= e NOTIFY.  This assumes that the server places the notification on the= channel for pick-up immediately (which will not be the case within a trans= action).

While the client i= s, 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 n= otification payload is received on the connection...?

kind of defeats the asynchronous aspect, no ?


You'd still want an asynchronous API for people but JavaScrip= t introduced the "async/await" feature for a reason.  In this case mak= ing it "sync" instead of coding up wait loop seems desirable.  That sa= id its quite possible I'm missing some existing feature as I haven't used t= his API at all.
=
David J.
=

3D"Visit


3D"Visit


3D"Visit

--=_13cf5a15-e0ea-4638-b322-7883fd756946--