Quickfix/j Source code Research (iii)

Source: Internet
Author: User
Tags local time
Quickfix/j Source code Research (iii)
Liyayawodeai@16.com

(iii). Client Fix resolution
Basics: The following article describes the premise that the required data dictionary has been generated according to its own business rules, and that a customized protocol parsing code has been generated using the quickfix/j ant jar Target. To generate the process and details of the protocol parsing code, please refer to the article Quickfix/j Source code Study (ii).

1. In the design of quickfix/j, in order to remove the coupling relationship between Messagefactory and the corresponding protocol parsing code, Quickfix. Defaultmessagefactory will use reflection to dynamically discover the parsing protocol's code when runtime. So if you have a custom data dictionary and have generated code to parse the protocol based on that dictionary, don't forget to add the message factory of the corresponding agreement to the Defaultmessagefactory discoverfactory(Beginstring, Factoryclassname).

2.DefaultMessageFactory has two main functions, one is to create a message (according to Beginstring and Msgtype), and the other is to create a group (according to Beginstring, Msgtype and Correspondingfieldid). Accordingly, in the Code of the parsing protocol generated by the data dictionary, of course there are messagefactory, and this messagefactory of course creates the message and group.

3. Defaultmessagefactory when creating the message, first find the corresponding version of the beginstring according to the factory, found the corresponding messages create, or new a default quickfix. Message.

The use of 4.MessageCracker. When the code that resolves the protocol is automatically generated, the corresponding version of the Messagecracker is definitely generated. By carefully reading this newly generated messagecracker, you will find that there are many onmessage methods that are not implemented internally and that the default throw Newunsupportedmessagetype () is added to the statement. In practical use, users need to create their own application and extendsquickfix. Messagecracker Implementsquickfix. Application. Because of override, these throw newunsupportedmessagetype will naturally be shielded.
If the user needs to take the content in the message, do the corresponding business logic, first in the user's Application.fromapp crack (sessionId), crack similar to the Cracker factory, It selects the corresponding Messagecracker according to the MessageHeader and then recalls the corresponding onmessage. OnMessage is override implemented in the user application.

5. Customer initiator implementation of client-side Protocol summary
A to create the processing class, extends Messagecracker implements Quickfix. Application implements Quickfix. applicationextended
(b) Add crack (Message, sessionId) to the Fromapp;
C to implement the corresponding onmessage for the message to be processed
D Create Socketinitiator instances and fill in the customized application,messagestorefactory,settings,logfactory,messagefactory.
e) Start Initiator.

6. If you want to save every message you receive into a single file backup, such as DBF, how to achieve.
a) programme 1. To achieve their own messagestore. Quickfix/j provides a ready-made filestore that all messages can be stored in the same file.
b) Programme 2. In the Fromapp interface of application, obtain the corresponding message, extract the required elements, and save the disk.
Two comparison of scenarios: Scenario 2 reduces parsing from string to message and is more efficient. Because Messagestore input is stringmessage, you need to parse it again to get a message.

7. The Fix standard agreement stipulates that messages (message) should have at least one field (field), and that if you find that there are no fields in the client's own fix protocol resolution, you need to remove the restriction on this condition in quickfix/j. Specific in Quickfix. Dictionary.
Java Code private void load (document document, String Msgtype, node node) throws Configerror {...//if (FIELDN   Odes.getlength () = = 0) {//throw new Configerror ("No fields found:msgtype=" + msgtype); //        }   ...   }
private void Load (document document, String Msgtype, node node) throws Configerror {
...        if (fieldnodes.getlength () = = 0) {
//            throw new Configerror ("No fields found:msgtype=" + msgtype);
//        }
...
}


8. In the implementation of quickfix/j, there is a presumption that the FIX version number is less than or equal to "fix.4.4", and that a greater than FIX4.4 is a logic. Then you need to be aware of the protocol version (that is, FIX's beginstring) that you define at the time of customization and whether it is less than or equal to "fix.4.4" from the point of view of the string comparison. If not, you need to change the logic of quickfix/j in many places. Like in Quickfix. In Datadictionary.load:
Java Code private void load (InputStream inputstream) throws Configerror {... if (beginstring.startswith Refix) | | Beginstring.compareto (fixversions.fix50) < 0) {...}
private void Load (InputStream inputstream) throws Configerror {
...
        if (Beginstring.startswith (fixt_prefix) | | | Beginstring.compareto (FIXVERSIONS.FIX50) < 0) {
        ...
...
}


9. Quickfix/j in the implementation, the time used in the default message header (header) is Utctimestamp, if the UTC time is not used in the custom, and the local time is used,
A to add the data type of local time, such as Localtimestampfield, can imitate quickfix. Utctimestampfield. Others also need to add localdateonlyfield,localtimeonlyfield,localtimestampconverter,localdateonlyconverter that are related to local time, Localtimeonlyconverter
(b) Where timestamp is used, add a version to determine whether the local time or UTC time is used depending on the version. Need to modify the place probably has: session.dotargettoohigh,session.generatesequencereset,session.initializeresendfields,session.validatepossdup,se Ssion.verify.

10.quickfix/j in the implementation, the heartbeat setting (Heartbtint) is determined by the client (initiator), while the Step Protocol stipulates that the heartbeat is on the server side (acceptor), This requires modifying the settings for roles and Heartbtint in Defaultsessionfactory.create (sessionid,settings). You also need to modify the logic in Session.nextlogon (message) that reads the Heartbtint and sets it to the state after landing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.