def __init__(self, action=None): self.g = (self, action) # Id similar to channel name, to correctly select the chosen guard among the guard set. self.id = uuid.uuid1().hex # Necessary to allow for correct locking self.dispatch = SocketDispatcher().getThread() self.dispatch.registerGuard(self.id) self.LM = LockMessenger(self.id)
class Guard(object): """ The empty interface of a guard. """ def __init__(self, action=None): self.g = (self, action) # Id similar to channel name, to correctly select the chosen guard among the guard set. self.id = uuid.uuid1().hex self.id = self.id.encode() # Necessary to allow for correct locking self.dispatch = SocketDispatcher().getThread() self.dispatch.registerGuard(self.id) self.LM = LockMessenger(self.id) def _offer(self, req): try: # Acquire lock conn, state, seq = self.LM.remote_acquire_and_get_state( req.process) # Check sequence number if seq != req.seq_check: state = FAIL # Success? if (state == READY): self.LM.remote_notify(conn, req.process, req.ch_id, None) # Release lock self.LM.remote_release(conn, req.process) except AddrUnavailableException: # Unable to reach process during offer # The primary reason is probably because a request were part of an alting and the process have exited. if conf.get(SOCKETS_STRICT_MODE): raise FatalException( "PyCSP unable to reach process during Guard.offer(%s)" % str(self.process)) else: sys.stderr.write( "PyCSP unable to reach process during Guard.offer(%s)\n" % str(self.process)) def _close(self): # Invoked from Alternation self.dispatch.deregisterGuard(self.id)
class Guard: """ The empty interface of a guard. """ def __init__(self, action=None): self.g = (self, action) # Id similar to channel name, to correctly select the chosen guard among the guard set. self.id = uuid.uuid1().hex # Necessary to allow for correct locking self.dispatch = SocketDispatcher().getThread() self.dispatch.registerGuard(self.id) self.LM = LockMessenger(self.id) def _offer(self, req): try: # Acquire lock conn, state, seq = self.LM.remote_acquire_and_get_state(req.process) # Check sequence number if seq != req.seq_check: state = FAIL # Success? if (state == READY): self.LM.remote_notify(conn, req.process, req.ch_id, None) # Release lock self.LM.remote_release(conn, req.process) except AddrUnavailableException: # Unable to reach process during offer # The primary reason is probably because a request were part of an alting and the process have exited. if conf.get(SOCKETS_STRICT_MODE): raise FatalException("PyCSP unable to reach process during Guard.offer(%s)" % str(self.process)) else: sys.stderr.write("PyCSP unable to reach process during Guard.offer(%s)\n" % str(self.process)) def _close(self): # Invoked from Alternation self.dispatch.deregisterGuard(self.id)