File size: 56,568 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 |
package com.thomsonreuters.upa.examples.consumer;
import java.net.InetAddress;
import java.net.UnknownHostException;
import com.thomsonreuters.upa.codec.Buffer;
import com.thomsonreuters.upa.codec.Codec;
import com.thomsonreuters.upa.codec.CodecFactory;
import com.thomsonreuters.upa.codec.CodecReturnCodes;
import com.thomsonreuters.upa.codec.DecodeIterator;
import com.thomsonreuters.upa.codec.Msg;
import com.thomsonreuters.upa.codec.MsgClasses;
import com.thomsonreuters.upa.codec.Qos;
import com.thomsonreuters.upa.codec.QosRates;
import com.thomsonreuters.upa.codec.QosTimeliness;
import com.thomsonreuters.upa.examples.common.ChannelSession;
import com.thomsonreuters.upa.examples.common.ResponseCallback;
import com.thomsonreuters.upa.examples.common.DirectoryHandler;
import com.thomsonreuters.upa.examples.common.DictionaryHandler;
import com.thomsonreuters.upa.examples.common.LoginHandler;
import com.thomsonreuters.upa.examples.common.StreamIdWatchList;
import com.thomsonreuters.upa.examples.common.SymbolListHandler;
import com.thomsonreuters.upa.shared.CommandLine;
import com.thomsonreuters.upa.shared.ConsumerLoginState;
import com.thomsonreuters.upa.shared.PingHandler;
import com.thomsonreuters.upa.rdm.DomainTypes;
import com.thomsonreuters.upa.rdm.Login;
import com.thomsonreuters.upa.transport.ChannelInfo;
import com.thomsonreuters.upa.transport.ChannelState;
import com.thomsonreuters.upa.transport.ConnectOptions;
import com.thomsonreuters.upa.transport.ConnectionTypes;
import com.thomsonreuters.upa.transport.Error;
import com.thomsonreuters.upa.transport.InProgInfo;
import com.thomsonreuters.upa.transport.TransportBuffer;
import com.thomsonreuters.upa.transport.TransportFactory;
import com.thomsonreuters.upa.transport.TransportReturnCodes;
import com.thomsonreuters.upa.valueadd.domainrep.rdm.directory.Service;
/**
* <p>
* This is a main class to run UPA Consumer application. The purpose of this
* application is to consume or post content between an OMM consumer and OMM
* provider. It is a single-threaded client application.
* </p>
* <H2>Summary</H2>
* <p>
* This class is responsible for the following:
* <ul>
* <li>Initialize and set command line options.
* <li>Create a {@link ChannelSession UPA Channel Session}.
* <li>Create Handler instances to handle Login, Directory, Dictionary,
* MarketPrice, MarketByOrder, MarketByPrice, and YieldCurve requests and responses.
* <li>Create handlers for posting and symbol list request, responses.
* <li>If the dictionary is found in the directory of execution, then it is
* loaded directly from the file. However, the default configuration for this
* application is to request the dictionary from the provider.
* <li>Connect to the provider, login, request source directory, request
* dictionary if not loaded from file, send item requests for specified domain
* types, and process responses (refresh, status, update, close).
* <li>Cleanup.
* </ul>
* <p>
* This class is also a call back for all events from provider. It dispatches
* events to domain specific handlers.
* <p>
* This application is intended as a basic usage example. Some of the design
* choices were made to favor simplicity and readability over performance. It is
* not intended to be used for measuring performance. This application uses
* Value Add and shows how using Value Add simplifies the writing of UPA
* applications. Because Value Add is a layer on top of UPA, you may see a
* slight decrease in performance compared to writing applications directly to
* the UPA interfaces.
* <p>
* <H2>Setup Environment</H2>
* <p>
* The RDMFieldDictionary and enumtype.def files could be located in the
* directory of execution or this application will request dictionary from
* provider.
* <p>
* <H2>Running the application:</H2>
* <p>
* Change directory to the <i>Java</i> directory and issue the following <i>Gradle</i> command.
* <p>
* Linux: ./gradlew runConsumer -PcommandLineArgs="arguments"<br>
* Windows: gradlew.bat runConsumer -PcommandLineArgs="arguments"<br>
* <br>
* Arguments are listed below.
* </p>
* <ul>
* <li>-h Server host name. Default is <i>localhost</i>.
* <li>-p Server port number. Default is <i>14002</i>.
* <li>-uname Login user name. Default is system user name.
* <li>-s Service name. Default is <i>DIRECT_FEED</i>.
* <li>-mp Market Price domain item name. Default is <i>TRI.N</i>. The user can
* specify multiple -mp instances, where each occurrence is associated with a
* single item. For example, specifying -mp TRI -mp GOOG will provide content
* for two MarketPrice items.
* <li>-mpps Market Price domain item name on private stream. No default. The
* user can specify multiple -mpps instances, where each occurrence is
* associated with a single item.
* <li>-mbo Market By Order domain item name. No default. The user can specify
* multiple -mbo instances, where each occurrence is associated with a single
* item.
* <li>-mbops Market By Order domain item name on private stream. No default.
* The user can specify multiple -mbops instances, where each occurrence is
* associated with a single item.
* <li>-mbp market By Price domain item name. No default. The user can specify
* multiple -mbp instances, where each occurrence is associated with a single
* item.
* <li>-mbpps market By Price domain item name on private stream. No default.
* The user can specify multiple -mbpps instances, where each occurrence is
* associated with a single item.
* <li>-yc Yield Curve domain item name. No default. The user can specify
* multiple -yc instances, where each occurrence is associated with a
* single item.
* <li>-ycps Yield Curve domain item name on private stream. No default. The
* user can specify multiple -ycps instances, where each occurrence is
* associated with a single item.
* <li>-view viewFlag. Default is false. If true, each request will use a basic
* dynamic view.
* <li>-post postFlag. Default is false. If true, the application will attempt
* to send post messages on the first requested Market Price item (i.e.,
* on-stream).
* <li>-offpost offPostFlag. Default is false. If true, the application will
* attempt to send post messages on the login stream (i.e., off-stream).
* <li>-publisherInfo publisherInfoFlag. Default is false. If true, the application will
* attempt to send post messages with publisher ID and publisher address.
* <li>-snapshot snapShotFlag. If true, each request will be non-streaming (i.e.
* snapshot). Default is false (i.e. streaming requests).
* <li>-sl symbolListName. symbolListName is optional without a default. If -sl
* is specified without a symbolListName the itemList from the source directory
* response will be used.
* <li>-x Provides XML tracing of messages.
* <li>-connectionType. Connection Type used (Socket, http, or encrypted).
* Default is <i>Socket</i>.
* <li>-runtime run time. Default is 600 seconds. Controls the time the
* application will run before exiting, in seconds.
* <li>-proxy proxyFlag. if provided, the application will attempt
* to make an http or encrypted connection through a proxy server (if
* connectionType is set to http or encrypted).
* <li>-ph Proxy host name.
* <li>-pp Proxy port number.
* <li>-plogin User name on proxy server.
* <li>-ppasswd Password on proxy server.
* <li>-pdomain Proxy Domain.
* <li>-krbfile Proxy KRB file.
* <li>-keyfile keystore file for encryption.
* <li>-keypasswd keystore password for encryption.
* <li>-at Specifies the Authentication Token. If this is present, the login user name type will be Login.UserIdTypes.AUTHN_TOKEN.
* <li>-ax Specifies the Authentication Extended information.
* <li>-aid Specifies the Application ID.
*
* </ul>
*
* @see DictionaryHandler
* @see DirectoryHandler
* @see LoginHandler
* @see PostHandler
* @see MarketPriceHandler
* @see MarketByOrderHandler
* @see MarketByPriceHandler
* @see SymbolListHandler
* @see YieldCurveHandler
*/
public class Consumer implements ResponseCallback
{
private static final int CONSUMER_CONNECTION_RETRY_TIME = 15; // seconds
private ChannelSession channelSession;
private ChannelInfo channelInfo;
private boolean postInit = false;
private LoginHandler loginHandler;
private DirectoryHandler srcDirHandler;
private DictionaryHandler dictionaryHandler;
private MarketPriceHandler marketPriceHandler;
private MarketByOrderHandler marketByOrderHandler;
private MarketByPriceHandler marketByPriceHandler;
private PostHandler postHandler;
private SymbolListHandler symbolListHandler;
private YieldCurveHandler yieldCurveHandler;
private boolean shouldOffStreamPost = false;
private boolean shouldOnStreamPost = false;
private Buffer postItemName;
private StreamIdWatchList itemWatchList;
// indicates if requested service is up
private boolean requestsSent;
private long runtime;
// default server host name
private static final String defaultSrvrHostname = "localhost";
// default server port number
private static final String defaultSrvrPortNo = "14002";
// default service name
private static final String defaultServiceName = "DIRECT_FEED";
// default item name
private static final String defaultItemName = "TRI.N";
// consumer run-time in seconds
private static final int defaultRuntime = 600;
private Error error; // error information
private DecodeIterator dIter = CodecFactory.createDecodeIterator();
private Msg responseMsg = CodecFactory.createMsg();
// private streams items are non-recoverable, it is not sent again after recovery
private boolean mppsRequestSent = false;
private boolean mbopsRequestSent = false;
private boolean mbppsRequestSent = false;
private boolean ycpsRequestSent = false;
private ConnectOptions _tunnelingConnectOpts;
private String _localHostName = null;
private String _localIPaddress = null;
public Consumer()
{
channelInfo = TransportFactory.createChannelInfo();
itemWatchList = new StreamIdWatchList();
loginHandler = new LoginHandler();
srcDirHandler = new DirectoryHandler();
dictionaryHandler = new DictionaryHandler();
marketPriceHandler = new MarketPriceHandler(itemWatchList);
marketByOrderHandler = new MarketByOrderHandler(itemWatchList);
marketByPriceHandler = new MarketByPriceHandler(itemWatchList);
postHandler = new PostHandler();
symbolListHandler = new SymbolListHandler();
yieldCurveHandler = new YieldCurveHandler(itemWatchList);
channelSession = new ChannelSession();
postItemName = CodecFactory.createBuffer();
error = TransportFactory.createError();
_tunnelingConnectOpts = TransportFactory.createConnectOptions();
}
/**
* Main loop that handles channel connection, login requests, reading and
* processing responses from channel.
*/
public void run()
{
PingHandler pingHandler = new PingHandler();
InProgInfo inProg = TransportFactory.createInProgInfo();
while (true)
{
try
{
connectRetry(inProg);
}
catch (InterruptedException intExp)
{
System.out.println("Thread: " + Thread.currentThread() + " interrupted. Error:" + intExp.getLocalizedMessage());
return;
}
// Handle run-time
if (System.currentTimeMillis() >= runtime)
{
System.out.println("Consumer run-time expired...");
break;
}
if (channelSession.channel().info(channelInfo, error) != TransportReturnCodes.SUCCESS)
{
System.out.println("Channel.info() failed");
closeChannel();
return;
}
System.out.printf("Channel Info:\n" +
" Max Fragment Size: %d\n" +
" Output Buffers: %d Max, %d Guaranteed\n" +
" Input Buffers: %d\n" +
" Send/Recv Buffer Sizes: %d/%d\n" +
" Ping Timeout: %d\n",
channelInfo.maxFragmentSize(),
channelInfo.maxOutputBuffers(), channelInfo.guaranteedOutputBuffers(),
channelInfo.numInputBuffers(),
channelInfo.sysSendBufSize(), channelInfo.sysRecvBufSize(),
channelInfo.pingTimeout()
);
System.out.println( " Client To Server Pings: " + channelInfo.clientToServerPings() +
"\n Server To Client Pings: " + channelInfo.serverToClientPings() +
"\n");
System.out.printf(" Connected component version: ");
int count = channelInfo.componentInfo().size();
if (count == 0)
System.out.printf("(No component info)");
else
{
for (int i = 0; i < count; ++i)
{
System.out.println(channelInfo.componentInfo().get(i).componentVersion());
if (i < count - 1)
System.out.printf(", ");
}
}
loginHandler.applicationName("Consumer");
loginHandler.role(Login.RoleTypes.CONS);
// Send login request message
channelSession.isLoginReissue = false;
if (loginHandler.sendRequest(channelSession, error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error sending Login request, exit.");
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
// Initialize ping handler
pingHandler.initPingHandler(channelSession.channel().pingTimeout());
// this is the message processing loop
readAndProcessResp(pingHandler);
}
}
// connection recovery loop
private void connectRetry(InProgInfo inProg) throws InterruptedException
{
String hostName = CommandLine.value("h");
String portNumber = CommandLine.value("p");
String interfaceName = CommandLine.value("i");
while (System.currentTimeMillis() < runtime && channelSession.shouldRecoverConnection())
{
System.out.println("Starting connection...");
requestsSent = false;
// get connect options from the channel session
ConnectOptions copts = channelSession.getConnectOptions();
// set the connection parameters on the connect options
copts.unifiedNetworkInfo().address(hostName);
copts.unifiedNetworkInfo().serviceName(portNumber);
copts.unifiedNetworkInfo().interfaceName(interfaceName);
channelSession.connect(inProg, error);
// connection hand-shake loop
waitUntilChannelActive(inProg);
if (channelSession.shouldRecoverConnection())
{
/* sleep before trying to recover connection */
Thread.sleep(CONSUMER_CONNECTION_RETRY_TIME * 1000);
continue;
}
}
}
/*
* Wait for channel to become active. This finalizes the three-way handshake.
*/
private void waitUntilChannelActive(InProgInfo inProg) throws InterruptedException
{
while (System.currentTimeMillis() < runtime && channelSession.channelState() != ChannelState.ACTIVE)
{
if (channelSession.initChannel(inProg, error) < TransportReturnCodes.SUCCESS)
{
System.out.println("Error initializing channel, will retry: " + error.text());
}
if (channelSession.channel() == null || channelSession.channelState() == ChannelState.ACTIVE)
break;
Thread.sleep(1000);
}
}
/* read processing loop */
private void readAndProcessResp(PingHandler pingHandler)
{
int ret = 0;
while (System.currentTimeMillis() < runtime)
{
// read until no more to read
ret = channelSession.read(pingHandler, this, error);
if (ret != CodecReturnCodes.SUCCESS)
{
System.out.println("Read failure, " + error.text());
System.out.println("Consumer exits...");
System.exit(TransportReturnCodes.FAILURE);
}
// break out of message processing loop if connection should recover
if (channelSession.shouldRecoverConnection())
break;
//Handle pings
if (pingHandler.handlePings(channelSession.channel(), error) != CodecReturnCodes.SUCCESS)
{
closeChannel();
System.out.println("Error handling pings: " + error.text());
System.out.println("Consumer exits...");
System.exit(TransportReturnCodes.FAILURE);
}
handlePosting();
// send login reissue if login reissue time has passed
if (channelSession.canSendLoginReissue &&
System.currentTimeMillis() >= channelSession.loginReissueTime)
{
channelSession.isLoginReissue = true;
if (loginHandler.sendRequest(channelSession, error) != CodecReturnCodes.SUCCESS)
{
System.out.println("Login reissue failed. Error: " + error.text());
}
else
{
System.out.println("Login reissue sent");
}
channelSession.canSendLoginReissue = false;
}
}
}
// on and off stream posting if enabled
private void handlePosting()
{
if (postHandler.enableOnstreamPost())
{
postItemName.clear();
int postStreamId = marketPriceHandler.getFirstItem(postItemName);
if (postStreamId == 0 || postItemName.length() == 0)
{
return;
}
postHandler.streamId(postStreamId);
postHandler.serviceId(srcDirHandler.serviceInfo().serviceId());
postHandler.dictionary(dictionaryHandler.dictionary());
postHandler.postItemName().data(postItemName.data(), postItemName.position(), postItemName.length());
int ret = postHandler.handlePosts(channelSession, error);
if (ret < CodecReturnCodes.SUCCESS)
System.out.println("Error posting onstream: " + error.text());
}
if (postHandler.enableOffstreamPost())
{
postHandler.streamId(loginHandler.refreshInfo().streamId());
postHandler.postItemName().data("OFFPOST");
postHandler.serviceId(srcDirHandler.serviceInfo().serviceId());
postHandler.dictionary(dictionaryHandler.dictionary());
int ret = postHandler.handlePosts(channelSession, error);
if (ret < CodecReturnCodes.SUCCESS)
System.out.println("Error posting offstream: " + error.text());
}
}
/**
* Initializes consumer application.
*
* It is responsible for: Initializing command line options used by the
* application. Parsing command line arguments. Initializing all domain
* handlers. Loading dictionaries from file.
*
* @param args
*/
public void init(String[] args)
{
// process command line args
addCommandLineArgs();
try
{
CommandLine.parseArgs(args);
}
catch (IllegalArgumentException ile)
{
System.err.println("Error loading command line arguments:\t");
System.err.println(ile.getMessage());
System.err.println();
System.err.println(CommandLine.optionHelpString());
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
if (args.length == 0 || (!isMarketPriceArgSpecified() && !isYieldCurveArgSpecified()))
{
CommandLine.parseArgs(new String[] { "-mp", defaultItemName });
}
// display product version information
System.out.println(Codec.queryVersion().toString());
System.out.println("Consumer initializing...");
try
{
runtime = System.currentTimeMillis() + CommandLine.intValue("runtime") * 1000;
}
catch (NumberFormatException ile)
{
System.err.println("Invalid argument, number expected.\t");
System.err.println(ile.getMessage());
System.out.println("Consumer exits...");
System.exit(-1);
}
shouldOffStreamPost = CommandLine.booleanValue("offpost");
// this application requires at least one market price item to be
// requested for on-stream posting to be performed
shouldOnStreamPost = CommandLine.booleanValue("post");
if (shouldOnStreamPost)
{
if (!CommandLine.hasArg("mp"))
{
System.out.println("\nPosting will not be performed as no Market Price items were requested");
shouldOnStreamPost = false;
}
}
postHandler.enableOnstreamPost(shouldOnStreamPost);
String value = CommandLine.value("publisherInfo");
if (value!= null)
{
String [] pieces = value.split(",");
if( pieces.length > 1 )
{
String publisherId = pieces[0];
String publisherAddress = pieces[1];
postHandler.setPublisherInfo(publisherId, publisherAddress);
}
else
{
System.err.println("Error loading command line arguments for publisherInfo [id, address]:\t");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
}
loginHandler.userName(CommandLine.value("uname"));
loginHandler.authenticationToken(CommandLine.value("at"));
loginHandler.authenticationExtended(CommandLine.value("ax"));
loginHandler.applicationId(CommandLine.value("aid"));
// set service name in directory handler
srcDirHandler.serviceName(CommandLine.value("s"));
marketPriceHandler.snapshotRequest(CommandLine.booleanValue("snapshot"));
marketByOrderHandler.snapshotRequest(CommandLine.booleanValue("snapshot"));
marketByPriceHandler.snapshotRequest(CommandLine.booleanValue("snapshot"));
yieldCurveHandler.snapshotRequest(CommandLine.booleanValue("snapshot"));
symbolListHandler.snapshotRequest(CommandLine.booleanValue("snapshot"));
marketPriceHandler.viewRequest(CommandLine.booleanValue("view"));
if (channelSession.initTransport(false, error) < CodecReturnCodes.SUCCESS)
{
System.err.println("Error initialize transport.");
System.out.println("Consumer exits...");
System.exit(error.errorId());
}
String connectionType = CommandLine.value("connectionType");
if (connectionType.equals("encrypted"))
{
channelSession.setConnectionType(ConnectionTypes.ENCRYPTED);
_tunnelingConnectOpts.tunnelingInfo().tunnelingType("encrypted");
// build tunneling and credentials config and pass to channelSession
setEncryptedConfiguration(_tunnelingConnectOpts);
}
else if (connectionType.equals("http"))
{
channelSession.setConnectionType(ConnectionTypes.HTTP);
_tunnelingConnectOpts.tunnelingInfo().tunnelingType("http");
// build http and credentials config and pass to channelSession
setHTTPconfiguration(_tunnelingConnectOpts);
}
// load dictionary
dictionaryHandler.loadDictionary();
// enable XML tracing
if (CommandLine.booleanValue("x"))
{
channelSession.enableXmlTrace(dictionaryHandler.dictionary());
}
}
private void setEncryptedConfiguration(ConnectOptions options)
{
if (CommandLine.booleanValue("proxy"))
{
options.tunnelingInfo().HTTPproxy(true);
String proxyHost = CommandLine.value("ph");
if ( proxyHost == null)
{
System.err.println("Error: Proxy hostname not provided.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
String proxyPort = CommandLine.value("pp");
if ( proxyPort == null)
{
System.err.println("Error: Proxy port number not provided.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
options.tunnelingInfo().HTTPproxyHostName(proxyHost);
try
{
options.tunnelingInfo().HTTPproxyPort(Integer.parseInt(proxyPort));
}
catch(Exception e)
{
System.err.println("Error: Proxy port number not provided.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
}
String keyFile = CommandLine.value("keyfile");
if (keyFile == null)
{
System.err.println("Error: Keystore file is missing for connectionType of encryption.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
String keyPasswd = CommandLine.value("keypasswd");
if (keyPasswd == null)
{
System.err.println("Error: Keystore Password is missing for connectionType of encryption.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
options.tunnelingInfo().KeystoreFile(keyFile);
options.tunnelingInfo().KeystorePasswd(keyPasswd);
channelSession.tunnelingConnectOptions(_tunnelingConnectOpts);
// credentials
if (options.tunnelingInfo().HTTPproxy())
{
setCredentials(options);
channelSession.credentialsConnectOptions(options);
}
}
private void setHTTPconfiguration(ConnectOptions options)
{
if (CommandLine.booleanValue("proxy"))
{
options.tunnelingInfo().HTTPproxy(true);
String proxyHost = CommandLine.value("ph");
if ( proxyHost == null)
{
System.err.println("Error: Proxy hostname not provided.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
String proxyPort = CommandLine.value("pp");
if ( proxyPort == null)
{
System.err.println("Error: Proxy port number not provided.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
options.tunnelingInfo().HTTPproxyHostName(proxyHost);
try
{
options.tunnelingInfo().HTTPproxyPort(Integer.parseInt(proxyPort));
}
catch(Exception e)
{
System.err.println("Error: Proxy port number not provided.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
}
channelSession.tunnelingConnectOptions(_tunnelingConnectOpts);
// credentials
if (options.tunnelingInfo().HTTPproxy())
{
setCredentials(options);
channelSession.credentialsConnectOptions(options);
}
}
/*
* For BASIC authentication we need: HTTPproxyUsername, HTTPproxyPasswd For
* NTLM authentication we need: HTTPproxyUsername, HTTPproxyPasswd,
* HTTPproxyDomain, HTTPproxyLocalHostname For Negotiate/Kerberos we need:
* HTTPproxyUsername, HTTPproxyPasswd, HTTPproxyDomain,
* HTTPproxyKRB5configFile
*/
private void setCredentials(ConnectOptions options)
{
String proxyUsername = CommandLine.value("plogin");
if ( proxyUsername == null)
{
System.err.println("Error: Proxy username not provided.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
String proxyPasswd = CommandLine.value("ppasswd");
if ( proxyPasswd == null)
{
System.err.println("Error: Proxy password not provided.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
String proxyDomain = CommandLine.value("pdomain");
if ( proxyDomain == null)
{
System.err.println("Error: Proxy domain not provided.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
options.credentialsInfo().HTTPproxyUsername(proxyUsername);
options.credentialsInfo().HTTPproxyPasswd(proxyPasswd);
options.credentialsInfo().HTTPproxyDomain(proxyDomain);
try
{
_localIPaddress = InetAddress.getLocalHost().getHostAddress();
_localHostName = InetAddress.getLocalHost().getHostName();
}
catch (UnknownHostException e)
{
_localHostName = _localIPaddress;
}
options.credentialsInfo().HTTPproxyLocalHostname(_localHostName);
String proxyKrbfile = CommandLine.value("krbfile");
if (proxyKrbfile == null)
{
System.err.println("Error: Proxy krbfile not provided.");
System.out.println("Consumer exits...");
System.exit(CodecReturnCodes.FAILURE);
}
options.credentialsInfo().HTTPproxyKRB5configFile(proxyKrbfile);
}
private boolean isMarketPriceArgSpecified()
{
return (CommandLine.hasArg("mp") ||
CommandLine.hasArg("mpps") ||
CommandLine.hasArg("mbp") ||
CommandLine.hasArg("mbpps") ||
CommandLine.hasArg("mbo") ||
CommandLine.hasArg("mbops") || CommandLine.hasArg("sl"));
}
private boolean isYieldCurveArgSpecified()
{
return (CommandLine.hasArg("yc") ||
CommandLine.hasArg("ycps"));
}
/**
* Call back method to process responses from channel. Processing responses
* consists of performing a high level decode of the message and then
* calling the applicable specific method for further processing.
* chnl - The channel of the response
* buffer - The message buffer containing the response.
*/
public void processResponse(ChannelSession chnl, TransportBuffer buffer)
{
// clear decode iterator
dIter.clear();
// set buffer and version info
dIter.setBufferAndRWFVersion(buffer, chnl.channel().majorVersion(), chnl.channel().minorVersion());
int ret = responseMsg.decode(dIter);
if (ret != CodecReturnCodes.SUCCESS)
{
System.out.println("\nDecodeMsg(): Error " + ret + " on SessionData Channel="
+ chnl.channel().selectableChannel() + " Size " + (buffer.data().limit() - buffer.data().position()));
closeChannel();
System.out.println("Consumer exits...");
System.exit(TransportReturnCodes.FAILURE);
}
processResponse(chnl, responseMsg, dIter);
}
private void processResponse(ChannelSession chnl, Msg responseMsg, DecodeIterator dIter)
{
switch (responseMsg.domainType())
{
case DomainTypes.LOGIN:
processLoginResp(chnl, responseMsg, dIter);
break;
case DomainTypes.SOURCE:
processSourceDirectoryResp(chnl, responseMsg);
break;
case DomainTypes.DICTIONARY:
processDictionaryResp(chnl, responseMsg, dIter);
checkAndInitPostingSupport();
break;
case DomainTypes.MARKET_PRICE:
processMarketPriceResp(responseMsg, dIter);
break;
case DomainTypes.MARKET_BY_ORDER:
processMarketByOrderResp(responseMsg, dIter);
break;
case DomainTypes.MARKET_BY_PRICE:
processMarketByPriceResp(responseMsg, dIter);
break;
case DomainTypes.SYMBOL_LIST:
processSymbolListResp(responseMsg, dIter);
break;
case DomainTypes.YIELD_CURVE:
processYieldCurveResp(responseMsg, dIter);
break;
default:
System.out.println("Unhandled Domain Type: " + responseMsg.domainType());
break;
}
}
private void processSymbolListResp(Msg responseMsg, DecodeIterator dIter)
{
if (symbolListHandler.processResponse(responseMsg, dIter, dictionaryHandler.dictionary()) != CodecReturnCodes.SUCCESS)
{
closeChannel();
System.err.println("Error processing response, exit.");
System.exit(TransportReturnCodes.FAILURE);
}
}
private void processMarketByPriceResp(Msg responseMsg, DecodeIterator dIter)
{
if (marketByPriceHandler.processResponse(responseMsg, dIter, dictionaryHandler
.dictionary(), error) != CodecReturnCodes.SUCCESS)
{
closeChannel();
System.err.println("Error processing marketByPrice response, exit.");
System.exit(TransportReturnCodes.FAILURE);
}
}
private void processMarketByOrderResp(Msg responseMsg, DecodeIterator dIter)
{
if (marketByOrderHandler.processResponse(responseMsg, dIter, dictionaryHandler
.dictionary(), error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error processing marketByOrder response, exit.");
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
}
private void processMarketPriceResp(Msg responseMsg, DecodeIterator dIter)
{
if (marketPriceHandler.processResponse(responseMsg, dIter, dictionaryHandler
.dictionary(), error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error processing marketPrice response, exit.");
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
}
private void processDictionaryResp(ChannelSession chnl, Msg responseMsg, DecodeIterator dIter)
{
if (dictionaryHandler.processResponse(chnl.channel(), responseMsg, dIter, error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error processing dictionary response, exit.");
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
if (dictionaryHandler.isFieldDictionaryLoaded() &&
dictionaryHandler.isEnumTypeDictionaryLoaded() &&
responseMsg.msgClass() == MsgClasses.REFRESH)
{
System.out.println("Dictionary ready, requesting item(s)...");
itemWatchList.clear();
sendMPRequests(chnl);
sendMBORequests(chnl);
sendMBPRequests(chnl);
sendSymbolListRequests(chnl);
sendYieldCurveRequests(chnl);
postHandler.enableOffstreamPost(shouldOffStreamPost);
postHandler.enableOnstreamPost(shouldOnStreamPost);
}
}
private void processSourceDirectoryResp(ChannelSession chnl, Msg responseMsg)
{
int ret = srcDirHandler.processResponse(chnl.channel(), responseMsg, dIter, error);
if (ret != CodecReturnCodes.SUCCESS)
{
System.err.println("Error processing source directory response, exit.");
System.out.println(error.text());
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
if (srcDirHandler.isRequestedServiceUp())
{
sendRequests(chnl);
}
else
{
// service not up or
// previously up service went down
requestsSent = false;
System.out.println("Requested service '" + CommandLine.value("s") + "' not up. Waiting for service to be up...");
}
}
private void processYieldCurveResp(Msg responseMsg, DecodeIterator dIter)
{
if (yieldCurveHandler.processResponse(responseMsg, dIter, dictionaryHandler
.dictionary(), error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error processing yieldCurve response, exit.");
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
}
private void sendRequests(ChannelSession chnl)
{
if (requestsSent)
return;
// first load dictionaries. send item requests and post
// messages only after dictionaries are loaded.
if (!isDictionariesLoaded())
{
if (srcDirHandler.serviceInfo().info().dictionariesProvidedList().size() > 0)
{
sendDictionaryRequests(chnl);
}
else
{
System.out.println("\nDictionary download not supported by the indicated provider");
}
return;
}
itemWatchList.clear();
sendMPRequests(chnl);
sendMBORequests(chnl);
sendMBPRequests(chnl);
sendSymbolListRequests(chnl);
sendYieldCurveRequests(chnl);
checkAndInitPostingSupport();
postHandler.enableOffstreamPost(shouldOffStreamPost);
postHandler.enableOnstreamPost(shouldOnStreamPost);
requestsSent = true;
}
private void sendDictionaryRequests(ChannelSession chnl)
{
dictionaryHandler.serviceId(srcDirHandler.serviceInfo().serviceId());
if (dictionaryHandler.sendRequests(chnl, error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error sending dictionary request, exit.");
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
}
private void sendSymbolListRequests(ChannelSession chnl)
{
if (!CommandLine.hasArg("sl"))
return;
if (!srcDirHandler.serviceInfo().checkHasInfo())
{
System.err.println("Error sending symbolList request, exit.");
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
Service.ServiceInfo info = srcDirHandler.serviceInfo().info();
if (info.qosList().size() > 0)
{
Qos qos = info.qosList().get(0);
symbolListHandler.qos().dynamic(qos.isDynamic());
symbolListHandler.qos().rate(qos.rate());
symbolListHandler.qos().timeliness(qos.timeliness());
}
else
{
symbolListHandler.qos().dynamic(false);
symbolListHandler.qos().rate(QosRates.TICK_BY_TICK);
symbolListHandler.qos().timeliness(QosTimeliness.REALTIME);
}
symbolListHandler.capabilities().addAll(info.capabilitiesList());
symbolListHandler.serviceId(srcDirHandler.serviceInfo().serviceId());
String cmdSLName = CommandLine.value("sl");
if (cmdSLName == null)
{
symbolListHandler.symbolListName().data(info.itemList().data(), info.itemList().position(), info.itemList().length());
}
else
{
symbolListHandler.symbolListName().data(cmdSLName);
}
if (symbolListHandler.sendRequest(chnl, error) != CodecReturnCodes.SUCCESS)
{
System.out.println(error.text());
System.err.println("Error sending symbolList request, exit...");
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
}
private void sendMBPRequests(ChannelSession chnl)
{
if (marketByPriceHandler.sendItemRequests(chnl, CommandLine.values("mbp"), false, loginHandler.refreshInfo(), srcDirHandler.serviceInfo(), error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error sending MBP request, exit.");
System.out.println(error.text());
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
if (CommandLine.hasArg("mbpps") && !mbppsRequestSent)
{
if (marketByPriceHandler.sendItemRequests(chnl, CommandLine.values("mbpps"), true, loginHandler.refreshInfo(), srcDirHandler.serviceInfo(), error) != CodecReturnCodes.SUCCESS)
{
System.out.println(error.text());
closeChannel();
System.out.println("Consumer exits...");
System.exit(TransportReturnCodes.FAILURE);
}
mbppsRequestSent = true;
}
}
private void sendMBORequests(ChannelSession chnl)
{
if (marketByOrderHandler.sendItemRequests(chnl, CommandLine.values("mbo"), false, loginHandler.refreshInfo(), srcDirHandler.serviceInfo(), error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error sending MBO request, exit.");
System.out.println(error.text());
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
if (CommandLine.hasArg("mbops") && !mbopsRequestSent)
{
if (marketByOrderHandler.sendItemRequests(chnl, CommandLine.values("mbops"), true, loginHandler.refreshInfo(), srcDirHandler.serviceInfo(), error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error sending MBO request, exit.");
System.out.println(error.text());
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
mbopsRequestSent = true;
}
}
private void sendMPRequests(ChannelSession chnl)
{
if (marketPriceHandler.sendItemRequests(chnl, CommandLine.values("mp"), false, loginHandler.refreshInfo(), srcDirHandler.serviceInfo(), error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error sending MP request, exit.");
System.out.println(error.text());
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
if (CommandLine.hasArg("mpps") && !mppsRequestSent)
{
if (marketPriceHandler.sendItemRequests(chnl, CommandLine.values("mpps"), true, loginHandler.refreshInfo(), srcDirHandler.serviceInfo(), error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error sending MP request, exit...");
System.out.println(error.text());
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
mppsRequestSent = true;
}
}
private void sendYieldCurveRequests(ChannelSession chnl)
{
if (yieldCurveHandler.sendItemRequests(chnl, CommandLine.values("yc"), false, loginHandler.refreshInfo(), srcDirHandler.serviceInfo(), error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error sending YC request, exit.");
System.out.println(error.text());
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
if (CommandLine.hasArg("ycps") && !ycpsRequestSent)
{
if (yieldCurveHandler.sendItemRequests(chnl, CommandLine.values("ycps"), true, loginHandler.refreshInfo(), srcDirHandler.serviceInfo(), error) != CodecReturnCodes.SUCCESS)
{
System.err.println("Error sending YC request, exit...");
System.out.println(error.text());
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
ycpsRequestSent = true;
}
}
private boolean isDictionariesLoaded()
{
return dictionaryHandler.isFieldDictionaryLoaded()
&& dictionaryHandler.isEnumTypeDictionaryLoaded();
}
private void checkAndInitPostingSupport()
{
if (!(shouldOnStreamPost || shouldOffStreamPost) || postInit)
return;
// set up posting if its enabled
// ensure that provider supports posting - if not, disable posting
if (!loginHandler.refreshInfo().checkHasFeatures() ||
!loginHandler.refreshInfo().features().checkHasSupportPost() ||
loginHandler.refreshInfo().features().supportOMMPost() == 0)
{
// provider does not support posting, disable it
shouldOffStreamPost = false;
shouldOnStreamPost = false;
postHandler.enableOnstreamPost(false);
postHandler.enableOffstreamPost(false);
System.out.println("Connected Provider does not support OMM Posting. Disabling Post functionality.");
return;
}
// This sets up our basic timing so post messages will be sent periodically
postHandler.initPostHandler();
// posting has been initialized
postInit = true;
}
private void processLoginResp(ChannelSession chnl, Msg responseMsg, DecodeIterator dIter)
{
int ret = loginHandler.processResponse(responseMsg, dIter, error);
if (ret != CodecReturnCodes.SUCCESS)
{
System.err.println("Error processing Login response, exit.");
System.out.println(error.text());
closeChannel();
System.exit(TransportReturnCodes.FAILURE);
}
// Handle login states
ConsumerLoginState loginState = loginHandler.loginState();
if (loginState == ConsumerLoginState.OK_SOLICITED)
{
if (!chnl.isLoginReissue)
{
//APIQA
System.err.println("....ReconnectClient....");
chnl.channel().reconnectClient(error);
//END APIQA
ret = srcDirHandler.sendRequest(chnl, error);
if (ret != CodecReturnCodes.SUCCESS)
{
System.out.println("Error sending directory request: " + error.text());
closeChannel();
System.out.println("Consumer exits...");
System.exit(TransportReturnCodes.FAILURE);
}
}
}
else if (loginState == ConsumerLoginState.CLOSED)
{
System.out.println(error.text());
closeChannel();
System.out.println("Consumer exits...");
System.exit(TransportReturnCodes.FAILURE);
}
else if (loginState == ConsumerLoginState.CLOSED_RECOVERABLE)
{
ret = channelSession.recoverConnection(error);
if (ret != CodecReturnCodes.SUCCESS)
{
System.out.println("Error recovering connection: " + error.text());
System.out.println("Consumer exits...");
System.exit(TransportReturnCodes.FAILURE);
}
}
else if (loginState == ConsumerLoginState.SUSPECT)
{
if (!loginHandler.refreshInfo().checkHasAttrib() || // default behavior when singleopen attrib not set
loginHandler.refreshInfo().attrib().singleOpen() == 0)
{
// login suspect from no single-open provider: 1) close source
// directory stream and item streams. 2) reopen streams
closeDictAndItemStreams();
// reopen directory stream, which in turn reopens other streams
// (dict, item streams)
ret = srcDirHandler.closeStream(channelSession, error);
if (ret != CodecReturnCodes.SUCCESS)
{
System.out.println("Error closing directory stream: " + error.text());
closeChannel();
System.out.println("Consumer exits...");
System.exit(TransportReturnCodes.FAILURE);
}
if (!chnl.isLoginReissue)
{
ret = srcDirHandler.sendRequest(chnl, error);
if (ret != CodecReturnCodes.SUCCESS)
{
System.out.println("Error sending directory request: " + error.text());
closeChannel();
System.out.println("Consumer exits...");
System.exit(TransportReturnCodes.FAILURE);
}
}
}
// login suspect from single-open provider: provider handles
// recovery. consumer does nothing in this case.
}
// get login reissue time from authenticationTTReissue
if (responseMsg.msgClass() == MsgClasses.REFRESH &&
loginHandler.refreshInfo().checkHasAuthenticationTTReissue())
{
chnl.loginReissueTime = loginHandler.refreshInfo().authenticationTTReissue() * 1000;
chnl.canSendLoginReissue = true;
}
}
private void closeDictAndItemStreams()
{
// have offstream posting post close status
postHandler.streamId(loginHandler.refreshInfo().streamId());
postHandler.postItemName().data("OFFPOST");
postHandler.serviceId(srcDirHandler.serviceInfo().serviceId());
postHandler.dictionary(dictionaryHandler.dictionary());
postHandler.closeOffStreamPost(channelSession, error);
// close item streams if opened
marketPriceHandler.closeStreams(channelSession, error);
marketByOrderHandler.closeStreams(channelSession, error);
marketByPriceHandler.closeStreams(channelSession, error);
symbolListHandler.closeStream(channelSession, error);
yieldCurveHandler.closeStreams(channelSession, error);
// close dictionary streams if opened
dictionaryHandler.closeStreams(channelSession, error);
}
/**
* Closes all streams for the consumer.
*/
public void uninitialize()
{
System.out.println("Consumer unitializing and exiting...");
if (channelSession.channel() == null)
{
channelSession.uninit(error);
System.out.println("Consumer exits...");
System.exit(TransportReturnCodes.SUCCESS);
}
// close all streams
closeDictAndItemStreams();
srcDirHandler.closeStream(channelSession, error);
// close login stream
loginHandler.closeStream(channelSession, error);
// flush before exiting
flushChannel();
closeChannel();
}
private void flushChannel()
{
int retval = 1;
while (retval > TransportReturnCodes.SUCCESS)
{
retval = channelSession.flush(error);
}
if (retval < TransportReturnCodes.SUCCESS)
{
System.out.println("Flush() failed with return code " + retval + "- <" + error
.text() + ">");
}
}
private void closeChannel()
{
channelSession.uninit(error);
}
private static void addCommandLineArgs()
{
CommandLine.programName("Consumer");
CommandLine.addOption("mp", "For each occurrence, requests item using Market Price domain.");
CommandLine.addOption("mpps", "For each occurrence, requests item using Market Price domain on private stream. Default is no market price private stream requests.");
CommandLine.addOption("mbo", "For each occurrence, requests item using Market By Order domain. Default is no market by order requests.");
CommandLine.addOption("mbops", "For each occurrence, requests item using Market By Order domain on private stream. Default is no market by order private stream requests.");
CommandLine.addOption("mbp", "For each occurrence, requests item using Market By Price domain. Default is no market by price requests.");
CommandLine.addOption("mbpps", "For each occurrence, requests item using Market By Price domain on private stream. Default is no market by price private stream requests.");
CommandLine.addOption("yc", "For each occurrence, requests item using Yield Curve domain. Default is no yield curve requests.");
CommandLine.addOption("ycps", "For each occurrence, requests item using Yield Curve domain on private stream. Default is no yield curve private stream requests.");
CommandLine.addOption("view", "Specifies each request using a basic dynamic view. Default is false.");
CommandLine.addOption("post", "Specifies that the application should attempt to send post messages on the first requested Market Price item (i.e., on-stream). Default is false.");
CommandLine.addOption("offpost", "Specifies that the application should attempt to send post messages on the login stream (i.e., off-stream).");
CommandLine.addOption("publisherInfo", "Specifies that the application should add user provided publisher Id and publisher ipaddress when posting");
CommandLine.addOption("snapshot", "Specifies each request using non-streaming. Default is false(i.e. streaming requests.)");
CommandLine.addOption("sl", "Requests symbol list using Symbol List domain. (symbol list name optional). Default is no symbol list requests.");
CommandLine.addOption("h", defaultSrvrHostname, "Server host name");
CommandLine.addOption("p", defaultSrvrPortNo, "Server port number");
CommandLine.addOption("i", (String)null, "Interface name");
CommandLine.addOption("s", defaultServiceName, "Service name");
CommandLine.addOption("uname", "Login user name. Default is system user name.");
CommandLine.addOption("connectionType", "Socket", "Specifies the connection type that the connection should use. Possible values are: 'Socket', 'http', 'encrypted'");
CommandLine.addOption("runtime", defaultRuntime, "Program runtime in seconds");
CommandLine.addOption("x", "Provides XML tracing of messages.");
CommandLine.addOption("proxy", "Specifies that the application will make a tunneling connection (http or encrypted) through a proxy server, default is false");
CommandLine.addOption("ph", "", "Proxy server host name");
CommandLine.addOption("pp", "", "Proxy port number");
CommandLine.addOption("plogin", "", "User Name on proxy server");
CommandLine.addOption("ppasswd", "", "Password on proxy server");
CommandLine.addOption("pdomain", "", "Proxy server domain");
CommandLine.addOption("krbfile", "", "KRB File location and name");
CommandLine.addOption("keyfile", "", "Keystore file location and name");
CommandLine.addOption("keypasswd", "", "Keystore password");
CommandLine.addOption("at", "", "Specifies the Authentication Token. If this is present, the login user name type will be Login.UserIdTypes.AUTHN_TOKEN.");
CommandLine.addOption("ax", "", "Specifies the Authentication Extended information.");
CommandLine.addOption("aid", "", "Specifies the Application ID.");
}
public static void main(String[] args) throws Exception
{
Consumer consumer = new Consumer();
consumer.init(args);
consumer.run();
consumer.uninitialize();
System.out.println("Consumer done");
}
}
|