当前位置: 首页>>代码示例>>Python>>正文


Python EventSubscriber.start方法代码示例

本文整理汇总了Python中pyon.event.event.EventSubscriber.start方法的典型用法代码示例。如果您正苦于以下问题:Python EventSubscriber.start方法的具体用法?Python EventSubscriber.start怎么用?Python EventSubscriber.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyon.event.event.EventSubscriber的用法示例。


在下文中一共展示了EventSubscriber.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_pub_on_different_subtypes

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
    def test_pub_on_different_subtypes(self):
        ar = event.AsyncResult()
        gq = queue.Queue()
        self.count = 0

        def cb(event, *args, **kwargs):
            self.count += 1
            gq.put(event)
            if event.description == "end":
                ar.set()

        sub = EventSubscriber(event_type="ResourceModifiedEvent", sub_type="st1", callback=cb)
        sub.start()

        pub1 = EventPublisher(event_type="ResourceModifiedEvent")
        pub2 = EventPublisher(event_type="ContainerLifecycleEvent")

        pub1.publish_event(origin="two", sub_type="st2", description="2")
        pub2.publish_event(origin="three", sub_type="st1", description="3")
        pub1.publish_event(origin="one", sub_type="st1", description="1")
        pub1.publish_event(origin="four", sub_type="st1", description="end")

        ar.get(timeout=5)
        sub.stop()

        res = []
        for x in xrange(self.count):
            res.append(gq.get(timeout=5))

        self.assertEquals(len(res), 2)
        self.assertEquals(res[0].description, "1")
开发者ID:daf,项目名称:pyon,代码行数:33,代码来源:test_event.py

示例2: InstrumentAgentEventSubscribers

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
class InstrumentAgentEventSubscribers(object):
    """
    Create subscribers for agent and driver events.
    """
    log.info("Start event subscribers")
    def __init__(self, instrument_agent_resource_id = None):
        # Start event subscribers, add stop to cleanup.
        self.no_events = None
        self.events_received = []
        self.async_event_result = AsyncResult()
        self.event_subscribers = []

        def consume_event(*args, **kwargs):
            log.debug('#**#**# Event subscriber (consume_event) recieved ION event: args=%s, kwargs=%s, event=%s.',
                str(args), str(kwargs), str(args[0]))

            log.debug("self.no_events = " + str(self.no_events))
            log.debug("self.event_received = " + str(self.events_received))

            self.events_received.append(args[0])
            if self.no_events and self.no_events == len(self.events_received):
                log.debug("CALLING self.async_event_result.set()")
                self.async_event_result.set()


        self.event_subscribers = EventSubscriber(
            event_type='ResourceAgentEvent', callback=consume_event,
            origin=instrument_agent_resource_id)
        self.event_subscribers.start()
        self.event_subscribers._ready_event.wait(timeout=5)
开发者ID:swarbhanu,项目名称:marine-integrations,代码行数:32,代码来源:instrument_agent_client.py

示例3: on_start

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
    def on_start(self):
        #print ">>>>>>>>>>>>>>>>>>>>>> MPL CFG = ", self.CFG

        self.pubsub_management = PubsubManagementServiceProcessClient(process=self)
        self.ssclient = SchedulerServiceProcessClient(process=self)
        self.rrclient = ResourceRegistryServiceProcessClient(process=self)
        self.data_retriever_client = DataRetrieverServiceProcessClient(process=self)
        self.dsm_client = DatasetManagementServiceProcessClient(process=self)
        self.pubsub_client = PubsubManagementServiceProcessClient(process = self)

        self.stream_info  = self.CFG.get_safe('process.publish_streams',{})
        self.stream_names = self.stream_info.keys()
        self.stream_ids   = self.stream_info.values()

        if not self.stream_names:
            raise BadRequest('MPL Transform has no output streams.')

        graph_time_periods= self.CFG.get_safe('graph_time_periods')

        # If this is meant to be an event driven process, schedule an event to be generated every few minutes/hours
        self.event_timer_interval = self.CFG.get_safe('graph_gen_interval')
        if self.event_timer_interval:
            event_origin = "Interval_Timer_Matplotlib"
            sub = EventSubscriber(event_type="ResourceEvent", callback=self.interval_timer_callback, origin=event_origin)
            sub.start()

            self.interval_timer_id = self.ssclient.create_interval_timer(start_time="now" , interval=self._str_to_secs(self.event_timer_interval),
                event_origin=event_origin, event_subtype="")

        super(VizTransformMatplotlibGraphs,self).on_start()
开发者ID:Bobfrat,项目名称:coi-services,代码行数:32,代码来源:matplotlib_graphs.py

示例4: NotificationSubscription

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
class NotificationSubscription(object):
    """
    Ties a notification's info to it's event subscriber
    """

    def  __init__(self, notification_request=None, callback=None):
        self._res_obj = notification_request  # The Notification Request Resource Object
        self.subscriber = EventSubscriber(  origin=notification_request.origin,
            origin_type = notification_request.origin_type,
            event_type=notification_request.event_type,
            sub_type=notification_request.event_subtype,
            callback=callback)
        self.notification_subscription_id = None

    def set_notification_id(self, id_=None):
        """
        Set the notification id of the notification object
        @param notification id
        """
        self.notification_subscription_id = id_

    def activate(self):
        """
        Start subscribing
        """
        self.subscriber.start()

    def deactivate(self):
        """
        Stop subscribing
        """
        self.subscriber.stop()
开发者ID:oceanzus,项目名称:coi-services,代码行数:34,代码来源:user_notification_service.py

示例5: test_create_interval_timer_with_end_time

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
    def test_create_interval_timer_with_end_time(self):
        # create the interval timer resource
        # create the event listener
        # call scheduler to set the timer
        # receive a few intervals, validate that arrival time is as expected
        # Validate no more events are published after end_time expires
        # Validate the timer was canceled after the end_time expires

        self.interval_timer_count_2 = 0
        self.interval_timer_sent_time_2 = 0
        self.interval_timer_received_time_2 = 0
        self.interval_timer_interval_2 = 3

        event_origin = "Interval_Timer_2"
        sub = EventSubscriber(event_type="TimerEvent", callback=self.interval_timer_callback_with_end_time, origin=event_origin)
        sub.start()
        self.addCleanup(sub.stop)

        start_time = self.now_utc()
        self.interval_timer_end_time_2 = start_time + 7
        id = self.ssclient.create_interval_timer(start_time="now" , interval=self.interval_timer_interval_2,
            end_time=self.interval_timer_end_time_2,
            event_origin=event_origin, event_subtype="")
        self.interval_timer_sent_time_2 = datetime.datetime.utcnow()
        self.assertEqual(type(id), str)

        # Wait until all events are published
        gevent.sleep((self.interval_timer_end_time_2 - start_time) + self.interval_timer_interval_2 + 1)

        # Validate the number of events generated
        self.assertEqual(self.interval_timer_count_2, 2, "Invalid number of timeouts generated. Number of event: %d Expected: 2 Timer id: %s " %(self.interval_timer_count_2, id))

        # Validate the timer was canceled after the end_time is expired
        with self.assertRaises(BadRequest):
            self.ssclient.cancel_timer(id)
开发者ID:jamie-cyber1,项目名称:coi-services,代码行数:37,代码来源:test_scheduler.py

示例6: test_create_forever_interval_timer

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
    def test_create_forever_interval_timer(self):
        # Test creating interval timer that runs forever

        self.interval_timer_count = 0
        self.interval_timer_sent_time = 0
        self.interval_timer_received_time = 0
        self.interval_timer_interval = 3

        event_origin = "Interval Timer Forever"
        sub = EventSubscriber(event_type="TimerEvent", callback=self.interval_timer_callback, origin=event_origin)
        sub.start()
        self.addCleanup(sub.stop)

        id = self.ssclient.create_interval_timer(start_time= self.now_utc(), interval=self.interval_timer_interval,
            end_time=-1,
            event_origin=event_origin, event_subtype=event_origin)
        self.interval_timer_sent_time = datetime.datetime.utcnow()
        self.assertEqual(type(id), str)

        # Wait for 4 events to be published
        gevent.sleep((self.interval_timer_interval * 4) + 1)
        self.ssclient.cancel_timer(id)
        time_diff = (datetime.datetime.utcnow() - self.interval_timer_sent_time).seconds
        timer_counts =  math.floor(time_diff/self.interval_timer_interval)


        # Validate the timer id is invalid once it has been canceled
        with self.assertRaises(BadRequest):
            self.ssclient.cancel_timer(id)

        # Validate events are not generated after canceling the timer
        self.assertEqual(self.interval_timer_count, timer_counts, "Invalid number of timeouts generated. Number of timeout: %d Expected timeout: %d Timer id: %s " %(self.interval_timer_count, timer_counts, id))
开发者ID:jamie-cyber1,项目名称:coi-services,代码行数:34,代码来源:test_scheduler.py

示例7: start_DeviceStatusAlertEvent_subscriber

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
        def start_DeviceStatusAlertEvent_subscriber(value_id, sub_type):
            """
            @return async_event_result  Use it to wait for the expected event
            """
            event_type = "DeviceStatusAlertEvent"

            async_event_result = AsyncResult()

            def consume_event(evt, *args, **kwargs):
                log.info('DeviceStatusAlertEvent_subscriber received evt: %s', str(evt))
                if evt.type_ != event_type or \
                   evt.value_id != value_id or \
                   evt.sub_type != sub_type:
                    return

                async_event_result.set(evt)

            kwargs = dict(event_type=event_type,
                          callback=consume_event,
                          origin=self.p_root.platform_device_id,
                          sub_type=sub_type)

            sub = EventSubscriber(**kwargs)
            sub.start()
            log.info("registered DeviceStatusAlertEvent subscriber: %s", kwargs)

            self._event_subscribers.append(sub)
            sub._ready_event.wait(timeout=self._receive_timeout)

            return async_event_result
开发者ID:Bobfrat,项目名称:coi-services,代码行数:32,代码来源:test_platform_agent_with_rsn.py

示例8: test_qc_events

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
    def test_qc_events(self):
        ph = ParameterHelper(self.dataset_management, self.addCleanup)
        pdict_id = ph.create_qc_pdict()
        stream_def_id = self.pubsub_management.create_stream_definition('qc stream def', parameter_dictionary_id=pdict_id)
        self.addCleanup(self.pubsub_management.delete_stream_definition, stream_def_id)

        stream_id, route = self.pubsub_management.create_stream('qc stream', exchange_point=self.exchange_point_name, stream_definition_id=stream_def_id)
        self.addCleanup(self.pubsub_management.delete_stream, stream_id)

        ingestion_config_id = self.get_ingestion_config()
        dataset_id = self.create_dataset(pdict_id)
        config = DotDict()

        self.ingestion_management.persist_data_stream(stream_id=stream_id, ingestion_configuration_id=ingestion_config_id, dataset_id=dataset_id, config=config)
        self.addCleanup(self.ingestion_management.unpersist_data_stream, stream_id, ingestion_config_id)

        publisher = StandaloneStreamPublisher(stream_id, route)
        rdt = RecordDictionaryTool(stream_definition_id=stream_def_id)
        rdt['time'] = np.arange(10)
        rdt['temp'] = np.arange(10) * 3

        verified = Event()
        def verification(event, *args, **kwargs):
            self.assertEquals(event.qc_parameter, 'temp_qc')
            self.assertEquals(event.temporal_value, 7)
            verified.set()

        es = EventSubscriber(event_type=OT.ParameterQCEvent, origin=dataset_id, callback=verification, auto_delete=True)
        es.start()
        self.addCleanup(es.stop)

        publisher.publish(rdt.to_granule())
        self.assertTrue(verified.wait(10))
开发者ID:jamie-cyber1,项目名称:coi-services,代码行数:35,代码来源:test_dm_end_2_end.py

示例9: test_quit_stops_timers

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
    def test_quit_stops_timers(self):

        ar = AsyncResult()
        def cb(*args, **kwargs):
            ar.set(args)

            self.interval_timer_count += 1

        event_origin = "test_quitter"
        sub = EventSubscriber(event_type="TimerEvent", callback=cb, origin=event_origin)
        sub.start()
        self.addCleanup(sub.stop)

        tid = self.ssclient.create_interval_timer(start_time="now",
                                                  interval=1,
                                                  event_origin=event_origin)

        # wait until at least one scheduled message
        ar.get(timeout=5)

        # shut it down!
        p = self.container.proc_manager.procs_by_name['scheduler']
        self.container.terminate_process(p.id)

        # assert empty
        self.assertEquals(p.schedule_entries, {})
开发者ID:jamie-cyber1,项目名称:coi-services,代码行数:28,代码来源:test_scheduler.py

示例10: test_timeoffday_timer

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
    def test_timeoffday_timer(self):
        # test creating a new timer that is one-time-only
        # create the timer resource
        # get the current time, set the timer to several seconds from current time
        # create the event listener
        # call scheduler to set the timer
        # verify that  event arrival is within one/two seconds of current time

        ss = SchedulerService()
        event_origin = "Time Of Day2"
        self.expire_sec_1 = 4
        self.expire_sec_2 = 4
        self.tod_count = 0
        expire1 = datetime.datetime.utcnow() + timedelta(seconds=self.expire_sec_1)
        expire2 = datetime.datetime.utcnow() + timedelta(seconds=self.expire_sec_2)
        # Create two timers
        times_of_day =[{'hour': str(expire1.hour),'minute' : str(expire1.minute), 'second':str(expire1.second) },
                       {'hour': str(expire2.hour),'minute' : str(expire2.minute), 'second':str(expire2.second)}]

        sub = EventSubscriber(event_type="ResourceEvent", callback=self.tod_callback, origin=event_origin)
        sub.start()
        # Expires in one days
        e = time.mktime((datetime.datetime.utcnow() + timedelta(days=1)).timetuple())
        self.tod_sent_time = datetime.datetime.utcnow()
        id = ss.create_time_of_day_timer(times_of_day=times_of_day, expires=e, event_origin=event_origin, event_subtype="")
        self.assertEqual(type(id), str)
        gevent.sleep(15)
        # After waiting for 15 seconds, validate only 2 events are generated.
        self.assertTrue(self.tod_count == 2)
开发者ID:pombredanne,项目名称:coi-services,代码行数:31,代码来源:test_scheduler.py

示例11: test_create_single_timer

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
    def test_create_single_timer(self):
        # test creating a new timer that is one-time-only

        # create the timer resource
        # create the event listener
        # call scheduler to set the timer

        # create then cancel the timer, verify that event is not received

        # create the timer resource
        # create the event listener
        # call scheduler to set the timer
        # call scheduler to cancel the timer
        # wait until after expiry to verify that event is not sent
        self.single_timer_count = 0
        event_origin = "Time of Day"

        sub = EventSubscriber(event_type="ResourceEvent", callback=self.single_timer_call_back, origin=event_origin)
        sub.start()

        # Time out in 3 seconds
        now = datetime.datetime.utcnow() + timedelta(seconds=3)
        times_of_day =[{'hour': str(now.hour),'minute' : str(now.minute), 'second':str(now.second) }]
        ss = SchedulerService()
        id = ss.create_time_of_day_timer(times_of_day=times_of_day,  expires=time.time()+25200+60, event_origin=event_origin, event_subtype="")

        self.assertEqual(type(id), str)
        ss.cancel_timer(id)
        gevent.sleep(5)
        # Validate the event is not sent
        self.assertEqual(self.single_timer_count, 0)
开发者ID:pombredanne,项目名称:coi-services,代码行数:33,代码来源:test_scheduler.py

示例12: test_create_interval_timer_with_end_time

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
    def test_create_interval_timer_with_end_time(self):
        # create the interval timer resource
        # create the event listener
        # call scheduler to set the timer
        # receive a few intervals, validate that arrival time is as expected
        # Validate no more events are published after end_time expires
        # Validate the timer was canceled after the end_time expires

        self.interval_timer_count = 0
        self.interval_timer_sent_time = 0
        self.interval_timer_received_time = 0
        self.interval_timer_interval = 2

        event_origin = "Interval Timer"
        sub = EventSubscriber(event_type="ResourceEvent", callback=self.interval_timer_callback, origin=event_origin)
        sub.start()

        start_time = self.now_utc()
        self.interval_timer_end_time = start_time + 5
        id = self.ssclient.create_interval_timer(start_time="now" , interval=self.interval_timer_interval,
            end_time=self.interval_timer_end_time,
            event_origin=event_origin, event_subtype="")
        self.interval_timer_sent_time = datetime.datetime.utcnow()
        self.assertEqual(type(id), str)

        # Wait until all events are published
        gevent.sleep((self.interval_timer_end_time - start_time) + self.interval_timer_interval + 1)

        # Validate only 2 events are published
        self.assertEqual(self.interval_timer_count, 2)

        # Validate the timer was canceled after the end_time is expired
        with self.assertRaises(BadRequest):
            self.ssclient.cancel_timer(id)
开发者ID:kerfoot,项目名称:coi-services,代码行数:36,代码来源:test_scheduler.py

示例13: start_subscribers

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
def start_subscribers():
    """
    """
    global platform_sub
    global result_sub    
    global go_time
    global logfile 
    go_time = time.time()
    loc_time = time.localtime(go_time)
    fname = '2caa_log_%d_%d_%d.txt' % (loc_time[3],loc_time[4],loc_time[5])
    fname = tcaa_args['logfile_dir'] + fname
    logfile = open(fname, 'w')
    logfile.write('%15.6f %40s %6d %6d %6d %6d %6d %6d %6d\n' %
        (0.0, 'Start', status, queue_size, len(requests_sent),
         len(results_recv), len(results_pending), len(results_confirmed),
         len(results_error)))
    
    platform_sub = EventSubscriber(
        event_type='PlatformEvent',
        callback=consume_event,
        origin=tcaa_args['xs_name']
    )
    platform_sub.start()
    
    result_sub = EventSubscriber(
        event_type='RemoteCommandResult',
        callback=consume_event,
        origin='fake_id'
    )
    result_sub.start()
开发者ID:ednad,项目名称:coi-services,代码行数:32,代码来源:shell_utils.py

示例14: test_create_forever_interval_timer

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
    def test_create_forever_interval_timer(self):
        # Test creating interval timer that runs forever

        self.interval_timer_count = 0
        self.interval_timer_sent_time = 0
        self.interval_timer_received_time = 0
        self.interval_timer_interval = 3

        event_origin = "Interval Timer Forever"
        sub = EventSubscriber(event_type="ResourceEvent", callback=self.interval_timer_callback, origin=event_origin)
        sub.start()

        id = self.ssclient.create_interval_timer(start_time= self.now_utc(), interval=self.interval_timer_interval,
            end_time=-1,
            event_origin=event_origin, event_subtype=event_origin)
        self.interval_timer_sent_time = datetime.datetime.utcnow()
        self.assertEqual(type(id), str)

        # Wait for 4 events to be published
        gevent.sleep((self.interval_timer_interval * 4) + 1)
        self.ssclient.cancel_timer(id)

        # Validate the timer id is invalid once it has been canceled
        with self.assertRaises(BadRequest):
            self.ssclient.cancel_timer(id)

        # Validate events are not generated after canceling the timer
        self.assertEqual(self.interval_timer_count, 4)
开发者ID:kerfoot,项目名称:coi-services,代码行数:30,代码来源:test_scheduler.py

示例15: _start_event_subscriber

# 需要导入模块: from pyon.event.event import EventSubscriber [as 别名]
# 或者: from pyon.event.event.EventSubscriber import start [as 别名]
    def _start_event_subscriber(self, event_type="DeviceEvent",
                                sub_type=None,
                                count=0):
        """
        Starts event subscriber for events of given event_type ("DeviceEvent"
        by default) and given sub_type ("platform_event" by default).
        """

        def consume_event(evt, *args, **kwargs):
            # A callback for consuming events.
            log.info('Event subscriber received evt: %s.', str(evt))
            self._events_received.append(evt)
            if count == 0:
                self._async_event_result.set(evt)

            elif count == len(self._events_received):
                self._async_event_result.set()

        sub = EventSubscriber(event_type=event_type,
                              sub_type=sub_type,
                              callback=consume_event)

        sub.start()
        log.info("registered event subscriber for event_type=%r, sub_type=%r, count=%d",
                 event_type, sub_type, count)

        self._event_subscribers.append(sub)
        sub._ready_event.wait(timeout=EVENT_TIMEOUT)
开发者ID:jamie-cyber1,项目名称:coi-services,代码行数:30,代码来源:base_test_platform_agent_with_rsn.py


注:本文中的pyon.event.event.EventSubscriber.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。