Re: [Quickfix-developers] How to stop a session?
Brought to you by:
orenmnero
From: Danis T. <td...@ho...> - 2002-11-19 17:46:39
|
OK. I modified my program a little. Let's see the code: 01 class Client { 02 ... 03 public void exchange() { 04 // Instantiating Initiator object 05 Initiator initiator = new SocketInitiator(new Callback(), ...); 06 07 (new Thread() { 08 public void run() { 09 initiator.start(); 10 System.out.println("Call to initiator.stop() has returned."); 11 } 12 }).start(); 13 14 // Wait for onRun() is called 15 waitForRun.receive(); 16 System.out.println("STARTED"); 17 18 // Do exchange 19 try { Thread.sleep(5000); } // any period sufficient to logon 20 catch(InterruptedException ex) {} 21 22 // It has been decided to logout. Wake up onRun() 23 synchronized(logoutLock) { logoutLock.notify(); } 24 25 System.out.println("FINISHED"); 26 } 27 28 private PostBox waitForRun; 29 private Object logoutLock; 30 31 32 class Callback implements Application { 33 ... // Interface methods are omitted. They just log out. 34 public void onRun() { 35 System.out.println("OnRun() started"); 36 synchronized(logoutLock) { 37 waitForRun.send(); 38 try { logoutLock.wait(); } 39 catch(InterruptedException wakeUp) {} 40 } 41 System.out.println("OnRun() finished"); 42 } 43 } 44 } ///:~ Here's the CLIENT's log: [35:07,869]: CLIENT: ON_CREATE OnRun() started STARTED [35:08,921]: CLIENT: TO_ADMIN: ...35=A|34=1... [35:08,951]: CLIENT: FROM_ADMIN: ...35=A|34=1... [35:08,951]: CLIENT: ON_LOGON <--- Here's a delay caused by sleep(...) FINISHED <--- Here we can OnRun() finished <--- see races Call to initiator.stop() has returned. After the last line of the log is printed the program "hangs up" and doesn't return control to the console. The SERVER sends Heartbeat respecting to the cinfigured schedule (every 30 seconds) and waits for the same msg from the CLIENT. But the CLIENT doesn't send Heartbeat and the SERVER asks its counterpart with TestRequest msg. After three such msgs leaved with no response the SERVER just logs out without sending LOGOUT msg. Now let me give some descriptions. PostBox class is an implementation of "post boxes" introduced in Operating Systems theory. It allows to "send" message to the "post box" which can be "received". If a message is sent earlier than someone tries to receive it then that one receives the message and continues execution. If you try to receive a message earlier than it is sent then the call to receive() method blocks execution until a message is sent. Hence, the line 18 is never executed while onRun() method doesn't reach the line 37. It means that logout will never be performed until the session isn't started properly. After onRun() has signaled that it's started it goes to sleep by a call to wait(). When the program logic decides to logout it wakes up sleeping onRun() method. The method finishes and a call to initiator.stop() in the line 09 returns. Why doesn't the program finish? If you replace the line 09 with the line 37 the program finishes successfully. Another question: I use MemoryStoreFactory. Can I somehow configure the QuickFix engine to allow it automatically send LOGON message with ResetSeqNumFlag set to 'Y'? ----- Original Message ----- From: <OM...@th...> To: <GMui@PrescientMarkets.com> Cc: <qui...@li...>; <qui...@li...>; <td...@ho...> Sent: Tuesday, November 19, 2002 3:06 AM Subject: Re: [Quickfix-developers] How to stop a session? The only way to do this currently is by setting the session times in your configuration file. By doing that you can have sessions start and stop during various times of day. I guess to do what you want some sort of boolean is needed to allow you to override the session times. Is this what you are thinking of? --oren GMui@PrescientMar kets.com To: OM...@th... cc: qui...@li..., 11/18/2002 04:59 qui...@li..., td...@ho... PM Subject: Re: [Quickfix-developers] How to stop a session? Is there any planned way to do shut down a session on a per-session level rather than the entire engine? Gary Mui Prescient Markets, Inc 914-989-3118 (W) 445 Hamilton Avenue 914-422-3693 (F) White Plains, NY 10601 Please visit us at http://www.cpmarket.com OM...@th... Sent by: To: td...@ho..., qui...@li...urc <qui...@li...> eforge.net cc: Subject: Re: [Quickfix-developers] How to stop a session? 11/18/02 04:10 PM The proper way to stop the initiator is simply to let the onRun method exit. This will cause the initiator to close itself down. --oren |---------+-----------------------------------------------> | | "Danis Tazeev" <td...@ho...> | | | Sent by: | | | qui...@li...ur| | | ceforge.net | | | | | | | | | 11/18/2002 10:51 AM | | | | |---------+-----------------------------------------------> > ---------------------------------------------------------------------------- ------------------| | | | To: <qui...@li...> | | cc: | | Subject: [Quickfix-developers] How to stop a session? | > ---------------------------------------------------------------------------- ------------------| Folks, I am experimenting with QuickFix using Java interfcace, and I have a couple of questions. I have created a CLIENT (initiator) and a SERVER (acceptor) which run on different JVM. A structure of both programs is idential excluding that the CLIENT uses Initiator class and the SERVER uses Acceptor class. Initially both of them create initiator or acceptor objects and start them. The object that implements Application interface is a simple logger with an inifinite loop in onRun(). Acceptor.start() method is blocked until onRun() is running. That's why the SERVER listens infinitely. I intend to send messages being outside from onRun() method of clients. To make this possible I start a simple thread that starts initiator. Something like this: (new Thread() { public void run() { initiator.statr(); } }).start(); where initiator is an instance of Initiator class. After that the CLIENT goes to sleep for awhile (10 secodns). The SERVER and the CLIENT successfully establish a session and wait. When the CLIENT wakes up it just tries to stop the "started" initiator. The call to Initiator.stop() method doesn't return and the session doesn't finish. Instead onRun() is called again. And when the time of Heartbeat message comes up LOGON procedure is initiated. See the log (FIX 4.1): [22:15,511]: CLIENT: ON_CREATE [22:15,521]: CLIENT: ON_RUN [22:25,516]: CLIENT: ON_RUN <-- !!! trying to stop() [22:26,478]: CLIENT: TO_ADMIN: ...35=A34=1... [22:26,528]: CLIENT: FROM_ADMIN: ...35=A34=1... [22:26,528]: CLIENT: ON_LOGOUT [22:56,572]: CLIENT: TO_ADMIN: ...35=034=2... [23:26,616]: CLIENT: TO_ADMIN: ...35=134=3... [23:56,740]: CLIENT: TO_ADMIN: ...35=134=4... [24:26,814]: CLIENT: TO_ADMIN: ...35=134=5... [24:56,858]: CLIENT: ON_LOGOUT [25:02,857]: CLIENT: TO_ADMIN: ...35=A34=6... <--- Again [25:02,867]: CLIENT: FROM_ADMIN: ...35=A34=2... [25:02,867]: CLIENT: ON_LOGON [25:02,877]: CLIENT: FROM_ADMIN: ...35=234=3... [25:02,877]: CLIENT: TO_ADMIN: ...35=434=2... [25:32,911]: CLIENT: TO_ADMIN: ...35=034=7... [25:32,911]: CLIENT: FROM_ADMIN: ...35=234=4... [25:32,911]: CLIENT: TO_ADMIN: ...35=434=6... [26:02,034]: CLIENT: FROM_ADMIN: ...35=034=5... [26:02,044]: CLIENT: ON_LOGOUT An unexpected exception has been detected in native code outside the VM. Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x8a1ee0a Function name=(N/A) Library=(N/A) Current Java thread: at org.quickfix.SocketInitiator.doStart(Native Method) at org.quickfix.SocketInitiator.start(Unknown Source) at rawclient.Client$1.run(Client.java:37) at java.lang.Thread.run(Unknown Source) Is it allowed to use QuickFix this way? Where am I wrong? I don't know where to dig. Thanks. Danis Tazeev ------------------------------------------------------- This sf.net email is sponsored by: To learn the basics of securing your web site with SSL, click here to get a FREE TRIAL of a Thawte Server Certificate: http://www.gothawte.com/rd524.html _______________________________________________ Quickfix-developers mailing list Qui...@li... https://lists.sourceforge.net/lists/listinfo/quickfix-developers ------------------------------------------------------- This sf.net email is sponsored by: To learn the basics of securing your web site with SSL, click here to get a FREE TRIAL of a Thawte Server Certificate: http://www.gothawte.com/rd524.html _______________________________________________ Quickfix-developers mailing list Qui...@li... https://lists.sourceforge.net/lists/listinfo/quickfix-developers |