BaseX client event protocol
Thursday, 17 May 2012 · 4 messages · last reply 8 Jul 2012
AB
Andy Bunce17 May 2012 12:22 #
Hi,
I am looking at adding WATCH and UNWATCH to my Node.js BaseX interface and I have a couple of questions before I start.
1) The documentation at http://docs.basex.org/wiki/Server_Protocol shows nothing in the Server Response column. This seems not to be the case. It looks like a standard BaseX protocol type response is to be expected?
2) The example at
https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/EventExample.javashows session2 watching and then executing. Does the server protocol identify "event pushes" in some way. That is when I receive a message how can I tell if is a event or a command response?
/Andy
AW
Andreas Weiler17 May 2012 13:04 #
Hi Andy,
Quoted text · Andy Bunce · 1 line
> 1) The documentation at http://docs.basex.org/wiki/Server_Protocol shows nothing in the Server Response column. This seems not to be the case. It looks like a standard BaseX protocol type response is to be expected?
yes you are right, the server response is a standard basex info message.
Quoted text · Andy Bunce · 1 line
> 2) The example at https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/EventExample.java shows session2 watching and then executing. Does the server protocol identify "event pushes" in some way. That is when I receive a message how can I tell if is a event or a command response?
the event reponse is send over a separate socket connection.
-- Andreas
Quoted text · Andy Bunce · 13 lines
Am 17.05.2012 um 12:22 schrieb Andy Bunce: > Hi, > I am looking at adding WATCH and UNWATCH to my Node.js BaseX interface and I have a couple of questions before I start. > > 1) The documentation at http://docs.basex.org/wiki/Server_Protocol shows nothing in the Server Response column. This seems not to be the case. It looks like a standard BaseX protocol type response is to be expected? > > 2) The example at https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/EventExample.java shows session2 watching and then executing. Does the server protocol identify "event pushes" in some way. That is when I receive a message how can I tell if is a event or a command response? > > /Andy > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
AB
Andy Bunce3 Jun 2012 23:28 #
I have made some progress on this...
I think the protocol response to the watch is in fact {port}{id}\0 Where {port} is a basex server port to connect in order to receive events and {id} some identifier.
The client should connect to the port and send {id}\0. The response is \0. After this the connection will receive events in the form {name}{msg}
I have implemented this in node.js. One difficulty is the very asynchronous nature of node
I have tried to recreate something based on the
c#<https://github.com/BaseXdb/basex-api/blob/master/src/main/c%23/EventExample.cs>example in
node<https://github.com/apb2006/basex-node/blob/master/examples/EventExample.js>allowing for this. It runs fine the first time after the server is started, in subsequent runs the event is never received.
The log from the 1st run is
21:19:01.858 [127.0.0.1:38155] LOGIN admin OK
21:19:01.861 [127.0.0.1:38156] LOGIN test1 OK
21:19:02.003 [127.0.0.1:38155] CREATE EVENT messenger
21:19:02.005 [127.0.0.1:38155] OK 143.0 ms
21:19:02.027 [127.0.0.1:38156] OK 13.41 ms
21:19:02.247 [127.0.0.1:38156] QUERY(0) for $i in 1 to 1000000 where $i=3 return $i OK 219.51 ms
21:19:02.248 [127.0.0.1:38156] QUERY(0) OK 0.5 ms
21:19:02.252 [127.0.0.1:38155] QUERY(0) db:event('messenger', 'Hello World!') OK 230.45 ms
21:19:02.254 [127.0.0.1:38155] QUERY(0) OK 0.76 ms
21:19:02.584 [127.0.0.1:38155] EXEC(0) OK 329.22 ms
21:19:02.943 [127.0.0.1:38156] EXEC(0) OK 694.17 ms
21:19:02.945 [127.0.0.1:38156] OK 0.34 ms
21:19:03.004 [127.0.0.1:38155] DROP EVENT messenger
21:19:03.005 [127.0.0.1:38155] OK 2.18 ms
21:19:03.006 [127.0.0.1:38155] EXIT
21:19:03.011 [127.0.0.1:38155] OK 6.03 ms
21:19:03.012 [127.0.0.1:38155] LOGOUT admin OK
21:19:03.014 [127.0.0.1:38156] EXIT
21:19:03.019 [127.0.0.1:38156] OK 6.57 ms
21:19:03.020 [127.0.0.1:38156] LOGOUT test1 OK
The next run gives
19:16.106 [127.0.0.1:38158] LOGIN admin OK
21:19:16.112 [127.0.0.1:38158] CREATE EVENT messenger
21:19:16.115 [127.0.0.1:38158] OK 27.79 ms
21:19:16.151 [127.0.0.1:38159] LOGIN test1 OK
21:19:16.192 [127.0.0.1:38158] QUERY(0) db:event('messenger', 'Hello World!') OK 0.98 ms
21:19:16.200 [127.0.0.1:38158] QUERY(0) OK 7.4 ms
21:19:16.207 [127.0.0.1:38159] OK 0.65 ms
21:19:16.220 [127.0.0.1:38159] QUERY(0) for $i in 1 to 1000000 where $i=3 return $i OK 7.77 ms
21:19:16.231 [127.0.0.1:38159] QUERY(0) OK 4.3 ms
21:19:16.253 [127.0.0.1:38158] EXEC(0) Error: null
21:19:16.732 [127.0.0.1:38159] EXEC(0) OK 459.42 ms
21:19:20.036 [127.0.0.1:38158] LOGOUT admin OK
21:19:20.042 [127.0.0.1:38159] LOGOUT test1 OK
The problem seems to EXEC(0) Error: null
Any ideas what the cause might be or how I can debug this further. /Andy
Quoted text · Andreas Weiler · 45 lines
On Thu, May 17, 2012 at 12:04 PM, Andreas Weiler < andreas.weiler at uni-konstanz.de> wrote: > Hi Andy, > > 1) The documentation at http://docs.basex.org/wiki/Server_Protocol shows > nothing in the Server Response column. This seems not to be the case. It > looks like a standard BaseX protocol type response is to be expected? > > > yes you are right, the server response is a standard basex info message. > > 2) The example at > https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/EventExample.java shows > session2 watching and then executing. Does the server protocol identify > "event pushes" in some way. That is when I receive a message how can I tell > if is a event or a command response? > > > the event reponse is send over a separate socket connection. > > -- Andreas > > Am 17.05.2012 um 12:22 schrieb Andy Bunce: > > Hi, > I am looking at adding WATCH and UNWATCH to my Node.js BaseX interface > and I have a couple of questions before I start. > > 1) The documentation at http://docs.basex.org/wiki/Server_Protocol shows > nothing in the Server Response column. This seems not to be the case. It > looks like a standard BaseX protocol type response is to be expected? > > 2) The example at > https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/EventExample.javashows session2 watching and then executing. Does the server protocol > identify "event pushes" in some way. That is when I receive a message how > can I tell if is a event or a command response? > > /Andy > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > >
AB
Andy Bunce8 Jul 2012 23:59 #
I have tried this with the latest 7.3.1 and also tried to simplify my client (node.js) code I am still getting errors, not every but most runs. However now I am getting a stack trace back in the server protocol info message. This is coming on the event port
I have an event "messenger" defined and then run code
var session1 = new basex.Session("localhost", 1984, "admin", "admin");
var session2 = new basex.Session("localhost", 1984, "admin", "admin");
session2.watch("messenger", watchCallback, this)
// below forced to run after above
session1.execute("XQUERY db:event('messenger', 99)", this);
----------
// called on receipt of event
function watchCallback(name, msg) {
session1.close(this);
session2.close(this);
};
--------- the info message on the event port ---Improper use? Potential bug? Your feedback is welcome:
Contact: basex-talk at mailman.uni-konstanz.de
Version: BaseX 7.3.1 beta
Java: Sun Microsystems Inc., 1.6.0_26
OS: Linux, i386
Stack Trace:
java.lang.NullPointerException
org.basex.server.ClientListener.notify(ClientListener.java:296) org.basex.core.Events.notify(Events.java:114)
org.basex.query.func.FNDb.event(FNDb.java:689)
org.basex.query.func.FNDb.item(FNDb.java:100)
org.basex.query.expr.ParseExpr.iter(ParseExpr.java:45)
org.basex.query.func.FNDb.iter(FNDb.java:85)
org.basex.query.QueryContext.iter(QueryContext.java:292)
org.basex.query.QueryContext.iter(QueryContext.java:244)
org.basex.query.QueryProcessor.iter(QueryProcessor.java:76) org.basex.core.cmd.AQuery.query(AQuery.java:94)
org.basex.core.cmd.XQuery.run(XQuery.java:22)
org.basex.core.Command.run(Command.java:363)
org.basex.core.Command.exec(Command.java:342)
org.basex.core.Command.execute(Command.java:78)
org.basex.server.ClientListener.run(ClientListener.java:150)
-----------------------------------------------------------
Any ideas?
/Andy
Quoted text · Andy Bunce · 104 lines
On Sun, Jun 3, 2012 at 10:28 PM, Andy Bunce <bunce.andy at gmail.com> wrote: > I have made some progress on this... > I think the protocol response to the watch is in fact {port}{id}\0 > Where {port} is a basex server port to connect in order to receive events > and {id} some identifier. > The client should connect to the port and send {id}\0. The response is \0. > After this the connection will receive events in the form {name}{msg} > > I have implemented this in node.js. One difficulty is the very > asynchronous nature of node > I have tried to recreate something based on the c#<https://github.com/BaseXdb/basex-api/blob/master/src/main/c%23/EventExample.cs>example in > node<https://github.com/apb2006/basex-node/blob/master/examples/EventExample.js>allowing for this. It runs fine the first time after the server is started, > in subsequent runs the event is never received. > > The log from the 1st run is > > 21:19:01.858 [127.0.0.1:38155] LOGIN admin OK > 21:19:01.861 [127.0.0.1:38156] LOGIN test1 OK > 21:19:02.003 [127.0.0.1:38155] CREATE EVENT messenger > 21:19:02.005 [127.0.0.1:38155] OK 143.0 ms > 21:19:02.027 [127.0.0.1:38156] OK 13.41 ms > 21:19:02.247 [127.0.0.1:38156] QUERY(0) for $i in 1 to 1000000 where $i=3 return $i OK 219.51 ms > 21:19:02.248 [127.0.0.1:38156] QUERY(0) OK 0.5 ms > 21:19:02.252 [127.0.0.1:38155] QUERY(0) db:event('messenger', 'Hello World!') OK 230.45 ms > 21:19:02.254 [127.0.0.1:38155] QUERY(0) OK 0.76 ms > 21:19:02.584 [127.0.0.1:38155] EXEC(0) OK 329.22 ms > 21:19:02.943 [127.0.0.1:38156] EXEC(0) OK 694.17 ms > 21:19:02.945 [127.0.0.1:38156] OK 0.34 ms > 21:19:03.004 [127.0.0.1:38155] DROP EVENT messenger > 21:19:03.005 [127.0.0.1:38155] OK 2.18 ms > 21:19:03.006 [127.0.0.1:38155] EXIT > 21:19:03.011 [127.0.0.1:38155] OK 6.03 ms > 21:19:03.012 [127.0.0.1:38155] LOGOUT admin OK > 21:19:03.014 [127.0.0.1:38156] EXIT > 21:19:03.019 [127.0.0.1:38156] OK 6.57 ms > 21:19:03.020 [127.0.0.1:38156] LOGOUT test1 OK > The next run gives > > 19:16.106 [127.0.0.1:38158] LOGIN admin OK > 21:19:16.112 [127.0.0.1:38158] CREATE EVENT messenger > 21:19:16.115 [127.0.0.1:38158] OK 27.79 ms > 21:19:16.151 [127.0.0.1:38159] LOGIN test1 OK > 21:19:16.192 [127.0.0.1:38158] QUERY(0) db:event('messenger', 'Hello World!') OK 0.98 ms > 21:19:16.200 [127.0.0.1:38158] QUERY(0) OK 7.4 ms > 21:19:16.207 [127.0.0.1:38159] OK 0.65 ms > 21:19:16.220 [127.0.0.1:38159] QUERY(0) for $i in 1 to 1000000 where $i=3 return $i OK 7.77 ms > 21:19:16.231 [127.0.0.1:38159] QUERY(0) OK 4.3 ms > 21:19:16.253 [127.0.0.1:38158] EXEC(0) Error: null > 21:19:16.732 [127.0.0.1:38159] EXEC(0) OK 459.42 ms > 21:19:20.036 [127.0.0.1:38158] LOGOUT admin OK > 21:19:20.042 [127.0.0.1:38159] LOGOUT test1 OK > > The problem seems to EXEC(0) Error: null > Any ideas what the cause might be or how I can debug this further. > /Andy > > > On Thu, May 17, 2012 at 12:04 PM, Andreas Weiler < > andreas.weiler at uni-konstanz.de> wrote: > >> Hi Andy, >> >> 1) The documentation at http://docs.basex.org/wiki/Server_Protocol shows >> nothing in the Server Response column. This seems not to be the case. It >> looks like a standard BaseX protocol type response is to be expected? >> >> >> yes you are right, the server response is a standard basex info message. >> >> 2) The example at >> https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/EventExample.java shows >> session2 watching and then executing. Does the server protocol identify >> "event pushes" in some way. That is when I receive a message how can I tell >> if is a event or a command response? >> >> >> the event reponse is send over a separate socket connection. >> >> -- Andreas >> >> Am 17.05.2012 um 12:22 schrieb Andy Bunce: >> >> Hi, >> I am looking at adding WATCH and UNWATCH to my Node.js BaseX interface >> and I have a couple of questions before I start. >> >> 1) The documentation at http://docs.basex.org/wiki/Server_Protocol shows >> nothing in the Server Response column. This seems not to be the case. It >> looks like a standard BaseX protocol type response is to be expected? >> >> 2) The example at >> https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/api/EventExample.javashows session2 watching and then executing. Does the server protocol >> identify "event pushes" in some way. That is when I receive a message how >> can I tell if is a event or a command response? >> >> /Andy >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> >> >> >
Written for BaseX 7.2, 7.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery