Example #1
0
class Interconnect(object):
    # @todo - Need a better name than "Interconnect"
    def __init__(self, endpoint_handler, sasl):
        # @todo - remove sasl???
        self._connection = Connection()
        self._endpoint_cb = endpoint_handler
        self.sasl = sasl

    @property
    def connection(self):
        return self._connection

    def process_endpoints(self):

        # wait until SASL has authenticated
        # ??? Meh, why callback???
        if self.sasl:
            if self.sasl.state not in (SASL.STATE_PASS,
                                       SASL.STATE_FAIL):
                print("SASL wait.")
                return

            self._endpoint_cb.sasl_done(self.sasl)
            self.sasl = None

        if self._connection.state & _NEED_INIT:
            self._endpoint_cb.connection_pending(self._connection)

        ssn = self._connection.session_head(_NEED_INIT)
        while ssn:
            self._endpoint_cb.session_pending(ssn)
            ssn = ssn.next(_NEED_INIT)

        link = self._connection.link_head(_NEED_INIT)
        while link:
            self._endpoint_cb.link_pending(link)
            link = link.next(_NEED_INIT)

        # @todo: any need for ACTIVE callback?
        # process the work queue

        delivery = self._connection.work_head
        while delivery:
            self._endpoint_cb.delivery_update(delivery)
            delivery = delivery.work_next

        # close all endpoints closed by remotes

        link = self._connection.link_head(_NEED_CLOSE)
        while link:
            self._endpoint_cb.link_remote_closed(link)
            link = link.next(_NEED_CLOSE)

        ssn = self._connection.session_head(_NEED_CLOSE)
        while ssn:
            self._endpoint_cb.session_remote_closed(link)
            ssn = ssn.next(_NEED_CLOSE)

        if self._connection.state == (_NEED_CLOSE):
            self._endpoint_cb.connection_remote_closed(self._connection)
Example #2
0
 def connection(self, handler=None):
     """Deprecated: use connection_to_host() instead
     """
     impl = _chandler(handler, self.on_error_delegate())
     result = Connection.wrap(pn_reactor_connection(self._impl, impl))
     if impl: pn_decref(impl)
     return result
Example #3
0
 def connection(self, handler=None):
     """Deprecated: use connection_to_host() instead
     """
     impl = _chandler(handler, self.on_error)
     result = Connection.wrap(pn_reactor_connection(self._impl, impl))
     if impl: pn_decref(impl)
     return result
Example #4
0
 def init_connector(self, cxtr):
     """ Initialize a newly accepted connector
 """
     sasl = cxtr.sasl()
     sasl.mechanisms("ANONYMOUS")
     cxtr.connection = Connection()
     if "idle_timeout" in self.args:
         cxtr.transport.idle_timeout = self.args["idle_timeout"]
Example #5
0
 def connection(self, handler=None):
     impl = _chandler(handler, self.on_error)
     result = Connection.wrap(pn_reactor_connection(self._impl, impl))
     pn_decref(impl)
     return result
Example #6
0
 def connection(self):
     conn = Connection()
     conn.collect(self.collector)
     return conn
Example #7
0
 def __init__(self, endpoint_handler, sasl):
     # @todo - remove sasl???
     self._connection = Connection()
     self._endpoint_cb = endpoint_handler
     self.sasl = sasl