Ask about EVENT
Friday, 2 March 2012 · 6 messages · last reply 3 Mar 2012
TN
Truong An Nguyen2 Mar 2012 08:51 #
Dear BaseX team,
I'd like to ask you why my class not run correctly. I'm using EVENT to notify changes from xquery. It must print numbers from 1 to 10, 50 times for each. Why does it skip some numbers in a random manner? How can I do to correct it?
Please see my attachment.
Thanks in advance.
AW
Andreas Weiler2 Mar 2012 09:09 #
Hi,
the problem is that you call the session2.close() method before all items are printed out in the for loop in the notify method of the notifier. This closes the session2 before all items from the event are received.
Just implement a mechanism, which is waiting for all items of the event before closing the session2.
-- Andreas
Quoted text · Truong An Nguyen · 11 lines
Am 02.03.2012 um 08:51 schrieb Truong An Nguyen: > Dear BaseX team, > I'd like to ask you why my class not run correctly. I'm using EVENT to notify changes from xquery. It must print numbers from 1 to 10, 50 times for each. Why does it skip some numbers in a random manner? How can I do to correct it? > Please see my attachment. > Thanks in advance. > > > <mainclass.java>_______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
T
truc.cam2 Mar 2012 10:12 #
Hi,
I followed your instruction. But it still skipped some number.
----- Forwarded message from Truong An Nguyen <ngtruongan at gmail.com> ----- Date: Fri, 2 Mar 2012 09:14:57 +0100
From: Truong An Nguyen <ngtruongan at gmail.com>
Subject: Fwd: [basex-talk] Ask about EVENT
To: truc.cam at emotive.de
---------- Forwarded message ----------
Quoted text · Andreas Weiler · 28 lines
From: Andreas Weiler <andreas.weiler at uni-konstanz.de> Date: Fri, Mar 2, 2012 at 9:09 AM Subject: Re: [basex-talk] Ask about EVENT To: Truong An Nguyen <ngtruongan at gmail.com> Cc: basex-talk at mailman.uni-konstanz.de Hi, the problem is that you call the session2.close() method before all items are printed out in the for loop in the notify method of the notifier. This closes the session2 before all items from the event are received. Just implement a mechanism, which is waiting for all items of the event before closing the session2. -- Andreas Am 02.03.2012 um 08:51 schrieb Truong An Nguyen: > Dear BaseX team, > I'd like to ask you why my class not run correctly. I'm using EVENT to notify changes from xquery. It must print numbers from 1 to 10, 50 times for each. Why does it skip some numbers in a random manner? How can I do to correct it? > Please see my attachment. > Thanks in advance. > > > <mainclass.java>_______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk ----- End forwarded message -----
AW
Andreas Weiler2 Mar 2012 11:34 #
Hi,
please have a look at the attached example...
Quoted text · truc.cam · 52 lines
Am 02.03.2012 um 10:12 schrieb truc.cam at emotive.de: > Hi, > I followed your instruction. But it still skipped some number. > > ----- Forwarded message from Truong An Nguyen <ngtruongan at gmail.com> ----- > Date: Fri, 2 Mar 2012 09:14:57 +0100 > From: Truong An Nguyen <ngtruongan at gmail.com> > Subject: Fwd: [basex-talk] Ask about EVENT > To: truc.cam at emotive.de > > ---------- Forwarded message ---------- > From: Andreas Weiler <andreas.weiler at uni-konstanz.de> > Date: Fri, Mar 2, 2012 at 9:09 AM > Subject: Re: [basex-talk] Ask about EVENT > To: Truong An Nguyen <ngtruongan at gmail.com> > Cc: basex-talk at mailman.uni-konstanz.de > > > Hi, > > the problem is that you call the session2.close() method before all items > are printed out in the for loop in the > notify method of the notifier. This closes the session2 before all items > from the event are received. > > Just implement a mechanism, which is waiting for all items of the event > before closing the session2. > > -- Andreas > > Am 02.03.2012 um 08:51 schrieb Truong An Nguyen: > >> Dear BaseX team, >> I'd like to ask you why my class not run correctly. I'm using EVENT to > notify changes from xquery. It must print numbers from 1 to 10, 50 times > for each. Why does it skip some numbers in a random manner? How can I do to > correct it? >> Please see my attachment. >> Thanks in advance. >> >> >> <mainclass.java>_______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > ----- End forwarded message ----- > > <mainclass.java>_______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
DP
Hi,
maybe, I should mention, that there was a small bug in the
EventListener, which caused the "randomness". It's fixed [1], so please try the example from Andreas with the latest snapshot of BaseX [2].
Regards,
Dimitar
[1]https://github.com/BaseXdb/basex/commit/bfc88559f339e418c4635f8ba022aefcb1b0eaff#diff-1 [2]http://files.basex.org/releases/latest/
Quoted text · +0100 · 52 lines
Am Freitag, den 02.03.2012, 10:12 +0100 schrieb truc.cam at emotive.de: > Hi, > I followed your instruction. But it still skipped some number. > > ----- Forwarded message from Truong An Nguyen <ngtruongan at gmail.com> ----- > Date: Fri, 2 Mar 2012 09:14:57 +0100 > From: Truong An Nguyen <ngtruongan at gmail.com> > Subject: Fwd: [basex-talk] Ask about EVENT > To: truc.cam at emotive.de > > ---------- Forwarded message ---------- > From: Andreas Weiler <andreas.weiler at uni-konstanz.de> > Date: Fri, Mar 2, 2012 at 9:09 AM > Subject: Re: [basex-talk] Ask about EVENT > To: Truong An Nguyen <ngtruongan at gmail.com> > Cc: basex-talk at mailman.uni-konstanz.de > > > Hi, > > the problem is that you call the session2.close() method before all items > are printed out in the for loop in the > notify method of the notifier. This closes the session2 before all items > from the event are received. > > Just implement a mechanism, which is waiting for all items of the event > before closing the session2. > > -- Andreas > > Am 02.03.2012 um 08:51 schrieb Truong An Nguyen: > > > Dear BaseX team, > > I'd like to ask you why my class not run correctly. I'm using EVENT to > notify changes from xquery. It must print numbers from 1 to 10, 50 times > for each. Why does it skip some numbers in a random manner? How can I do to > correct it? > > Please see my attachment. > > Thanks in advance. > > > > > > <mainclass.java>_______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > ----- End forwarded message ----- > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
T
truc.cam3 Mar 2012 05:04 #
Thanks you for your help. It's very useful. But I found 2 problem.
1.If method notify is longer. The application will raise the error:
"Exception in thread "main" org.basex.core.BaseXException: Stopped at line 1, column 60:
[BASX0009] Event 'EVENT' is unknown.
at org.basex.server.ClientQuery.exec(ClientQuery.java:93)
at org.basex.server.ClientQuery.execute(ClientQuery.java:58) at mainclass.main(mainclass.java:61)
"
The code as following:
BaseXServer server = new BaseXServer();
ClientSession session1 = new ClientSession(server.context,
"admin", "admin");
ClientSession session2 = new ClientSession(server.context,
"admin", "admin");
final ArrayList<String> incoming = new ArrayList<String>();
try
{
session1.execute("drop event EVENT");
}
catch (Exception ex)
{ }
session1.execute("create event EVENT");
session2.watch("EVENT", new EventNotifier() {
@Override
public void notify(String value) {
// TODO Auto-generated method stub
try {
Thread.sleep(10);
} catch(InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} incoming.add(value);
}
});
session1.query("for $value in (1 to 1000000) return
db:event('EVENT',$value)").execute();
while(true)
{
System.out.println(incoming.size());
}2.If the max number is over 10.000.000.Sometimes the application is successful.Sometimes It will raise the error:
"Exception in thread "main" java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at org.basex.io.in.BufferInput.read(BufferInput.java:151)
at org.basex.io.in.DecodingInput.read(DecodingInput.java:34)
at org.basex.server.ClientSession.receive(ClientSession.java:309)
at org.basex.server.ClientQuery.exec(ClientQuery.java:92)
at org.basex.server.ClientQuery.execute(ClientQuery.java:58)
at mainclass.main(mainclass.java:53)"The code as following:
BaseXServer server = new BaseXServer();
ClientSession session1 = new ClientSession(server.context,
"admin", "admin");
ClientSession session2 = new ClientSession(server.context,
"admin", "admin");
final ArrayList<String> incoming = new ArrayList<String>();
try
{
session1.execute("drop event EVENT");
}
catch (Exception ex)
{ }
session1.execute("create event EVENT");
session2.watch("EVENT", new EventNotifier() {
@Override
public void notify(String value) {
// TODO Auto-generated method stub
incoming.add(value);
}
});
session1.query("for $value in (1 to 10000000) return
db:event('EVENT',$value)").execute();
while(true)
{
System.out.println(incoming.size());
}Quoting Dimitar Popov <dimitar.popov at uni-konstanz.de>:
Quoted text · Dimitar Popov · 64 lines
> Hi, > > maybe, I should mention, that there was a small bug in the > EventListener, which caused the "randomness". It's fixed [1], so please > try the example from Andreas with the latest snapshot of BaseX [2]. > > Regards, > Dimitar > > [1]https://github.com/BaseXdb/basex/commit/bfc88559f339e418c4635f8ba022aefcb1b0eaff#diff-1 > [2]http://files.basex.org/releases/latest/ > > Am Freitag, den 02.03.2012, 10:12 +0100 schrieb truc.cam at emotive.de: >> Hi, >> I followed your instruction. But it still skipped some number. >> >> ----- Forwarded message from Truong An Nguyen <ngtruongan at gmail.com> ----- >> Date: Fri, 2 Mar 2012 09:14:57 +0100 >> From: Truong An Nguyen <ngtruongan at gmail.com> >> Subject: Fwd: [basex-talk] Ask about EVENT >> To: truc.cam at emotive.de >> >> ---------- Forwarded message ---------- >> From: Andreas Weiler <andreas.weiler at uni-konstanz.de> >> Date: Fri, Mar 2, 2012 at 9:09 AM >> Subject: Re: [basex-talk] Ask about EVENT >> To: Truong An Nguyen <ngtruongan at gmail.com> >> Cc: basex-talk at mailman.uni-konstanz.de >> >> >> Hi, >> >> the problem is that you call the session2.close() method before all items >> are printed out in the for loop in the >> notify method of the notifier. This closes the session2 before all items >> from the event are received. >> >> Just implement a mechanism, which is waiting for all items of the event >> before closing the session2. >> >> -- Andreas >> >> Am 02.03.2012 um 08:51 schrieb Truong An Nguyen: >> >> > Dear BaseX team, >> > I'd like to ask you why my class not run correctly. I'm using EVENT to >> notify changes from xquery. It must print numbers from 1 to 10, 50 times >> for each. Why does it skip some numbers in a random manner? How can I do to >> correct it? >> > Please see my attachment. >> > Thanks in advance. >> > >> > >> > <mainclass.java>_______________________________________________ >> > BaseX-Talk mailing list >> > BaseX-Talk at mailman.uni-konstanz.de >> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> >> ----- End forwarded message ----- >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Written for BaseX 7.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery