File size: 21,495 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 |
package com.thomsonreuters.upa.valueadd.examples.watchlistconsumer;
import java.util.ArrayList;
import java.util.List;
import com.thomsonreuters.upa.codec.Array;
import com.thomsonreuters.upa.codec.ArrayEntry;
import com.thomsonreuters.upa.codec.Buffer;
import com.thomsonreuters.upa.codec.CodecFactory;
import com.thomsonreuters.upa.codec.CodecReturnCodes;
import com.thomsonreuters.upa.codec.DataTypes;
import com.thomsonreuters.upa.codec.ElementEntry;
import com.thomsonreuters.upa.codec.ElementList;
import com.thomsonreuters.upa.codec.EncodeIterator;
import com.thomsonreuters.upa.codec.Int;
import com.thomsonreuters.upa.codec.MsgClasses;
import com.thomsonreuters.upa.codec.Qos;
import com.thomsonreuters.upa.codec.RequestMsg;
import com.thomsonreuters.upa.codec.RequestMsgFlags;
import com.thomsonreuters.upa.codec.UInt;
import com.thomsonreuters.upa.shared.rdm.marketprice.MarketPriceRequestFlags;
import com.thomsonreuters.upa.rdm.DomainTypes;
import com.thomsonreuters.upa.rdm.ElementNames;
import com.thomsonreuters.upa.rdm.InstrumentNameTypes;
import com.thomsonreuters.upa.rdm.SymbolList;
import com.thomsonreuters.upa.rdm.ViewTypes;
public class ItemRequest
{
private List<String> itemNames;
private int streamId;
private Qos qos;
private Qos worstQos;
private int priorityClass;
private int priorityCount;
private int serviceId;
private int identifier;
private List<Integer> viewFieldList;
private List<String> viewElementNameList;
private int domainType;
private int flags;
private boolean isSymbolListData;
public static final Buffer VIEW_TYPE = CodecFactory.createBuffer();
/** :ViewData */
public static final Buffer VIEW_DATA = CodecFactory.createBuffer();
RequestMsg requestMsg = (RequestMsg)CodecFactory.createMsg();
private ElementList elementList = CodecFactory.createElementList();
private ElementList behaviorList = CodecFactory.createElementList();
private ElementEntry elementEntry = CodecFactory.createElementEntry();
private ElementEntry dataStreamEntry = CodecFactory.createElementEntry();
private Array array = CodecFactory.createArray();
private ArrayEntry arrayEntry = CodecFactory.createArrayEntry();
private Buffer itemNameBuf = CodecFactory.createBuffer();
private Int tempInt = CodecFactory.createInt();
private UInt tempUInt = CodecFactory.createUInt();
private Buffer elementNameBuf = CodecFactory.createBuffer();
private Array viewArray = CodecFactory.createArray();
public ItemRequest()
{
this(DomainTypes.MARKET_PRICE);
this.isSymbolListData = false;
}
public ItemRequest(int domainType)
{
qos = CodecFactory.createQos();
worstQos = CodecFactory.createQos();
itemNames = new ArrayList<String>();
priorityClass = 1;
priorityCount = 1;
flags = 0;
identifier = -1;
this.domainType = domainType;
}
public int streamId()
{
return streamId;
}
public void streamId(int streamId)
{
this.streamId = streamId;
}
public void symbolListData(boolean isSymbolListData)
{
this.isSymbolListData = isSymbolListData;
}
/**
* Clears the current contents of this object and prepares it for re-use.
*/
public void clear()
{
flags = 0;
qos.clear();
worstQos.clear();
itemNames.clear();
priorityClass = 1;
priorityCount = 1;
identifier = -1;
isSymbolListData = false;
if (viewFieldList != null)
viewFieldList.clear();
if (viewElementNameList != null)
viewElementNameList.clear();
}
/**
* Checks the presence of private stream flag.
*
* @return true - if exists; false if does not exist.
*/
public boolean checkPrivateStream()
{
return (flags & MarketPriceRequestFlags.PRIVATE_STREAM) != 0;
}
/**
* Applies private stream flag.
*/
public void applyPrivateStream()
{
flags |= MarketPriceRequestFlags.PRIVATE_STREAM;
}
/**
*
* @return service id
*/
public int serviceId()
{
return serviceId;
}
/**
* @param serviceId
*/
public ItemRequest serviceId(int serviceId)
{
this.serviceId = serviceId;
return this;
}
/**
*
* @return list of item names
*/
public List<String> itemNames()
{
return itemNames;
}
/**
*
* @param itemNames list of item names
*/
public void itemNames(List<String> itemNames)
{
this.itemNames = itemNames;
}
/**
*
* @param itemName item name
*/
public void addItem(String itemName)
{
itemNames.add(itemName);
}
/**
*
* @return priority class used by request
*/
public int priorityClass()
{
return priorityClass;
}
/**
*
* @return priority count used by request
*/
public int priorityCount()
{
return priorityCount;
}
/**
*
* @param priorityClass
* @param priorityCount
*
*/
public void priority(int priorityClass, int priorityCount)
{
this.priorityClass = priorityClass;
this.priorityCount = priorityCount;
}
/**
* Checks the presence of streaming.
*
* @return true - if exists; false if does not exist.
*/
public boolean checkStreaming()
{
return (flags & MarketPriceRequestFlags.STREAMING) != 0;
}
/**
* Applies streaming flag.
*/
public void applyStreaming()
{
flags |= MarketPriceRequestFlags.STREAMING;
}
/**
* Checks the presence of Qos.
*
* @return true - if exists; false if does not exist.
*/
public boolean checkHasQos()
{
return (flags & MarketPriceRequestFlags.HAS_QOS) != 0;
}
/**
* Applies Qos flag.
*/
public void applyHasQos()
{
flags |= MarketPriceRequestFlags.HAS_QOS;
}
/**
* Checks the presence of WorstQos.
*
* @return true - if exists; false if does not exist.
*/
public boolean checkHasWorstQos()
{
return (flags & MarketPriceRequestFlags.HAS_WORST_QOS) != 0;
}
/**
* Applies WorstQos flag.
*/
public void applyHasWorstQos()
{
flags |= MarketPriceRequestFlags.HAS_WORST_QOS;
}
/**
* Checks the presence of Priority flag.
*
* @return true - if exists; false if does not exist.
*/
public boolean checkHasPriority()
{
return (flags & MarketPriceRequestFlags.HAS_PRIORITY) != 0;
}
/**
* Applies Priority flag.
*/
public void applyHasPriority()
{
flags |= MarketPriceRequestFlags.HAS_PRIORITY;
}
/**
* Applies View flag.
*/
public void applyHasView()
{
flags |= MarketPriceRequestFlags.HAS_VIEW;
}
/**
* Applies Pause flag.
*/
public void applyPause()
{
flags |= RequestMsgFlags.PAUSE;
}
// APIQA: apply/check NoRefresh flag methods
public void applyNoRefresh()
{
flags |= 0x2000;
}
public boolean checkHasNoRefresh()
{
return (flags & 0x2000) != 0;
}
// END APIQA
/**
* Checks the presence of Pause.
*
* @return true - if exists; false if does not exist.
*/
public boolean checkHasPause()
{
return (flags & RequestMsgFlags.PAUSE) != 0;
}
/**
* Checks the presence of View flag.
*
* @return true - if exists; false if does not exist.
*/
public boolean checkHasView()
{
return (flags & MarketPriceRequestFlags.HAS_VIEW) != 0;
}
/**
*
* @return Qos used by request
*/
public Qos qos()
{
return qos;
}
/**
*
* @return WorstQos used by request
*/
public Qos worstQos()
{
return worstQos;
}
/**
*
* @return list of view fields
*/
public List<Integer> viewFields()
{
return viewFieldList;
}
/**
*
* @return list of view elementNames
*/
public List<String> viewElementNames()
{
return viewElementNameList;
}
/**
*
* @param viewList list of view fields
*/
public void viewFields(List<Integer> viewList)
{
viewFieldList = viewList;
}
/**
*
* @param elementNameList list of element names
*/
public void viewElementNames(List<String> elementNameList)
{
viewElementNameList = elementNameList;
}
/**
* Checks the presence of service id flag.
* @return true - if exists; false if does not exist.
*/
public boolean checkHasServiceId()
{
return (flags & MarketPriceRequestFlags.HAS_SERVICE_ID) != 0;
}
/**
* Applies service id flag.
*/
public void applyHasServiceId()
{
flags |= MarketPriceRequestFlags.HAS_SERVICE_ID;
}
/**
*
* @return Domain type
*/
public int domainType()
{
return domainType;
}
/**
*
* @param domainType Domain type
*/
public void domainType(int domainType)
{
this.domainType = domainType;
}
/**
* Set the identifier for the msg Key
*/
public void identifier(int setIdentifier)
{
identifier = setIdentifier;
}
/**
* @return Identifier
*/
public int identifier()
{
return identifier;
}
/**
* Checks the presence of an identifier
* @return true - if exists; false if does not exist;
*/
public boolean checkHasIdentifier()
{
if (identifier >= 0)
return true;
else
return false;
}
public void encode()
{
requestMsg.clear();
/* set-up message */
requestMsg.msgClass(MsgClasses.REQUEST);
requestMsg.streamId(streamId());
requestMsg.domainType(domainType);
requestMsg.containerType(DataTypes.NO_DATA);
if (checkHasQos())
{
requestMsg.applyHasQos();
requestMsg.qos().dynamic(qos.isDynamic());
requestMsg.qos().rate(qos.rate());
requestMsg.qos().timeliness(qos.timeliness());
requestMsg.qos().rateInfo(qos.rateInfo());
requestMsg.qos().timeInfo(qos.timeInfo());
}
if (checkHasWorstQos())
{
requestMsg.applyHasWorstQos();
requestMsg.worstQos().dynamic(worstQos.isDynamic());
requestMsg.worstQos().rate(worstQos.rate());
requestMsg.worstQos().timeliness(worstQos.timeliness());
requestMsg.worstQos().rateInfo(worstQos.rateInfo());
requestMsg.worstQos().timeInfo(worstQos.timeInfo());
}
if (checkHasPriority())
{
requestMsg.applyHasPriority();
requestMsg.priority().priorityClass(priorityClass());
requestMsg.priority().count(priorityCount());
}
if (checkStreaming())
{
requestMsg.applyStreaming();
}
if (checkHasPause())
{
requestMsg.applyPause();
}
// APIQA: apply NoRefresh flag on requestMsg if set
if (checkHasNoRefresh())
{
requestMsg.applyNoRefresh();
}
// END APIQA
boolean isBatchRequest = itemNames.size() > 1;
applyFeatureFlags(isBatchRequest);
/* specify msgKey members */
requestMsg.msgKey().applyHasNameType();
requestMsg.msgKey().nameType(InstrumentNameTypes.RIC);
/* If user set Identifier */
if (checkHasIdentifier())
{
requestMsg.msgKey().applyHasIdentifier();
requestMsg.msgKey().identifier(identifier);
}
if (!isBatchRequest && !checkHasIdentifier())
{
requestMsg.msgKey().applyHasName();
requestMsg.msgKey().name().data(itemNames.get(0));
}
}
/**
* Encodes the item request.
*
* @param encodeIter The Encode Iterator
* @return {@link CodecReturnCodes#SUCCESS} if encoding succeeds or failure
* if encoding fails.
*
* This method is only used within the Market By Price Handler and
* each handler has its own implementation, although much is similar
*/
public int encode(EncodeIterator encodeIter)
{
boolean isBatchRequest = itemNames.size() > 1;
int ret = CodecReturnCodes.SUCCESS;
encode();
/* encode request message payload */
if (checkHasView() || isSymbolListData || isBatchRequest)
{
ret = encodeRequestPayload(isBatchRequest, encodeIter);
if (ret < CodecReturnCodes.SUCCESS)
return ret;
}
return CodecReturnCodes.SUCCESS;
}
private int encodeRequestPayload(boolean isBatchRequest, EncodeIterator encodeIter)
{
elementList.clear();
elementList.applyHasStandardData();
int ret = elementList.encodeInit(encodeIter, null, 0);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
if (isBatchRequest && (encodeBatchRequest(encodeIter) < CodecReturnCodes.SUCCESS))
{
return CodecReturnCodes.FAILURE;
}
if (checkHasView())
{
if (viewFieldList != null && viewFieldList.size() > 0)
{
if (encodeViewRequest(encodeIter, ViewTypes.FIELD_ID_LIST) < CodecReturnCodes.SUCCESS)
{
return CodecReturnCodes.FAILURE;
}
}
else if (viewElementNameList != null && viewElementNameList.size() > 0)
{
if (encodeViewRequest(encodeIter, ViewTypes.ELEMENT_NAME_LIST) < CodecReturnCodes.SUCCESS)
{
return CodecReturnCodes.FAILURE;
}
}
}
if (isSymbolListData && (encodeSymbolListData(encodeIter) < CodecReturnCodes.SUCCESS))
{
return CodecReturnCodes.FAILURE;
}
ret = elementList.encodeComplete(encodeIter, true);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
return CodecReturnCodes.SUCCESS;
}
private void applyFeatureFlags(boolean isBatchRequest)
{
if (checkPrivateStream())
{
requestMsg.applyPrivateStream();
}
if (checkHasView() || isSymbolListData || isBatchRequest)
{
requestMsg.containerType(DataTypes.ELEMENT_LIST);
if (checkHasView())
{
requestMsg.applyHasView();
}
if (isBatchRequest)
{
requestMsg.applyHasBatch();
}
}
}
private int encodeBatchRequest(EncodeIterator encodeIter)
{
/*
* For Batch requests, the message has a payload of an element list that
* contains an array of the requested items
*/
elementEntry.clear();
array.clear();
itemNameBuf.clear();
elementEntry.name(ElementNames.BATCH_ITEM_LIST);
elementEntry.dataType(DataTypes.ARRAY);
int ret = elementEntry.encodeInit(encodeIter, 0);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
/* Encode the array of requested item names */
array.primitiveType(DataTypes.ASCII_STRING);
array.itemLength(0);
ret = array.encodeInit(encodeIter);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
for (String itemName : itemNames)
{
arrayEntry.clear();
itemNameBuf.data(itemName);
ret = arrayEntry.encode(encodeIter, itemNameBuf);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
}
ret = array.encodeComplete(encodeIter, true);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
ret = elementEntry.encodeComplete(encodeIter, true);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
return CodecReturnCodes.SUCCESS;
}
/*
* Encodes the View Element Entry. This entry contains an array of FIDs that
* the consumer wishes to receive from the provider.
*
* This method is only used within the Market Price Handler
*/
private int encodeViewRequest(EncodeIterator encodeIter, int viewType)
{
elementEntry.clear();
tempUInt.clear();
elementEntry.name(ElementNames.VIEW_TYPE);
elementEntry.dataType(DataTypes.UINT);
if (viewType == ViewTypes.FIELD_ID_LIST)
tempUInt.value(ViewTypes.FIELD_ID_LIST);
else
tempUInt.value(ViewTypes.ELEMENT_NAME_LIST);
int ret = elementEntry.encode(encodeIter, tempUInt);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
elementEntry.clear();
elementEntry.name(ElementNames.VIEW_DATA);
elementEntry.dataType(DataTypes.ARRAY);
if ((ret = elementEntry.encodeInit(encodeIter, 0)) < CodecReturnCodes.SUCCESS)
{
return ret;
}
if (viewType == ViewTypes.FIELD_ID_LIST)
{
viewArray.primitiveType(DataTypes.INT);
viewArray.itemLength(2);
}
else
viewArray.primitiveType(DataTypes.ASCII_STRING);
if ((ret = viewArray.encodeInit(encodeIter)) < CodecReturnCodes.SUCCESS)
{
return ret;
}
if (viewType == ViewTypes.FIELD_ID_LIST)
{
for (Integer viewField : viewFieldList)
{
arrayEntry.clear();
tempInt.value(viewField);
ret = arrayEntry.encode(encodeIter, tempInt);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
}
}
else
{
for (String elementName : viewElementNameList)
{
arrayEntry.clear();
elementNameBuf.data(elementName);
ret = arrayEntry.encode(encodeIter, elementNameBuf);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
}
}
ret = viewArray.encodeComplete(encodeIter, true);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
ret = elementEntry.encodeComplete(encodeIter, true);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
return CodecReturnCodes.SUCCESS;
}
public int encodeSymbolListData(EncodeIterator encodeIter)
{
int ret = CodecReturnCodes.SUCCESS;
elementEntry.clear();
elementEntry.name(SymbolList.ElementNames.SYMBOL_LIST_BEHAVIORS);
elementEntry.dataType(DataTypes.ELEMENT_LIST);
ret = elementEntry.encodeInit(encodeIter, 0);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
behaviorList.clear();
behaviorList.applyHasStandardData();
ret = behaviorList.encodeInit(encodeIter, null, 0);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
dataStreamEntry.clear();
dataStreamEntry.name(SymbolList.ElementNames.SYMBOL_LIST_DATA_STREAMS);
dataStreamEntry.dataType(DataTypes.UINT);
if (checkStreaming())
tempUInt.value(SymbolList.SymbolListDataStreamRequestFlags.SYMBOL_LIST_DATA_STREAMS);
else
tempUInt.value(SymbolList.SymbolListDataStreamRequestFlags.SYMBOL_LIST_DATA_SNAPSHOTS);
if ((ret = dataStreamEntry.encode(encodeIter, tempUInt)) < CodecReturnCodes.SUCCESS)
{
return ret;
}
ret = behaviorList.encodeComplete(encodeIter, true);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
ret = elementEntry.encodeComplete(encodeIter, true);
if (ret < CodecReturnCodes.SUCCESS)
{
return ret;
}
return CodecReturnCodes.SUCCESS;
}
}
|