Commit 05c15eeb authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Jérome Perrin

OperatorPreemptive corrected

parent 2f71f199
......@@ -46,19 +46,22 @@ class OperatorPreemptive(Operator):
def checkIfResourceIsAvailable(self,callerObject=None):
activeResource= self.getResource()
activeResourceQueue = activeResource.getResourceQueue()
try:
# read the station operated by the operator
# find out which station is requesting the operator?
thecaller=callerObject
# if the operator is occupied return True
if len(activeResourceQueue)==0:
return True
# read the station currently operated by the operator
victim=activeResourceQueue[0]
# read its activeQ
victimQueue=victim.getActiveObjectQueue()
# find out which station is requesting the operator?
thecaller=callerObject
# if the callerObject is None then return False as the operator is occupied
if thecaller==None:
return False
thecallerQueue=thecaller.getActiveObjectQueue()
#if the receiver is not empty
if len(victimQueue)>0:
# and the caller is not empty
if len(thecallerQueue)>0:
#if the receiver is not empty and the caller is not empty
if len(victimQueue)>0 and len(theCallerQueue):
try:
#if the Entity to be forwarded to the station currently processed by the operator is critical
if thecallerQueue[0].isCritical:
#if the receiver does not hold an Entity that is also critical
......@@ -68,7 +71,7 @@ class OperatorPreemptive(Operator):
victim.preempt()
victim.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station
return True
# if the operator is not occupied, or if the caller is None then perform the default behaviour
# if the entity has no isCritical property then ran the default behaviour
except:
pass
return len(self.Res.activeQ)<self.capacity
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment