def __init__(self, name, actor_pusher, level_logger=logging.WARNING, timeout=None): """ :param str name: Actor name :param powerapi.PusherActor actor_pusher: Pusher actor whom send results :param int level_logger: Define logger level :param bool timeout: Time in millisecond to wait for a message before called timeout_handler. """ Actor.__init__(self, name, level_logger, timeout) #: (powerapi.PusherActor): Pusher actor whom send results. self.actor_pusher = actor_pusher formula_id = reduce( lambda acc, x: acc + (re.search(r'^\(? ?\'(.*)\'\)?', x).group(1), ), name.split(','), ()) #: (powerapi.State): Basic state of the Formula. self.state = FormulaState(Actor._initial_behaviour, SocketInterface(name, timeout), self.logger, formula_id)
def __init__(self, name, database, report_filter, report_model, stream_mode=False, level_logger=logging.WARNING, timeout=0, timeout_puller=100): """ :param str name: Actor name. :param BaseDB database: Allow to interact with a Database. :param Filter report_filter: Filter of the Puller. :param int level_logger: Define the level of the logger :param int tiemout_puller: (require stream mode) time (in ms) between two database reading :param bool asynchrone: use asynchrone driver """ Actor.__init__(self, name, level_logger, timeout) #: (State): Actor State. self.state = PullerState(self, database, report_filter, report_model, stream_mode, timeout_puller, asynchrone=database.asynchrone) self.low_exception += database.exceptions
def __init__(self, name, formula_init_function, route_table, level_logger=logging.WARNING, timeout=None): """ :param str name: Actor name :param func formula_init_function: Function for creating Formula :param route_table: initialized route table of the DispatcherActor :type route_table: powerapi.dispatcher.state.RouteTable :param int level_logger: Define the level of the logger :param bool timeout: Define the time in millisecond to wait for a message before run timeout_handler """ Actor.__init__(self, name, level_logger, timeout) # (func): Function for creating Formula self.formula_init_function = formula_init_function # (powerapi.DispatcherState): Actor state self.state = DispatcherState(Actor._initial_behaviour, SocketInterface(name, timeout), self.logger, self._create_factory(), route_table)
def __init__(self, name, report_model, database, level_logger=logging.WARNING, timeout=1000, delay=100, max_size=50): """ :param str name: Pusher name. :param Report report_model: ReportModel :param BaseDB database: Database use for saving data. :param int level_logger: Define the level of the logger :param int delay: number of ms before message containing in the buffer will be writen in database :param int max_size: maximum of message that the buffer can store before write them in database """ Actor.__init__(self, name, level_logger, timeout) #: (State): State of the actor. self.state = PusherState(self, database, report_model, asynchrone=database.asynchrone) self.delay = delay self.max_size = max_size
def _initialization(self, start_message: PusherStartMessage): Actor._initialization(self, start_message) self.database = start_message.database try: self.database.connect() except DBError as error: raise InitializationException(error.msg) from error
def receiveMsg_ActorExitRequest(self, message: ActorExitRequest, sender: ActorAddress): """ When receiving ActorExitRequest, forward it to all formula """ Actor.receiveMsg_ActorExitRequest(self, message, sender) for _, (formula, __) in self.formula_pool.items(): self.send(formula, ActorExitRequest()) for _, formula in self.formula_waiting_service.get_all_formula(): self.send(formula, ActorExitRequest())
def _initialization(self, message: StartMessage): Actor._initialization(self, message) self.formula_class = message.formula_class self.formula_values = message.formula_values self.route_table = message.route_table self.device_id = message.device_id self.formula_name_service = FormulaNameService() if self.route_table.primary_dispatch_rule is None: raise InitializationException( 'Dispatcher initialized without primary dispatch rule')
def setup(self): """ Check if there is a primary group by rule. Set define StartMessage, PoisonPillMessage and Report handlers """ Actor.setup(self) if self.state.route_table.primary_dispatch_rule is None: raise NoPrimaryDispatchRuleRuleException() self.add_handler(Report, FormulaDispatcherReportHandler()) self.add_handler(PoisonPillMessage, PoisonPillMessageHandler()) self.add_handler(StartMessage, StartHandler())
def __init__(self): Actor.__init__(self, DispatcherStartMessage) self.formula_class: Type[FormulaActor] = None self.formula_values: FormulaValues = None self.route_table: RouteTable = None self.device_id = None self._exit_mode = False self.formula_name_service = None self.formula_waiting_service = FormulaWaitingService() self.formula_pool = {} self.formula_number_id = 0
def __init__(self, name, pushers: Dict[str, PusherActor], level_logger=logging.WARNING, timeout=None): """ Initialize a new Formula actor. :param name: Actor name :param pushers: Pusher actors :param level_logger: Level of the logger :param timeout: Time in millisecond to wait for a message before calling the timeout handler """ Actor.__init__(self, name, level_logger, timeout) self.state = FormulaState(self, pushers)
def __init__(self, name, report_model, database, level_logger=logging.WARNING, timeout=1000): """ :param str name: Pusher name. :param Report report_model: ReportModel :param BaseDB database: Database use for saving data. :param int level_logger: Define the level of the logger """ Actor.__init__(self, name, level_logger, timeout) #: (State): State of the actor. self.state = PusherState(self, database, report_model)
def __init__(self, name, push_socket_addr, level_logger=logging.WARNING, timeout=None): """ :param str name: Actor name :param int level_logger: Define logger level :param bool timeout: Time in millisecond to wait for a message before called timeout_handler. """ Actor.__init__(self, name, level_logger, timeout) #: (powerapi.State): Basic state of the Formula. self.state = State(self) self.addr = push_socket_addr self.push_socket = None
def __init__(self, name, database, report_filter, report_model, stream_mode=False, level_logger=logging.WARNING, timeout=0, timeout_sleeping=100): """ :param str name: Actor name. :param BaseDB database: Allow to interact with a Database. :param Filter report_filter: Filter of the Puller. :param int level_logger: Define the level of the logger """ Actor.__init__(self, name, level_logger, timeout) #: (State): Actor State. self.state = PullerState(self, database, report_filter, report_model, stream_mode, timeout, timeout_sleeping)
def __init__(self, name, database, report_filter, level_logger=logging.WARNING, timeout=0, timeout_sleeping=100): """ :param str name: Actor name. :param BaseDB database: Allow to interact with a Database. :param Filter report_filter: Filter of the Puller. :param int level_logger: Define the level of the logger :param bool stream_mode: Puller stream_mode himself when it finish to read all the database. """ Actor.__init__(self, name, level_logger, timeout) #: (State): Actor State. self.state = PullerState(Actor._initial_behaviour, SocketInterface(name, timeout), self.logger, database, report_filter, timeout, timeout_sleeping)
def __init__(self, start_message_cls: Type[FormulaStartMessage]): Actor.__init__(self, start_message_cls) self.pushers: Dict[str, ActorAddress] = None self.device_id = None self.sensor = None
def __init__(self): Actor.__init__(self, 'test_supervisor') self.state = State(Mock(), SocketInterface('test_supervisor', 0), Mock()) self.send_msg = [] self.alive = False
def __init__(self, name=ACTOR_NAME): Actor.__init__(self, name, level_logger=LOG_LEVEL) self.state = State(Mock(), Mock(), self.logger)
def _initialization(self, start_message: FormulaStartMessage): Actor._initialization(self, start_message) self.pushers = start_message.values.pushers self.device_id = start_message.domain_values.device_id self.sensor = start_message.domain_values.sensor
def __init__(self): Actor.__init__(self, 'test_supervisor') self.state = State(Mock()) self.send_msg = [] self.alive = False
def __init__(self, name=ACTOR_NAME): Actor.__init__(self, name, level_logger=LOG_LEVEL)
def __init__(self): Actor.__init__(self, PusherStartMessage) self.database = None