示例#1
0
文件: mutex.py 项目: fredronnv/AdHoc
    def _check_current_holder(self, session_id=None):
        if not session_id:
            session_id = self.function.session.oid

        q = "SELECT 1 "
        q += " FROM rpcc_mutex "
        q += "WHERE id=:mutex "
        q += "  AND holder_session=:sesn "
        ret = list(self.db.get(q, mutex=self.mutex_id, sesn=session_id))

        if len(ret) == 0:
            raise default_error.ExtMutexNotHeldError()
示例#2
0
文件: mutex.py 项目: fredronnv/AdHoc
    def create_variable(self, name, typ, session=None):
        self._check_current_holder(session)

        q = "INSERT INTO rpcc_mutex_var (mutex_id, name, typ) "
        q += " VALUES (:mtx, :name, :typ) "

        try:
            affected = self.db.put(q, mtx=self.mutex_id, name=name, typ=typ)
        except database.IntegrityError as _e:
            raise default_error.ExtMutexVariableAlreadyExistsError()

        if affected == 0:
            raise default_error.ExtMutexNotHeldError()
示例#3
0
文件: mutex.py 项目: fredronnv/AdHoc
    def get_variable_names(self, typ, session=None):
        # Mutex hold check is implicit in query
        if not session:
            session = self.function.session.oid

        q = "SELECT m.id, v.name "
        q += " FROM rpcc_mutex m LEFT OUTER JOIN rpcc_mutex_var v "
        q += "      ON (m.id=v.mutex_id "
        q += "          AND m.holder_session=:sesn "
        q += "          AND v.typ=:typ) "

        ret = list(self.db.get(q, sesn=session, typ=typ))

        # No rows returned -> mutex not held
        if len(ret) == 0:
            raise default_error.ExtMutexNotHeldError()

        # One or more rows -> non-null values are variable names of the
        # specified type.
        return [var for (_, var) in ret if var is not None]
示例#4
0
 def do(self):
     if not self.mutex.release(self.force):
         raise default_error.ExtMutexNotHeldError()