BubbleHProcess onConnect method


/ Published in: Java
Save to your folder(s)

onConnect method used by the BubbleHProcess in the ContactSim simulator.


Copy this code and paste it in your HTML
  1. public void onConnect(Process p, Simulation s) {
  2. // do the business
  3. List<BubbleHMessage> toSend = new LinkedList<BubbleHMessage>();
  4. BubbleHProcess process = (BubbleHProcess) p;
  5.  
  6. // on N connected with encountered node P
  7. // for each message M (for destination D) in buffer of N
  8. // Identify bridging community (BC), smallest community containing N and
  9. // D.
  10. // IF P == D
  11. // then pass the message
  12. // ELSE IF P shares a community with D that is smaller than BC
  13. // then pass the message.
  14. // ELSE IF P is more central in BC than N
  15. // then pass the message.
  16.  
  17. String hopcode = null;
  18. // foreach message in my buffer
  19. for (BubbleHMessage message : my_buffer) {
  20.  
  21. /**
  22. * Identify smallest community that Self and Destination share =
  23. * Bridging Community
  24. * */
  25. int my_bridge_community = my_oracle.bridgeCommunity(my_node.getID(), message.dest);
  26. //int his_bridge_community = BubbleHeirarchyOracle.bridgeCommunity(process.getNode().getID(), message.dest, my_properties);
  27.  
  28. // if encountered node is destination
  29. if (process.getNode().getID() == message.dest) {
  30. // pass it on to them.
  31. toSend.add(message);
  32. } else {
  33. int remote_bridge = my_oracle.bridgeCommunity(process.getNode().getID(), message.dest);
  34. if (my_oracle.isBetter(remote_bridge, my_bridge_community)) {
  35. // if P is in community with message.dest, that is smaller
  36. // than BC
  37. // pass message
  38. toSend.add(message);
  39.  
  40. } else if (process.getCommunities().contains(my_bridge_community)) {// if both nodes are in the bridge community
  41.  
  42. // if the rank of the encountered node is higher, pass the message
  43. if (process.getlocalRank(my_bridge_community) > getlocalRank(my_bridge_community)) {
  44. // pass message
  45. toSend.add(message);
  46. message.setHopCode("RANKBC-" + my_bridge_community);
  47. bridge_community_ranking_message_passed++;
  48. }
  49. } else {
  50. // process is not destination, is not in a smaller community
  51. // with the destination, and is not in the bridge community,
  52. // therefore we do not pass the message to it
  53. }
  54. }
  55.  
  56. }
  57. for (BubbleHMessage message : toSend) {
  58. my_transmittedCount++;
  59. message.hopCount++;
  60. s.sendMessage(this, process, message);
  61. my_buffer.remove(message); // not sure if this is strictly part of
  62. // BubbleRap, however to get anything like
  63. // the cost figures they quote, it seems
  64. // like the only way!
  65. }
  66. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.