当前位置: 首页>>代码示例>>Python>>正文


Python Session.set_incoming_window方法代码示例

本文整理汇总了Python中session.Session.set_incoming_window方法的典型用法代码示例。如果您正苦于以下问题:Python Session.set_incoming_window方法的具体用法?Python Session.set_incoming_window怎么用?Python Session.set_incoming_window使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在session.Session的用法示例。


在下文中一共展示了Session.set_incoming_window方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import set_incoming_window [as 别名]
class Session:

  def __init__(self, connection):
    self.proto = ProtoSession(link)
    self.connection = connection
    self._lock = self.connection._lock
    self.timeout = 120
    self.txn = None
    self.proto.begin()

  def wait(self, predicate, timeout=DEFAULT):
    if timeout is DEFAULT:
      self.timeout = timeout
    self.connection.wait(predicate, timeout)

  @synchronized
  def sender(self, target, name=None, unsettled=None):
    if isinstance(target, basestring):
      target = Target(address=target)
    snd = Sender(self.connection, name or str(uuid4()), target)
    self.proto.add(snd.proto)
    for k, v in (unsettled or {}).items():
      snd.proto.resume(k, v)
    snd.proto.attach()
    self.wait(lambda: snd.proto.attached() or snd.proto.detaching())
    if snd.proto.remote_target is None:
      snd.close()
      raise LinkError("no such target: %s" % target)
    else:
      snd.address = getattr(snd.proto.remote_target, "address", None)
      snd.unsettled = snd.proto.remote_unsettled()
    return snd

  @synchronized
  def receiver(self, source, limit=0, drain=False, name=None, unsettled=None):
    if isinstance(source, basestring):
      source = Source(address=source)
    rcv = Receiver(self.connection, name or str(uuid4()), source)
    self.proto.add(rcv.proto)
    if limit:
      rcv.flow(limit, drain=drain)
    for k, v in (unsettled or {}).items():
      rcv.proto.resume(k, v)
    rcv.proto.attach()
    self.wait(lambda: rcv.proto.attached() or rcv.proto.attaching())
    if rcv.proto.remote_source is None:
      rcv.close()
      raise LinkError("no such source: %s" % source)
    else:
      rcv.address = getattr(rcv.proto.remote_source, "address", None)
      rcv.unsettled = rcv.proto.remote_unsettled()
    return rcv

  @synchronized
  def incoming_window(self):
    return self.proto.incoming_window(self)

  @synchronized
  def set_incoming_window(self, *args, **kwargs):
    return self.proto.set_incoming_window(*args, **kwargs)

  def _txn_link(self):
    if self.txn is None:
      self.txn = self.sender(Coordinator(), "txn-%s" % uuid4())

  @synchronized
  def declare(self, timeout=None):
    self._txn_link()
    self.txn.send(Message(Declare(), delivery_tag="declare"))
    for t, l, r in self.txn.pending(block=True, timeout=timeout):
      if t == "declare":
        self.txn.settle(t)
        return r.state.txn_id
    else:
      raise SessionError("transaction declare failed")

  @synchronized
  def discharge(self, txn, fail=False, timeout=None):
    self._txn_link()
    self.txn.send(Message(Discharge(txn_id=txn, fail=fail), delivery_tag="discharge"))
    for t, l, r in self.txn.pending(block=True, timeout=timeout):
      if t == "discharge":
        self.txn.settle(t)
        break
    else:
      raise SessionError("transaction discharge failed")

  @synchronized
  def close(self):
    self.proto.end()
开发者ID:grkvlt,项目名称:amqp,代码行数:92,代码来源:client.py


注:本文中的session.Session.set_incoming_window方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。