pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philippe Ebersohl <philippe.ebersohl@dalim.com>
To: Dave Cramer <pg@fastcrypt.com>
Cc: List <pgsql-jdbc@postgresql.org>
Subject: Re: A method to asynchronously LISTEN ?
Date: Fri, 12 Apr 2019 22:03:21 +0200 (CEST)
Message-ID: <1325099851.4102688.1555099401456.JavaMail.zimbra@dalim.com> (raw)
In-Reply-To: <CADK3HHLQUFeWt0jW+S8EEFK9wfcvPOvrJJvQWesxyGvstJGRcA@mail.gmail.com>
References: <1058674020.3669693.1550249725415.JavaMail.zimbra@dalim.com>
	<CAKFQuwb_32MwN6SkMW=3pLQ=Y2e7zhteUsGJPvm_um0PCp+gAw@mail.gmail.com>
	<1000052273.5516163.1551264468429.JavaMail.zimbra@dalim.com>
	<CADK3HHKoF32aJJajOqyaT76A12FE+o9R_cbNAzop5OuLy4xCLg@mail.gmail.com>
	<15704019.5681554.1551347564337.JavaMail.zimbra@dalim.com>
	<1703112628.790711.1552297274774.JavaMail.zimbra@dalim.com>
	<CADK3HHL1kDF=0UEXEhSo6pBXVCh83-nBnEjqJU8+i_JMQ1D9gg@mail.gmail.com>
	<CADK3HHLQUFeWt0jW+S8EEFK9wfcvPOvrJJvQWesxyGvstJGRcA@mail.gmail.com>

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> 
Cc: "List" <pgsql-jdbc@postgresql.org> 
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

view thread (16+ messages)  latest in thread

Message-ID: <1325099851.4102688.1555099401456.JavaMail.zimbra@dalim.com>
Permalink:  ../1325099851.4102688.1555099401456.JavaMail.zimbra@dalim.com/
Also on:    postgresql.org/message-id/1325099851.4102688.1555099401456.JavaMail.zimbra@dalim.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: philippe.ebersohl@dalim.com, pg@fastcrypt.com
  Subject: Re: A method to asynchronously LISTEN ?
  In-Reply-To: <1325099851.4102688.1555099401456.JavaMail.zimbra@dalim.com>
  References: <1058674020.3669693.1550249725415.JavaMail.zimbra@dalim.com> <CAKFQuwb_32MwN6SkMW=3pLQ=Y2e7zhteUsGJPvm_um0PCp+gAw@mail.gmail.com> <1000052273.5516163.1551264468429.JavaMail.zimbra@dalim.com> <CADK3HHKoF32aJJajOqyaT76A12FE+o9R_cbNAzop5OuLy4xCLg@mail.gmail.com> <15704019.5681554.1551347564337.JavaMail.zimbra@dalim.com> <1703112628.790711.1552297274774.JavaMail.zimbra@dalim.com> <CADK3HHL1kDF=0UEXEhSo6pBXVCh83-nBnEjqJU8+i_JMQ1D9gg@mail.gmail.com> <CADK3HHLQUFeWt0jW+S8EEFK9wfcvPOvrJJvQWesxyGvstJGRcA@mail.gmail.com> <1325099851.4102688.1555099401456.JavaMail.zimbra@dalim.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox