Exemplo n.º 1
0
    def update(self):
        """
        Update this provider. Should be invoked when the server gets updated.

        This method will notify all clients that wait for
        `self.next_revision_available`.
        """

        with self.lock:
            # Increment revision and commit it.
            self.revision += 1
            self.server.commit(self.revision + 1)

            # Unblock all waiting clients.
            self.next_revision_available.set()
            self.next_revision_available.clear()

            # Check sessions to see which revision can be removed.
            if self.sessions:
                lowest_revision = min(
                    session.revision for session in self.sessions.itervalues())

                # Remove all old revision history
                if lowest_revision == self.revision:
                    self.server.clean(lowest_revision)

        # Invoke hooks
        invoke_hooks(self.hooks, "updated", self.revision)
Exemplo n.º 2
0
    def update(self):
        """
        Update this provider. Should be invoked when the server gets updated.

        This method will notify all clients that wait for
        `self.next_revision_available`.
        """

        with self.lock:
            # Increment revision and commit it.
            self.revision += 1
            self.server.commit(self.revision + 1)

            # Unblock all waiting clients.
            self.next_revision_available.set()
            self.next_revision_available.clear()

            # Check sessions to see which revision can be removed.
            if self.sessions:
                lowest_revision = min(
                    session.revision for session in self.sessions.itervalues())

                # Remove all old revision history
                if lowest_revision == self.revision:
                    self.server.clean(lowest_revision)

        # Invoke hooks
        invoke_hooks(self.hooks, "updated", self.revision)
Exemplo n.º 3
0
    def destroy_session(self, session_id):
        """
        Destroy an (existing) session.
        """

        try:
            del self.sessions[session_id]
        except KeyError:
            pass

        # Invoke hooks
        invoke_hooks(self.hooks, "session_destroyed", session_id)
Exemplo n.º 4
0
    def destroy_session(self, session_id):
        """
        Destroy an (existing) session.
        """

        try:
            del self.sessions[session_id]
        except KeyError:
            pass

        # Invoke hooks
        invoke_hooks(self.hooks, "session_destroyed", session_id)
Exemplo n.º 5
0
    def create_session(self, user_agent, remote_address, client_version):
        """
        Create a new session.

        :param str user_agent: Client user agent
        :param str remote_addr: Remote address of client
        :param str client_version: Remote client version
        :return: The new session id
        :rtype: int
        """

        self.session_counter += 1
        self.sessions[self.session_counter] = session = self.session_class()

        # Set session properties
        session.user_agent = user_agent
        session.remote_address = remote_address
        session.client_version = client_version

        # Invoke hooks
        invoke_hooks(self.hooks, "session_created", self.session_counter)

        return self.session_counter
Exemplo n.º 6
0
    def create_session(self, user_agent, remote_address, client_version):
        """
        Create a new session.

        :param str user_agent: Client user agent
        :param str remote_addr: Remote address of client
        :param str client_version: Remote client version
        :return: The new session id
        :rtype: int
        """

        self.session_counter += 1
        self.sessions[self.session_counter] = session = self.session_class()

        # Set session properties
        session.user_agent = user_agent
        session.remote_address = remote_address
        session.client_version = client_version

        # Invoke hooks
        invoke_hooks(self.hooks, "session_created", self.session_counter)

        return self.session_counter