Problem with Async (multiple) notifications

From: Andres Olarte <olarte(dot)andres(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Problem with Async (multiple) notifications
Date: 2005-06-24 23:39:54
Message-ID: 3fccaa6905062416392e578f58@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I've been playing with async notifications lately, and I've found a
small problem: when several notifications are issued at once (for
example within a transaction) normally only one of those gets to the
client. The rest of the notifications are not received until
something happens on the connection, for example a query or another
notification. I'm using the latest CVS, updated yesterday. I've
looked over the code, and there's nothing obvious. I think that this
has to do with java's handling of sockets, as the C example that deals
with notifications works fine. It seems that some packages are
"stuck" in the socket, but my knowledge of sockets is very limited. A
possible workarround would be to issue the simplest possible query or
message to the backend when a notification is found, to see if anymore
notifications are "stuck". This would generate a little bit of extra
traffic, but only when there is a notification. Here is a small test
case showing what's happening:

public class TestAsync extends TestCase {

Connection conn2,conn1;

public void testAsync() {
String user = "andres";
String pass = "";
String url = "jdbc:postgresql://127.0.0.1/template1";
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException cnf) {
fail("Data Base Driver not Found: " + cnf.getMessage());

}
try {

conn1 = DriverManager.getConnection(url, user, pass);
conn2 = DriverManager.getConnection(url, user, pass);
conn2.setAutoCommit(true);

Statement stmt2 = conn2.createStatement();
stmt2.execute("LISTEN test1");
stmt2.execute("LISTEN test2");
stmt2.execute("LISTEN test3");
PGConnection pgconn = (PGConnection) conn2;


Statement stmt1=conn1.createStatement();
stmt1.execute("NOTIFY test1;");
stmt1.execute("NOTIFY test2;");
stmt1.execute("NOTIFY test3;");
conn1.commit();

PGNotification[] nots = pgconn.getNotifications();

assertEquals(3,nots.length);


} catch (SQLException sqle) {
fail("SQLException sql" + sqle.getLocalizedMessage());
}

}

I'm running a 7.4 backend, but I don't think that's the problem. But
if someone thinks I'm doing something wrong, please let me know!!
thanks to all of the people that have worked on PostreSQL

Andres Olarte

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2005-06-25 00:55:02 Re: Problem with Async (multiple) notifications
Previous Message Kevin Murphy 2005-06-24 21:18:35 Re: Statement setNull for Types.CLOB