Пример #1
0
    def add_listener(self, listener):
        """
        Add a :class:`PoolListener`-like object to this pool.

        `listener` may be an object that implements some or all of
        :class:`PoolListener`, or a dictionary of callables containing implementations
        of some or all of the named methods in :class:`PoolListener`.

        """

        listener = as_interface(
            listener,
            methods=(
                "connection_created",
                "connection_checked_out",
                "connection_checked_in",
                "connection_disposed",
                "connection_recycled",
                "connection_failed",
                "obtained_server_list",
                "pool_recreated",
                "pool_disposed",
                "pool_at_max",
            ),
        )

        self.listeners.append(listener)
        if hasattr(listener, "connection_created"):
            self._on_connect.append(listener)
        if hasattr(listener, "connection_checked_out"):
            self._on_checkout.append(listener)
        if hasattr(listener, "connection_checked_in"):
            self._on_checkin.append(listener)
        if hasattr(listener, "connection_disposed"):
            self._on_dispose.append(listener)
        if hasattr(listener, "connection_recycled"):
            self._on_recycle.append(listener)
        if hasattr(listener, "connection_failed"):
            self._on_failure.append(listener)
        if hasattr(listener, "obtained_server_list"):
            self._on_server_list.append(listener)
        if hasattr(listener, "pool_recreated"):
            self._on_pool_recreate.append(listener)
        if hasattr(listener, "pool_disposed"):
            self._on_pool_dispose.append(listener)
        if hasattr(listener, "pool_at_max"):
            self._on_pool_max.append(listener)
Пример #2
0
    def add_listener(self, listener):
        """
        Add a :class:`PoolListener`-like object to this pool.

        `listener` may be an object that implements some or all of
        :class:`PoolListener`, or a dictionary of callables containing implementations
        of some or all of the named methods in :class:`PoolListener`.

        """

        listener = as_interface(
            listener,
            methods=('connection_created', 'connection_checked_out',
                     'connection_checked_in', 'connection_disposed',
                     'connection_recycled', 'connection_failed',
                     'obtained_server_list', 'pool_recreated', 'pool_disposed',
                     'pool_at_max'))

        self.listeners.append(listener)
        if hasattr(listener, 'connection_created'):
            self._on_connect.append(listener)
        if hasattr(listener, 'connection_checked_out'):
            self._on_checkout.append(listener)
        if hasattr(listener, 'connection_checked_in'):
            self._on_checkin.append(listener)
        if hasattr(listener, 'connection_disposed'):
            self._on_dispose.append(listener)
        if hasattr(listener, 'connection_recycled'):
            self._on_recycle.append(listener)
        if hasattr(listener, 'connection_failed'):
            self._on_failure.append(listener)
        if hasattr(listener, 'obtained_server_list'):
            self._on_server_list.append(listener)
        if hasattr(listener, 'pool_recreated'):
            self._on_pool_recreate.append(listener)
        if hasattr(listener, 'pool_disposed'):
            self._on_pool_dispose.append(listener)
        if hasattr(listener, 'pool_at_max'):
            self._on_pool_max.append(listener)