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@uni-konstanz.de:
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/bfc88559f339e418c4635f8ba022aefcb1b0... [2]http://files.basex.org/releases/latest/
Am Freitag, den 02.03.2012, 10:12 +0100 schrieb truc.cam@emotive.de:
Hi, I followed your instruction. But it still skipped some number.
----- Forwarded message from Truong An Nguyen ngtruongan@gmail.com ----- Date: Fri, 2 Mar 2012 09:14:57 +0100 From: Truong An Nguyen ngtruongan@gmail.com Subject: Fwd: [basex-talk] Ask about EVENT To: truc.cam@emotive.de
---------- Forwarded message ---------- From: Andreas Weiler andreas.weiler@uni-konstanz.de Date: Fri, Mar 2, 2012 at 9:09 AM Subject: Re: [basex-talk] Ask about EVENT To: Truong An Nguyen ngtruongan@gmail.com Cc: basex-talk@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@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
----- End forwarded message -----
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk