Commit 33f02e01 authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Jérome Perrin

minor changes to ConditionalBuffer haveToDispose()

parent 79a73ba1
......@@ -51,39 +51,44 @@ class ConditionalBuffer(QueuePreemptive):
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
thecaller = callerObject
# assert that the callerObject is not None
assert thecaller!=None, 'the caller object of the ConditionalBuffer should not be None'
# -------------------------------------------------------------------
# check the length of the activeObjectQueue
# if the length is zero then no componentType or entity.type can be read
# in this case return zero
if len(activeObjectQueue)==0:
return False
# read the entity to be disposed
activeEntity = activeObjectQueue[0]
# assert that the entity.type is OrderComponent
assert activeEntity.type=='OrderComponent',\
"the entity to be disposed is not of type OrderComponent"
# -------------------------------------------------------------------
# if the type of the component is Secondary then verify that the basics of the same Order
# are already processed before disposing them to the next object
if activeEntity.componentType=='Secondary'\
and (not activeEntity.order.basicsEnded):
return False
# -------------------------------------------------------------------
#if we have only one possible receiver just check if the receiver is the caller
if(len(activeObject.next)==1 or callerObject==None):
activeObject.receiver=activeObject.next[0]
return thecaller==activeObject.receiver
# -------------------------------------------------------------------
#give the entity to the possible receiver that is waiting for the most time.
#plant does not do this in every occasion!
maxTimeWaiting=0
# loop through the object in the successor list
# loop through the object in the successor list
for object in activeObject.next:
if(object.canAccept(activeObject)): # if the object can accept
timeWaiting=now()-object.timeLastEntityLeft # compare the time that it has been waiting
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):# with the others'
# if the object can accept
if(object.canAccept(activeObject)):
timeWaiting=now()-object.timeLastEntityLeft
# compare the time that it has been waiting with the others'
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):
maxTimeWaiting=timeWaiting
self.receiver=object # and update the receiver to the index of this object
# and update the receiver to the index of this object
self.receiver=object
#return True if the Queue caller is the receiver
return thecaller is self.receiver
......
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