def stop(self): """ Tell the component to stop. The connection to the manager will be closed. The job process will also finish. """ self.debug('BaseComponent.stop') # Set ourselves to waking while we're shutting down. self.setMood(moods.waking) # Run stop methods, starting from the subclass, up to this base class. stops = common.get_all_methods(self, 'do_stop', True) return _maybeDeferredChain(stops, self)
def do_setup(self): """ Subclasses can implement me to set up the component before it is started. It should set up the component, possibly opening files and resources. Non-programming errors should not be raised, but returned as a failing deferred. The return value may be a deferred. """ plug_starts = [] for socket, plugs in self.config['plugs'].items(): self.plugs[socket] = [] for plug in plugs: entry = plug['entries']['default'] instance = reflectcall.reflectCall(entry['module-name'], entry['function-name'], plug) self.plugs[socket].append(instance) self.debug('Starting plug %r on socket %s', instance, socket) plug_starts.append(instance.start) # Call check methods, starting from the base class and working down to # subclasses. checks = common.get_all_methods(self, 'do_check', False) def checkErrorCallback(result): # if the mood is now sad, it means an error was encountered # during check, and we should return a failure here. # since the checks are responsible for adding a message, # this is a handled error. current = self.state.get('mood') if current == moods.sad.value: self.warning('Running checks made the component sad.') raise errors.ComponentSetupHandledError() checks.append(checkErrorCallback) return _maybeDeferredChain(plug_starts + checks, self)
def run_setups(): setups = common.get_all_methods(self, 'do_setup', False) return _maybeDeferredChain(setups, self)