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 1h3Oo4-0001yU-0M for pgsql-jdbc@arkaria.postgresql.org; Mon, 11 Mar 2019 17:33:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h3Oo1-0004tY-SO for pgsql-jdbc@arkaria.postgresql.org; Mon, 11 Mar 2019 17:33:41 +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 1h3HR0-0000wO-CU for pgsql-jdbc@lists.postgresql.org; Mon, 11 Mar 2019 09:41:26 +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 1h3HQv-0007nj-7m for pgsql-jdbc@postgresql.org; Mon, 11 Mar 2019 09:41:23 +0000 Received: from localhost (localhost [127.0.0.1]) by mail2.dalim.com (Postfix) with ESMTP id 406E6EC008; Mon, 11 Mar 2019 10:41:17 +0100 (CET) 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 DeTJ1UJdXI1t; Mon, 11 Mar 2019 10:41:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail2.dalim.com (Postfix) with ESMTP id 26B14EC017; Mon, 11 Mar 2019 10:41:15 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail2.dalim.com 26B14EC017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalim.com; s=C5CD85AE-9875-11E7-8F4E-7B36B4C25526; t=1552297275; bh=JSXp3YtHgflxMTILeU4no5tLl8jYoRUOFn38pQW/fzw=; h=Date:From:To:Message-ID:MIME-Version; b=aaLzx8V1//vlwbVfCRlNpK0lxFxsuOJAJ7sIEGM2MXVvFqAODGPJ2JtKrLV51tcIZ Yvppfx7tCWcfgabiDrhJwgTP3xP7r/qsnldcZIsywsXaqruvmnQ0rjqd9BG5EMBgzL ZYY9bkA7keMfEqyMvn6R9KEN/AAY/gmdY+9Q1Jcc= X-Amavis-Modified: Mail body modified (using disclaimer) - mail2.dalim.com 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 8teNdmbcNvUD; Mon, 11 Mar 2019 10:41:14 +0100 (CET) Received: from mail2.dalim.com (localhost [127.0.0.1]) by mail2.dalim.com (Postfix) with ESMTP id E11CBEC008; Mon, 11 Mar 2019 10:41:14 +0100 (CET) Date: Mon, 11 Mar 2019 10:41:14 +0100 (CET) From: Philippe Ebersohl To: Dave Cramer Cc: List Message-ID: <1703112628.790711.1552297274774.JavaMail.zimbra@dalim.com> In-Reply-To: <15704019.5681554.1551347564337.JavaMail.zimbra@dalim.com> References: <1058674020.3669693.1550249725415.JavaMail.zimbra@dalim.com> <1000052273.5516163.1551264468429.JavaMail.zimbra@dalim.com> <15704019.5681554.1551347564337.JavaMail.zimbra@dalim.com> Subject: Re: A method to asynchronously LISTEN ? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_a8787b1f-0ca3-442e-865d-89f28097c2c7" X-Mailer: Zimbra 8.8.11_GA_3780 (ZimbraWebClient - SAF12 (Mac)/8.8.11_GA_3780) Thread-Topic: A method to asynchronously LISTEN ? Thread-Index: PXnlMP3RlAtj95DA+1evUDvAj0WI6+qsvKg6 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=_a8787b1f-0ca3-442e-865d-89f28097c2c7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 From: "Philippe Ebersohl" To: "Dave Cramer" Cc: "David G. Johnston" , "List" 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" To: "Philippe Ebersohl" Cc: "David G. Johnston" , "List" 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: 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 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/ ] --=_a8787b1f-0ca3-442e-865d-89f28097c2c7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Hello,
could you pleas advise what is wro= ng in our testing ?

We retrie= ved the git sources, build them.
Modified the testNotify() as sho= wn below.
When performing  "NOTIFY mynotifi= cation"  from an SQL client, w= e do not see  the "Notification received" messag= e as expected.

Thank you.

Regards,

Philippe Ebersohl 




From: "Philippe Ebersohl" <philippe.e= bersohl@dalim.com>
To: "Dave Cramer" <pg@fastcrypt.com><= br>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 ?

Hello,<= /div>
we retrieved the sources.


After starting the testNo= tify() below, we execute from pgadmin : notify mynotification

But the li= stener is not notified.

Did we miss something ?



public v= oid testNotify() throws SQLException, InterruptedException {
  = ;          final AtomicBoolean flag =3D = new AtomicBoolean(false);
         &n= bsp;  Statement stmt =3D conn.createStatement();
   =         ((org.postgresql.PGConnection)conn).= addNotificationListener(new org.postgresql.PGNotificationListener() {
&n= bsp;             @Overrid= e
              p= ublic void notification(org.postgresql.PGNotification notification) {
&n= bsp;             &nb= sp; flag.set(true);

          &nbs= p;         System.out.println("Notificat= ion received");

          =     }
          &= nbsp; });
            stmt.= executeUpdate("LISTEN mynotification");
//      = ;      stmt.executeUpdate("NOTIFY mynotification");
=
            Thread.sleep(3= 0000);
           
&nbs= p;           org.postgresql.PGNotif= ication[] notifications =3D conn.unwrap(org.postgresql.PGConnection.class).= getNotifications();
          &n= bsp; //assertTrue(flag.get());
        &nb= sp;   //assertNotNull(notifications);
     = ;       //assertEquals(1, notifications.length);            //assertEquals("= mynotification", notifications[0].getName());
     &= nbsp;      //long endMillis =3D System.currentTimeMilli= s();
            //long run= time =3D endMillis - startMillis;
        =     //assertNull("There have been notifications, although no= ne have been expected.",notifications);
      &= nbsp;     //assertTrue("We didn't wait long enough! runtime= =3D" + runtime, runtime > 450);

      &n= bsp;     stmt.close();
      &nb= sp;   }


Regards.

Philipp= e Ebersohl 



From: "Dave Cramer" <pg@fastcrypt.com>
To: "Philippe Ebersohl" = <philippe.ebersohl@dalim.com>
Cc: "David G. Johnston" <d= avid.g.johnston@gmail.com>, "List" <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 <philippe.ebersohl@dalim.com> = wrote:
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 shou= ld just work fine and we would like to test it.
How could we have access to = a postgresql-*.jdbc.jar that includes this feature ?

<= span style=3D"font-family: arial,helvetica,sans-serif;">Regards,
Philippe&nb= sp;

I just rebased it over th= e current code https://github.com/pgjdbc/pgjdbc/pull/579
Yo= u should be able to build it manually using the commandline instructions to= get the pull 

git checkout -b davecramer-notif= y master

then use maven to build it




=



From: "Dav= id 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:1= 7: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. John= ston <da= vid.g.johnston@gmail.com> wrote:
The question being asked is whether executeUpdate method = performs synchronous execution of the listener function queue during its ex= ecution.

<= /div>
This after sen= ding the command to the server and the server completing execution of the N= OTIFY.  This assumes that the server places the notification on the ch= annel for pick-up immediately (which will not be the case within a transact= ion).

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 f= or people but JavaScript introduced the "async/await" feature for a reason.=   In this case making it "sync" instead of coding up wait loop seems d= esirable.  That said its quite possible I'm missing some existing feat= ure as I haven't used this API at all.

David J.


3D"Visit


3D"Visit

= 3D"Visit=0A
= --=_a8787b1f-0ca3-442e-865d-89f28097c2c7--