00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 package com.epam.benchmark.throughput;
00042
00043 import com.epam.benchmark.Util;
00044 import com.epam.fix.FIXVersion;
00045 import com.epam.fix.message.FIXFieldList;
00046 import com.epam.fix.message.RawFIXUtil;
00047 import com.epam.fix.message.constants.FIXT11;
00048 import com.epam.fixengine.*;
00049
00050 import java.io.IOException;
00051
00052
00053
00054
00055 public class ThroughputTester implements FIXSessionListener {
00056
00057 public static final int MESSAGES_COUNT = 1000000;
00058
00059 private static final String TEST_MESSAGE = "8=FIX.4.2\u00019=1\u000135=D\u000149=BLP\u000156=SCHB\u000134=01\u000150=30737\u000197=Y\u000152=20000809-20:20:50\u000111=90001008\u00011=10030003\u000121=2\u000155=TESTA\u000154=1\u000138=4000\u000140=2\u000159=0\u000144=30\u000147=I\u000160=20000809-18:20:32\u000110=000\u0001";
00060 private static final FIXFieldList MESSAGE_CONTENT = RawFIXUtil.getFIXFieldList(TEST_MESSAGE.getBytes());
00061
00062 private FIXSession session;
00063
00064 private String host;
00065
00066 private int port;
00067
00068
00069 public ThroughputTester(String host, int port) {
00070 this.host = host;
00071 this.port = port;
00072 }
00073
00074 public static void main(String[] args) throws Exception {
00075 if (args.length != 2) {
00076 printUsageAndExit();
00077 }
00078 String host = args[0];
00079 int port = -1;
00080 try {
00081 port = Integer.parseInt(args[1]);
00082 } catch (NumberFormatException e) {
00083 System.out.println("Incorrect port");
00084 printUsageAndExit();
00085 }
00086 new ThroughputTester(host, port).run();
00087 }
00088
00089 public void run() throws Exception {
00090 connect();
00091 startMeasuring();
00092 }
00093
00094 private void connect() throws Exception {
00095 SessionParameters details = new SessionParameters();
00096 details.setFixVersion(FIXVersion.FIX42);
00097 details.setHost(host);
00098 details.setHeartbeatInterval(30);
00099 details.setPort(port);
00100 details.setSenderCompId("BLP");
00101 details.setTargetCompId("SCHB");
00102 this.session = details.createNewFIXSession();
00103 this.session.setFIXSessionListener(this);
00104 session.connect();
00105 Thread.sleep(1000);
00106 }
00107
00108 public void startMeasuring() throws IOException {
00109 for (int i = 0; i < MESSAGES_COUNT; i++) {
00110 session.sendMessage(MESSAGE_CONTENT);
00111 }
00112 }
00113
00114
00115
00116 public void onSessionStateChange(SessionState sessionState) {
00117 System.out.println("Session state changed:" + sessionState);
00118 if (sessionState == SessionState.DISCONNECTED) {
00119 this.session.dispose();
00120 this.session = null;
00121 }
00122 }
00123
00124
00125
00126 public void onNewMessage(FIXFieldList message) {
00127 System.out.println("New application level message type: "
00128 + message.getTag(FIXT11.Header.MsgType).getStringValue()
00129 + " received ");
00130
00131 }
00132
00133 private static void printUsageAndExit() {
00134 System.out.println("SimpleClient host port");
00135 System.exit(1);
00136 }
00137 }