methods used by broker and router collapsed to ObjectInterruption

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