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 1gzIpt-000217-Th for pgsql-jdbc@arkaria.postgresql.org; Thu, 28 Feb 2019 10:22:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gzIps-0007Fh-EK for pgsql-jdbc@arkaria.postgresql.org; Thu, 28 Feb 2019 10:22:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzINu-0007GO-IF for pgsql-jdbc@lists.postgresql.org; Thu, 28 Feb 2019 09:53:46 +0000 Received: from mail2.dalim.com ([145.253.191.74]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzINh-0005yg-WF for pgsql-jdbc@postgresql.org; Thu, 28 Feb 2019 09:53:36 +0000 Received: from localhost (localhost [127.0.0.1]) by mail2.dalim.com (Postfix) with ESMTP id BF95F16601E; Thu, 28 Feb 2019 10:52:45 +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 rGtsWwYi2mq8; Thu, 28 Feb 2019 10:52:44 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail2.dalim.com (Postfix) with ESMTP id B6CCB166022; Thu, 28 Feb 2019 10:52:44 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.9.2 mail2.dalim.com B6CCB166022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalim.com; s=C5CD85AE-9875-11E7-8F4E-7B36B4C25526; t=1551347564; bh=yttfZKO5/teyfSEZ7gKQMkfCmvNrFpugSIXfyGUIVWE=; h=Date:From:To:Message-ID:Subject:MIME-Version:Content-Type; b=Xc4K/mLXt1YwgVoFM8UswF2QjbN4GMNSxxWRYBbQSHiD8pvp5E0EAQp2aExiLFOAU E5pG8RIJkGxtm97UtSyIy6bQ1MPFCTKSJDtSuZPBzeU5KsgY3lG6EF2VGns1BFWB95 X/bplNGrUpP8o6IcdyfNifHrrMoCJqcsrBkLRLzc= X-Amavis-Modified: Mail body modified (using disclaimer) - mail2.dalim.com X-Virus-Scanned: amavisd-new at 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 tJRudPlg24wO; Thu, 28 Feb 2019 10:52:44 +0100 (CET) Received: from mail2.dalim.com (localhost [127.0.0.1]) by mail2.dalim.com (Postfix) with ESMTP id 780C816601B; Thu, 28 Feb 2019 10:52:44 +0100 (CET) Date: Thu, 28 Feb 2019 10:52:44 +0100 (CET) From: Philippe Ebersohl To: Dave Cramer Cc: "David G. Johnston" , List Message-ID: <15704019.5681554.1551347564337.JavaMail.zimbra@dalim.com> In-Reply-To: References: <1058674020.3669693.1550249725415.JavaMail.zimbra@dalim.com> <1855336325.5176233.1551086100885.JavaMail.zimbra@dalim.com> <1000052273.5516163.1551264468429.JavaMail.zimbra@dalim.com> Subject: Re: A method to asynchronously LISTEN ? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_5681553_1597214443.1551347564336" X-Mailer: Zimbra 8.6.0_GA_1153 (ZimbraWebClient - SAF12 (Mac)/8.6.0_GA_1153) Thread-Topic: A method to asynchronously LISTEN ? Thread-Index: PXnlMP3RlAtj95DA+1evUDvAj0WI6w== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_5681553_1597214443.1551347564336 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 < 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 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 notify then use maven to build it Dave Cramer davec@postgresintl.com www.postgresintl.com BQ_BEGIN 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: BQ_BEGIN On Tue, 26 Feb 2019 at 12:29, David G. Johnston < 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. BQ_END ------=_Part_5681553_1597214443.1551347564336 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
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 testNot= ify() throws SQLException, InterruptedException {
    &nb= sp;       final AtomicBoolean flag =3D new AtomicB= oolean(false);
            = Statement stmt =3D conn.createStatement();
     &nbs= p;      ((org.postgresql.PGConnection)conn).addNotifica= tionListener(new org.postgresql.PGNotificationListener() {
  &= nbsp;           @Override
 =              public void = notification(org.postgresql.PGNotification notification) {
  &= nbsp;             flag.se= t(true);

            &nbs= p;       System.out.println("Notification rec= eived");

          &nb= sp;   }
          &nbs= p; });
            stmt.exe= cuteUpdate("LISTEN mynotification");
//      &n= bsp;     stmt.executeUpdate("NOTIFY mynotification");
            Thread.sleep(3000= 0);
           
 &= nbsp;          org.postgresql.PGNotifica= tion[] notifications =3D conn.unwrap(org.postgresql.PGConnection.class).get= Notifications();
           = ; //assertTrue(flag.get());
         =    //assertNotNull(notifications);
     &n= bsp;      //assertEquals(1, notifications.length);
&= nbsp;           //assertEquals("myn= otification", notifications[0].getName());
     &nbs= p;      //long endMillis =3D System.currentTimeMillis()= ;
            //long runtim= e =3D endMillis - startMillis;
        &nb= sp;   //assertNull("There have been notifications, although none = have been expected.",notifications);
      &nbs= p;     //assertTrue("We didn't wait long enough! runtime=3D"= + runtime, runtime > 450);

       =     stmt.close();
        =   }


Regards.

Philippe Ebersohl 


=
From: "Dave Cramer" <pg@fastcrypt.com>
To: "Phili= ppe Ebersohl" <philippe.ebersohl@dalim.com>
Cc: "David G. J= ohnston" <david.g.johnston@gmail.com>, "List" <pgsql-jdbc@postgres= ql.org>
Sent: Wednesday, 27 February, 2019 11:53:59
Subj= ect: Re: A method to asynchronously LISTEN ?

=


On Wed, 27 Feb 2019 at 05:47, Ph= ilippe 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 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&nbs= p;h= ttps://github.com/pgjdbc/pgjdbc/pull/579
You should be able t= o 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 notify

then use maven to build it



=

From: "David G= . Johnston" <david.g.johnston@gmail.com>
To: "Dave Cramer" <pg@fastcrypt.com>=
Cc: "Philippe Ebersohl" <philippe.ebersohl@dalim.com>, "List" &l= t;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 <p= g@fastcrypt.com> wrote:
<= div dir=3D"ltr">


<= div dir=3D"ltr" class=3D"gmail_attr">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 liste= ner function queue during its execution.

This after s= ending 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 transa= ction).

While the client is, IIRC, synchronous, thus= the local order of operations can be controlled, the server is asynchronou= s and thus this test is exposed to timing issues.  Maybe we need somet= hing like conn.listenSync() that blocks until a notification payload is rec= eived on the connection...?

kind of = defeats the asynchronous aspect, no ?
=

<= /blockquote>

You'd still want an asynchronous API for pe= ople but JavaScript introduced the "async/await" feature for a reason. = ; In this case making it "sync" instead of coding up wait loop seems desira= ble.  That said its quite possible I'm missing some existing feature a= s I haven't used this API at all.

David J.


3D"Visit


= 3D"Visit=0A
= ------=_Part_5681553_1597214443.1551347564336--