methods used by broker and router collapsed to ObjectInterruption

parent 5a9dfa2d
......@@ -229,7 +229,7 @@ class Machine(CoreObject):
self.router.startCycle.signal(self.id)
# the machine must wait until the router has decided which machine will operated by which operator
# yield waitevent, self, self.routerCycleOver
yield waituntil, self, self.router.routerIsSet
yield waituntil, self, self.router.isSet
self.router.victim=None
# if the machine is not picked by the router the it should wait again
if not self.canProceedWithGetEntity:
......@@ -250,7 +250,7 @@ class Machine(CoreObject):
self.requestOperator()
self.timeWaitForLoadOperatorStarted = now()
# wait until the Broker has waited times equal to loadTime (if any)
yield waituntil, self, self.broker.brokerIsSet
yield waituntil, self, self.broker.isSet
self.timeWaitForLoadOperatorEnded = now()
self.loadOperatorWaitTimeCurrentEntity += self.timeWaitForLoadOperatorEnded-self.timeWaitForLoadOperatorStarted
self.totalTimeWaitingForLoadOperator += self.loadOperatorWaitTimeCurrentEntity
......@@ -274,7 +274,7 @@ class Machine(CoreObject):
# machine has to release the operator
self.releaseOperator()
# wait until the Broker has finished processing
yield waituntil, self, self.broker.brokerIsSet
yield waituntil, self, self.broker.isSet
# TODO: reset the requestinEntity before receiving the currentEntity
self.requestingEntity=None
......@@ -296,7 +296,7 @@ class Machine(CoreObject):
self.requestOperator()
self.timeWaitForOperatorStarted = now()
# wait until the Broker has waited times equal to loadTime (if any)
yield waituntil, self, self.broker.brokerIsSet
yield waituntil, self, self.broker.isSet
self.timeWaitForOperatorEnded = now()
self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted
......@@ -325,7 +325,7 @@ class Machine(CoreObject):
# machine has to release the operator
self.releaseOperator()
# wait until the Broker has finished processing
yield waituntil, self, self.broker.brokerIsSet
yield waituntil, self, self.broker.isSet
# variables used to flag any interruptions and the end of the processing
interruption=False
......@@ -370,7 +370,7 @@ class Machine(CoreObject):
and self.isOperated()\
and any(type=="Processing" for type in self.multOperationTypeList):
self.releaseOperator()
yield waituntil,self,self.broker.brokerIsSet
yield waituntil,self,self.broker.isSet
# if there is a failure in the machine or interruption due to preemption, it is passivated
yield passivate,self
......@@ -392,7 +392,7 @@ class Machine(CoreObject):
and not interruption:
self.timeWaitForOperatorStarted = now()
self.requestOperator()
yield waituntil,self,self.broker.brokerIsSet
yield waituntil,self,self.broker.isSet
self.timeWaitForOperatorEnded = now()
self.operatorWaitTimeCurrentEntity += self.timeWaitForOperatorEnded-self.timeWaitForOperatorStarted
......@@ -410,7 +410,7 @@ class Machine(CoreObject):
and any(type=="Processing" for type in self.multOperationTypeList)\
and not interruption:
self.releaseOperator()
yield waituntil,self,self.broker.brokerIsSet
yield waituntil,self,self.broker.isSet
continue
# output to trace that the processing in the Machine self.objName ended
......@@ -444,7 +444,7 @@ class Machine(CoreObject):
and any(type=="Processing" for type in self.multOperationTypeList)\
and not interruption:
self.releaseOperator()
yield waituntil,self,self.broker.brokerIsSet
yield waituntil,self,self.broker.isSet
while 1:
......@@ -738,14 +738,14 @@ class Machine(CoreObject):
# # TESTING
# print now(), self.id, 'requested router'
self.inPositionToGet=True
if not self.router.routerIsCalled():
self.router.invokeRouter()
if not self.router.isCalled():
self.router.invoke()
# =======================================================================
# prepare the machine to be operated
# =======================================================================
def requestOperator(self):
self.broker.invokeBroker()
self.broker.invoke()
self.toBeOperated = True
# =======================================================================
......@@ -762,7 +762,7 @@ class Machine(CoreObject):
or any(type=='Processing' for type in self.multOperationTypeList)):
self.currentOperator.activeCallersList=[]
self.broker.invokeBroker()
self.broker.invoke()
self.toBeOperated = False
# =======================================================================
......
......@@ -33,15 +33,45 @@ class ObjectInterruption(Process):
def __init__(self, victim=None):
Process.__init__(self)
self.victim=victim
# variable used to hand in control to the objectInterruption
self.call=False
def initialize(self):
Process.__init__(self)
self.call=False
#the main process of the core object
#this is dummy, every object must have its own implementation
def run(self):
raise NotImplementedError("Subclass must define 'run' method")
# =======================================================================
# hand in the control to the objectIterruption.run
# to be called by the machine
# =======================================================================
def invoke(self):
self.call=True
# =======================================================================
# return control to the Machine.run
# =======================================================================
def exit(self):
self.call=False
# =======================================================================
# call the objectInterruption
# filter for object interruption - yield waituntil isCalled
# =======================================================================
def isCalled(self):
return self.call
# =======================================================================
# the objectIterruption returns control to machine.Run
# filter for Machine - yield request/release operator
# =======================================================================
def isSet(self):
return not self.call
#outputs data to "output.xls"
def outputTrace(self, message):
pass
......
......@@ -43,8 +43,6 @@ class Broker(ObjectInterruption):
def __init__(self, operatedMachine):
ObjectInterruption.__init__(self,operatedMachine)
self.type = "Broker"
# variable used to hand in control to the Broker
self.call=False
# variables that have to do with timing
self.timeOperationStarted = 0
self.timeLastOperationEnded = 0
......@@ -55,7 +53,6 @@ class Broker(ObjectInterruption):
#===========================================================================
def initialize(self):
ObjectInterruption.initialize(self)
self.call=False
self.timeLastOperationEnded=0
self.timeOperationStarted=0
self.timeWaitForOperatorStarted=0
......@@ -65,7 +62,7 @@ class Broker(ObjectInterruption):
# =======================================================================
def run(self):
while 1:
yield waituntil,self,self.brokerIsCalled # wait until the broker is called
yield waituntil,self,self.isCalled # wait until the broker is called
# ======= request a resource
if self.victim.isOperated()\
and any(type=="Load" or type=="Setup" or type=="Processing"\
......@@ -109,37 +106,5 @@ class Broker(ObjectInterruption):
else:
pass
# return the control the machine.run
self.exitBroker()
# =======================================================================
# call the broker
# filter for Broker - yield waituntil brokerIsCalled
# =======================================================================
def brokerIsCalled(self):
return self.call
# =======================================================================
# the broker returns control to OperatedMachine.Run
# filter for Machine - yield request/release operator
# =======================================================================
def brokerIsSet(self):
return not self.call
# =======================================================================
# hand in the control to the Broker.run
# to be called by the machine
# =======================================================================
def invokeBroker(self):
self.call=True
# =======================================================================
# return control to the Machine.run
# =======================================================================
def exitBroker(self):
self.call=False
self.exit()
\ No newline at end of file
......@@ -44,8 +44,6 @@ class Router(ObjectInterruption):
def __init__(self):
ObjectInterruption.__init__(self)
self.type = "Router"
# variable used to hand in control to the Broker
self.call=False
# signal used to initiate the generator of the Router
self.startCycle=SimEvent('startCycle')
# TODO: create an initialise method for router to reset the attributes for every replication
......@@ -59,7 +57,6 @@ class Router(ObjectInterruption):
#===========================================================================
def initialize(self):
ObjectInterruption.initialize(self)
self.call=False
# list that holds all the objects that can receive
self.pendingObjects=[]
self.calledOperator=[]
......@@ -87,7 +84,8 @@ class Router(ObjectInterruption):
yield waitevent, self, self.startCycle
self.victim=findObjectById(self.startCycle.signalparam)
# yield waituntil,self,self.routerIsCalled
# yield waituntil,self,self.isCalled
# when the router is called for the first time wait till all the entities
# finished all their moves in stations of non-Machine-type
# before they can enter again a type-Machine object
......@@ -214,7 +212,7 @@ class Router(ObjectInterruption):
# print [str(object.id) for object in self.pendingObjects if object.canProceedWithGetEntity]
#===================================================================
self.exitRouter()
self.exit()
#===========================================================================
# have the entities that have ended their processing when the router
......@@ -258,32 +256,11 @@ class Router(ObjectInterruption):
if allEntitiesMoved:
return True
return True
# =======================================================================
# call the Scheduler
# filter for Broker - yield waituntil brokerIsCalled
# =======================================================================
def routerIsCalled(self):
return self.call
# =======================================================================
# the broker returns control to OperatedMachine.Run
# filter for Machine - yield request/release operator
# =======================================================================
def routerIsSet(self):
return not self.call
# =======================================================================
# hand in the control to the Broker.run
# to be called by the machine
# =======================================================================
def invokeRouter(self):
self.call=True
# =======================================================================
# return control to the Machine.run
# =======================================================================
def exitRouter(self):
def exit(self):
from Globals import G
# reset the variables that are used from the Router
for operator in self.candidateOperators:
......@@ -298,8 +275,8 @@ class Router(ObjectInterruption):
del self.pendingObjects[:]
del self.multipleCriterionList[:]
self.schedulingRule='WT'
# reset the call flag of the Router
self.call=False
ObjectInterruption.exit(self)
# self.victim.routerCycleOver.signal('router has implemented its logic')
#=======================================================================
......
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