Exemplo n.º 1
0
class Sender(Link):

  def __init__(self, connection, name, target):
    Link.__init__(self, connection)
    self.proto = ProtoSender(name, None, target)

  @synchronized
  def send(self, message=None, delivery_tag=None, txn=None, **kwargs):
    self.wait(self.capacity)
    if message:
      kwargs["message_format"] = 0
      kwargs["payload"] = encode(message)
      if delivery_tag is None:
        delivery_tag = message.delivery_tag
    if txn is not None:
      kwargs["state"] = TransactionalState(Binary(txn))
    return self.proto.send(delivery_tag=delivery_tag, **kwargs)
Exemplo n.º 2
0
Arquivo: test.py Projeto: grkvlt/amqp
def connection():
  from connection import Connection
  from session import Session
  from link import Sender, Receiver, link
  from protocol import Fragment, Linkage

  a = Connection(lambda n: Session(n, link))
  b = Connection(lambda n: Session(n, link))
  a.id = "A"
  a.tracing = set(["ops", "err"])
  b.id = "B"
  b.tracing = set(["ops", "err"])

  def pump():
    while a.pending() or b.pending():
      b.write(a.read())
      a.write(b.read())

  s = Session("test-ssn", link)
  a.add(s)
  s2 = Session("test-ssn2", link)
  a.add(s2)

  a.open(hostname="asdf")
  b.open()
  s.begin()
  s2.begin()
  l = Sender("qwer", local=Linkage("S", "T"))
  s.add(l)
  l.attach()

  pump()

  bssn = [x for x in b.incoming.values() if x.name == "test-ssn"][0]
  bssn.begin()
  bl = bssn.links["qwer"]
  bl.attach()
  bl.flow(10)

  pump()

  l.settle(l.send(fragments=Fragment(True, True, 0, 0, "asdf")))
  tag = l.send(delivery_tag="blah", fragments=Fragment(True, True, 0, 0, "asdf"))

  pump()

  ln = bssn.links["qwer"]
  x = ln.get()
  print "INCOMING XFR:", x
  ln.disposition(x.delivery_tag, "ACCEPTED")

  xfr = ln.get()
  print "INCOMING XFR:", xfr
  ln.disposition(xfr.delivery_tag, "ASDF")

  print "--"

  pump()

  print "--"

  print "DISPOSITION", l.get_remote(modified=True)
  l.settle(tag)

  l.detach()
  bl.detach()

  pump()

  s.end(True)
  pump()
  bssn.end(True)
  s2.end(True)
  a.close()
  b.close()

  pump()
Exemplo n.º 3
0
Arquivo: test.py Projeto: grkvlt/amqp
def session():
  from connection import Connection
  from session import Session
  from link import link, Sender, Receiver
  from protocol import Fragment, Linkage

  a = Connection(lambda n: Session(n, link))
  a.tracing = set(["ops", "err"])
  a.id = "A"
  b = Connection(lambda n: Session(n, link))
  b.tracing = set(["err"])
  b.id = "B"
  ssn = Session("test", link)
  a.add(ssn)
  ssn.begin()
#  nss = Session("test", link)
#  b.add(nss)

  def pump():
    a.tick()
    b.tick()
    b.write(a.read())
    a.write(b.read())

  pump()

  nss = [s for s in b.incoming.values() if s.name == "test"][0]
  nss.begin()

  snd = Sender("L", "S", "T")
  ssn.add(snd)
  rcv = Receiver("L", "S", "T")
  nss.add(rcv)

  snd.attach()
  rcv.attach()
  rcv.flow(10)

  pump()

  snd.send(fragments=Fragment(True, True, 0, 0, "m1"))
  snd.send(fragments=Fragment(True, True, 0, 0, "m2"))
  dt3 = snd.send(fragments=Fragment(True, True, 0, 0, "m3"))

  pump()

  print "PENDING", rcv.pending()

  pump()

  snd.send(fragments=Fragment(True, True, 0, 0, "m4"))

  pump()

  xfrs = []
  while rcv.pending():
    x = rcv.get()
    xfrs.append(x)
    print "XFR", x

  rcv.disposition(xfrs[-1].delivery_tag, "ACCEPTED")

  pump()

  snd.send(fragments=Fragment(True, True, 0, 0, "m5"))

  pump()

  rcv.disposition(xfrs[0].delivery_tag, "ACCEPTED")

  print "----------"
  pump()
  print "----------"

  print "ssn.outgoing:", ssn.outgoing
  print "snd.unsettled:", snd.unsettled
  for xfr in xfrs[1:-1]:
    rcv.disposition(xfr.delivery_tag, "ACCEPTED")
  print "rcv.unsettled", rcv.unsettled
  print "rcv.pending()", rcv.pending()
  rcv.disposition(rcv.get().delivery_tag)

  pump()
  print "----------"

  print "ssn.outgoing:", ssn.outgoing
  print "snd.unsettled:", snd.unsettled

  print "settling:", dt3
  snd.settle(dt3)

  print "ssn.outgoing:", ssn.outgoing
  print "snd.unsettled:", snd.unsettled

  for dt in list(snd.unsettled):
    snd.settle(dt)

  snd.detach()
  rcv.detach()

  pump()

  print "ssn.outgoing:", ssn.outgoing
  print "snd.unsettled:", snd.unsettled
Exemplo n.º 4
0
 def __init__(self, connection, name, target):
   Link.__init__(self, connection)
   self.proto = ProtoSender(name, None, target)