Esempio n. 1
0
class RedisAreaDispatcher(AreaDispatcher):
    def __init__(self, area, redis_area, redis_market):
        super().__init__(area)
        self.area_event_dispatcher = RedisAreaEventDispatcher(area, self, redis_area)
        self.market_event_dispatcher = AreaRedisMarketEventDispatcher(area, self, redis_market)
        self.market_notify_event_dispatcher = MarketNotifyEventSubscriber(area, self)
        self.area_to_market_event_dispatcher = AreaToMarketEventPublisher(area)

    def publish_market_clearing(self):
        self.area_to_market_event_dispatcher.publish_markets_clearing()

    def broadcast_activate(self, **kwargs):
        self._broadcast_events(AreaEvent.ACTIVATE, **kwargs)

    def broadcast_tick(self, **kwargs):
        return self._broadcast_events(AreaEvent.TICK, **kwargs)

    def broadcast_market_cycle(self, **kwargs):
        self.market_notify_event_dispatcher.cycle_market_channels()
        return self._broadcast_events(AreaEvent.MARKET_CYCLE, **kwargs)

    def broadcast_balancing_market_cycle(self, **kwargs):
        return self._broadcast_events(AreaEvent.BALANCING_MARKET_CYCLE, **kwargs)

    def _broadcast_events(self, event_type, **kwargs):
        if isinstance(event_type, AreaEvent):
            self.area_event_dispatcher.broadcast_event_redis(event_type, **kwargs)
        elif isinstance(event_type, MarketEvent):
            self.market_event_dispatcher.broadcast_event_redis(event_type, **kwargs)
        else:
            assert False, f"Event type {event_type} is not an Area or Market event."

    @property
    def broadcast_callback(self):
        return self._broadcast_events
Esempio n. 2
0
 def __init__(self, area, redis_area, redis_market):
     super().__init__(area)
     self.area_event_dispatcher = RedisAreaEventDispatcher(
         area, self, redis_area)
     self.market_event_dispatcher = AreaRedisMarketEventDispatcher(
         area, self, redis_market)
     self.market_notify_event_dispatcher = MarketNotifyEventSubscriber(
         area, self)
     self.area_to_market_event_dispatcher = AreaToMarketEventPublisher(area)