MCPcopy Create free account
hub / github.com/akeranen/the-one / sortByQueueMode

Method sortByQueueMode

routing/MessageRouter.java:504–545  ·  view source on GitHub ↗

Sorts/shuffles the given list according to the current sending queue mode. The list can contain either Message or Tuple objects. Other objects cause error. @param list The list to sort or shuffle @return The sorted/shuffled list

(List list)

Source from the content-addressed store, hash-verified

502 * @return The sorted/shuffled list
503 */
504 @SuppressWarnings(value = "unchecked") /* ugly way to make this generic */
505 protected List sortByQueueMode(List list) {
506 switch (sendQueueMode) {
507 case Q_MODE_RANDOM:
508 Collections.shuffle(list, new Random(SimClock.getIntTime()));
509 break;
510 case Q_MODE_FIFO:
511 Collections.sort(list,
512 new Comparator() {
513 /** Compares two tuples by their messages' receiving time */
514 public int compare(Object o1, Object o2) {
515 double diff;
516 Message m1, m2;
517
518 if (o1 instanceof Tuple) {
519 m1 = ((Tuple<Message, Connection>)o1).getKey();
520 m2 = ((Tuple<Message, Connection>)o2).getKey();
521 }
522 else if (o1 instanceof Message) {
523 m1 = (Message)o1;
524 m2 = (Message)o2;
525 }
526 else {
527 throw new SimError("Invalid type of objects in " +
528 "the list");
529 }
530
531 diff = m1.getReceiveTime() - m2.getReceiveTime();
532 if (diff == 0) {
533 return 0;
534 }
535 return (diff < 0 ? -1 : 1);
536 }
537 });
538 break;
539 /* add more queue modes here */
540 default:
541 throw new SimError("Unknown queue mode " + sendQueueMode);
542 }
543
544 return list;
545 }
546
547 /**
548 * Gives the order of the two given messages as defined by the current

Callers 3

updateMethod · 0.80

Calls 1

getIntTimeMethod · 0.95

Tested by

no test coverage detected