Exemple #1
0
  def setup_mcast(self):
    self.groups = {}
    nodes_keys = self.nodes.keys()
    nodes_keys.sort()
    # Populate <code>groups</code> with metadata of groups which the 
    # current process is part of.
    # gid(key) : unique group ID of the group (globally unique)
    # mid : member ID of the current process in the group (group-wise unique)
    # members : group members (names) in sorted order
    for owner, members in self.group_owners.iteritems():
      members.sort()
      if self.local_name in members:
        gid = nodes_keys.index(owner)
        mid = members.index(self.local_name)
        self.groups[gid] = {
          'members' : members,
          'mid' : mid,
        }

    # More metadata
    for gid,g in self.groups.iteritems():
      g['mcast_id'] = 1
      g['latest_seqids_nodes'] = {}
      for k in g['members']:
        g['latest_seqids_nodes'][k] = 0
      g['hold_back_queue'] = []
      g['mcast_msgs_sent'] = {}
      # Initialize multicast clock service
      cs_factory = ClockServiceFactory()
      cs_factory.set_nodes(len(g['members'])) # No. of nodes in the group
      cs_factory.set_host_node_id(g['mid']) # Member ID for *this* process
      g['mcast_vector_clock'] = cs_factory.get_clock("VECTOR")

    # Reference to group owned by this process
    self.mcast_group = self.groups[self.nid]

    # Hold back queue required for causal ordering of message delivery
    self.co_hold_back_queue = []

    # Event to notify of new messages on hold back queue for causal ordering
    self.new_messages_event = threading.Event()
Exemple #2
0
  if len(sys.argv) == 3:
    config_filename = sys.argv[1]
    local_name = sys.argv[2]
    mp = MessagePasser(config_filename, local_name)
    mp.update_config()

    # Update K
    K = len(mp.mcast_group['members'])

    # Initialize the clock service here
    # Should be done AFTER update_config() on MessagePasser
    cs_factory = ClockServiceFactory()
    cs_factory.set_nodes(len(mp.nodes)) # No. of nodes in the system
    cs_factory.set_host_node_id(mp.nid) # ID for *this* process
    # Uncomment for Vector Clock
    cs = cs_factory.get_clock("VECTOR")
    
    # Inject Clock Service into MessagePasser
    mp.set_clockservice(cs)

    # Start server thread(s)
    send_msgs_thread = threading.Thread(name="send_msgs_thread", target=mp.process_send_queue)
    recv_msgs_thread = threading.Thread(name="recv_msgs_thread", target=mp.receive_message)
    mcast_recv_msgs_thread = threading.Thread(name="mcast_recv_msgs_thread", target=mp.mcast_receive)
    co_deliver_msgs_thread = threading.Thread(name="co_deliver_msgs_thread", target=mp.co_deliver)
    send_msgs_thread.start()
    recv_msgs_thread.start()
    mcast_recv_msgs_thread.start()
    co_deliver_msgs_thread.start()

    # Start thread to process application messages received
Exemple #3
0
from clockservice import ClockServiceFactory

if __name__ == "__main__":
    if len(sys.argv) == 3:
        config_filename = sys.argv[1]
        local_name = sys.argv[2]
        mp = MessagePasser(config_filename, local_name)
        mp.update_config()

        # Initialize the clock service here
        # Should be done AFTER update_config() on MessagePasser
        cs_factory = ClockServiceFactory()
        cs_factory.set_nodes(len(mp.nodes))  # No. of nodes in the system
        cs_factory.set_host_node_id(mp.nid)  # ID for *this* process
        # Logical Clock
        cs = cs_factory.get_clock("LOGICAL")
        # Uncomment for Vector Clock
        # cs = cs_factory.get_clock("VECTOR")

        # Inject Clock Service into MessagePasser
        mp.set_clockservice(cs)

        # Start server thread listening to messages
        listen_thread = threading.Thread(name="listen_thread", target=mp.receive_message)
        listen_thread.start()

        CLIENT_PROMPT = "[&]"

        while True:
            try:
                inp = raw_input(CLIENT_PROMPT)