Ejemplo n.º 1
0
def set_up_spread_peer():
    '''
    Set up Spread utility for Spread peer
    @return Tuple of (Spread mailbox, Spread message object for sending, 
        Spread message object for receiving, group list of the mailbox)
    '''

    # Register the signal timeout handler
    signal.signal(signal.SIGALRM, timeout_handler)

    group_list = spread.GroupList()
    group_list.add(params.SPREAD_GROUP_NAME)

    try:
        mbox = spread.Mailbox(params.SPREAD_DAEMON_PORT, "vyan1_mbox", False,
                              0)
    except spread.Error as error:
        error._print()
        raise error
    mbox.join(params.SPREAD_GROUP_NAME)
    mbox.add_group(params.SPREAD_GROUP_NAME)

    send_MSG = spread.Message()
    rcv_MSG = spread.Message()
    service = spread.Message.Reliable | spread.Message.SelfDiscard
    send_MSG.set_service(service)

    return (mbox, send_MSG, rcv_MSG, group_list)
Ejemplo n.º 2
0
  def test_receive_message(self):
    data = "foobar"

    groups = spread.GroupList()
    padding = spread.Message()

    self.mbox.clear_groups()
    self.mbox.clear_message_parts()
    self.mbox.add_group(self.rmbox.private_group())
    self.mbox.add_message_part(data)
    self.mbox.send()

    self.rmbox.clear_groups()
    self.rmbox.clear_message_parts()
    self.rmbox.add_message_part(self.message)
    self.rmbox.add_message_part(padding)

    padding.resize(padding.capacity())
    self.assertTrue(padding.size() > 0)

    bytes = self.rmbox.receive()
    self.rmbox.copy_groups(groups)

    self.assertEqual(0, padding.size())
    self.assertEqual(len(data) + 1, bytes)
    self.assertEqual(len(data) + 1, self.message.size())
    self.assertEqual(data, self.message.read(len(data) + 1))
    self.assertEqual(self.rmbox.private_group(), groups.group(0))
    self.assertEqual(self.mbox.private_group(), self.message.sender())
Ejemplo n.º 3
0
  def test_scatter_send(self):
    sm = spread.ScatterMessage()
    m  = spread.Message()

    self.join()

    self.message.write("test_scatter_send")
    m.write("test_scatter_send2")

    self.assertTrue(sm.add(self.message))
    self.assertTrue(sm.add(m))
    self.mbox.send(sm, MailboxTest.TestGroupName)

    self.mbox.clear_groups()
    self.mbox.add_group(MailboxTest.TestGroupName)
    self.mbox.clear_message_parts()

    # If you add a straight data message part, you must make sure
    # it does not get garbage-collected before the s.
    s1 = "test_scatter_send3"
    self.assertTrue(self.mbox.add_message_part(s1))
    s2 = "test_scatter_send4"
    self.assertTrue(self.mbox.add_message_part(s2))
    self.mbox.send()

    self.leave()
Ejemplo n.º 4
0
  def setUp(self):
    try:
      self.mbox = spread.Mailbox(MailboxTest.TestDaemon, "", True, 0)
      self.rmbox = spread.Mailbox(MailboxTest.TestDaemon)
    except spread.Error as error:
      error._print()
      raise error

    self.message = spread.Message()
Ejemplo n.º 5
0
  def test_scatter_group_send(self):
    groups = spread.GroupList()
    sm = spread.ScatterMessage()
    m = spread.Message()

    groups.add(MailboxTest.TestGroupName)
    groups.add(MailboxTest.TestGroupName2)

    self.join()
    self.message.write("test_scatter_group_send")
    m.write("test_scatter_group_send2")
    sm.add(self.message)
    sm.add(m)
    self.mbox.send(sm, groups)
    self.leave()
Ejemplo n.º 6
0
def set_up_start_spread():
    '''
    Set up Spread utility for start_spread program
    @return (Spread mailbox, Spread message object for sending)
    '''

    try:
        mbox = spread.Mailbox(params.SPREAD_DAEMON_PORT, "start_spread", False,
                              0)
    except spread.Error as error:
        error._print()
        raise error
    mbox.add_group(params.SPREAD_GROUP_NAME)

    send_MSG = spread.Message()
    service = spread.Message.Reliable | spread.Message.SelfDiscard
    send_MSG.set_service(service)

    return (mbox, send_MSG)
Ejemplo n.º 7
0
'''
Signaling program to start multicast process for all MNIST peers

Author: Yuan Jing Vincent Yan ([email protected])
'''
import spread
import params

if __name__ == '__main__':
    try:
        mbox = spread.Mailbox(params.SPREAD_DAEMON_PORT, "start_spread", False,
                              0)
    except spread.Error as error:
        error._print()
        raise error

    send_msg = spread.Message()
    service = spread.Message.Reliable | spread.Message.SelfDiscard
    send_msg.set_service(service)

    mbox.add_group(params.SPREAD_GROUP_NAME)
    send_msg.write(params.START_SPREAD_SIGNAL)
    mbox.send(send_msg)
    print("start_mcast: Let the show begin!")
Ejemplo n.º 8
0
import sys
import spread

group_name = "JHU_VDL"
group_list = spread.GroupList()
group_list.add(group_name)

try:
    mbox = spread.Mailbox("4803", "", False, 0)
except spread.Error as error:
    error._print()
    raise error
message = spread.Message()
rcv_msg = spread.Message()

data = "foobar"
service = spread.Message.Reliable | spread.Message.SelfDiscard
#message.set_service(service)

mbox.clear_groups()
mbox.clear_message_parts()
mbox.join(group_name)  #

mbox.add_group(group_name)
message.write(data)
mbox.send(message)

while mbox.poll() == 0:
    pass
print 'poll ', mbox.poll()
#mbox.send(message, group_list)
Ejemplo n.º 9
0
 def setUp(self):
     self.message = spread.Message()