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


Python SUBSCRIPTION_MANAGER.poll_all方法代码示例

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


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

示例1: test_poll_all

# 需要导入模块: from mpx.service.subscription_manager import SUBSCRIPTION_MANAGER [as 别名]
# 或者: from mpx.service.subscription_manager.SUBSCRIPTION_MANAGER import poll_all [as 别名]
 def test_poll_all(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     # Check that each invokation gets all values.
     for i in range(0,10):
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if len(all_values) != len(self.nrt1to4):
             # We did not get all 4 values!
             raise (
                 "poll_all(self.nrt1to4) did not return all values."
                 " (%d out of %d)" % (len(all_values),len(self.nrt1to4))
                 )
     # Check that (eventually) all the values are result dictionaries.
     all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         if None not in all_values.values():
             return
         time.sleep(0.1)
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     if None in all_values.values():
         raise (
             "Never got changes for all four result dictionaries, %d." %
             len(all_values)
             )
     return
开发者ID:mcruse,项目名称:monotone,代码行数:30,代码来源:_test_case_subscription_manager.py

示例2: scan_nodes_for_changes

# 需要导入模块: from mpx.service.subscription_manager import SUBSCRIPTION_MANAGER [as 别名]
# 或者: from mpx.service.subscription_manager.SUBSCRIPTION_MANAGER import poll_all [as 别名]
 def scan_nodes_for_changes(self):
     sub_dict = SM.poll_all(self.sid)
     self.node_values=sub_dict
     print 'scan_nodes_for_changes sm:', sub_dict
     if sub_dict: #if there have been any changes
         #look at the value in the sheet and send it if there is a difference
         for row_index in sub_dict.keys():
             try:
                 url, mode, value = self.sheet[row_index]
                 new_value = sub_dict[row_index]['value']
                 if mode < 3: #not write only
                     update = 0
                     print "compare: ", str(new_value), value
                     if str(new_value) != value:
                         update = 1
                         try:
                             if new_value == eval(value): #check numeric comparison
                                 update = 0
                         except:
                             pass #text words won't eval
                     if update:
                         print 'scan_nodes_for_changes set_cell:', row_index
                         self.set_cell(row_index, 3, new_value) 
             except:
                 msglog.exception()
开发者ID:mcruse,项目名称:monotone,代码行数:27,代码来源:spreadsheet.py

示例3: test_targeted_event_handling

# 需要导入模块: from mpx.service.subscription_manager import SUBSCRIPTION_MANAGER [as 别名]
# 或者: from mpx.service.subscription_manager.SUBSCRIPTION_MANAGER import poll_all [as 别名]
    def test_targeted_event_handling(self):
        event_maker = EventProducerTestClass()
        event_maker.configure({'name':'EventProducerTester','parent':'/'})
        event_maker.start()
        nr = {1:event_maker}
        sid = SUBSCRIPTION_MANAGER.create_delivered(self, nr)

        # Wait for polling to start and verify value made it without any events
        t1 = time.time()
        while (time.time() - t1) < 1.0:
            all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
            time.sleep(0.1)
        # Check that subscription value is the initial value of 100
        if all_values[1]['value'] != 100:
            raise ("polled_event_handling did not return inital value: " +
                   str(all_values[1]['value']))
        # make a rapid series of changes to the node value
        for i in range(10):
            event_maker._cov_check(i)
            time.sleep(0.1)
        # check change count, should be approx 10
        value_updates = self.__event_updated_values[1]['changes']
        cov_counts = self._cov_counter
        if value_updates < cov_counts:
            raise (
                "Targeted event handling event count did not match %d vs %d"
                % (value_updates, cov_counts)
                )
开发者ID:mcruse,项目名称:monotone,代码行数:30,代码来源:_test_case_subscription_manager.py

示例4: test_poll_all_plus_exceptions

# 需要导入模块: from mpx.service.subscription_manager import SUBSCRIPTION_MANAGER [as 别名]
# 或者: from mpx.service.subscription_manager.SUBSCRIPTION_MANAGER import poll_all [as 别名]
 def test_poll_all_plus_exceptions(self):
     SUBSCRIPTION_MANAGER._set_tunable_parameters({
         'minimum_poll_interval':0.0,
         })
     nrt1to4bad5to6 = {}
     nrt1to4bad5to6.update(self.nrt1to4)
     nrt1to4bad5to6['/services/time/is/an/illusion'] = (
         '/services/time/is/an/illusion'
         )
     nrt1to4bad5to6['/services/exception'] = '/services/exception'
     sid = SUBSCRIPTION_MANAGER.create_polled(nrt1to4bad5to6)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != nrt1to4bad5to6:
         raise "Initial node reference table mismatch."
     # Check that each invokation gets all values.
     for i in range(0,10):
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if len(all_values) != len(nrt1to4bad5to6):
             # We did not get all 4 values!
             raise (
                 "poll_all(self.nrt1to4) did not return all values."
                 " (%d out of %d)" % (len(all_values),len(nrt1to4bad5to6))
                 )
     # Check that (eventually) all the values are result dictionaries.
     all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         if None not in all_values.values():
             self.__all_plus_exceptions_check(all_values)
             # Finally, test that a new subscription gets the correct
             # results.
             time.sleep(0.1)
             sid = SUBSCRIPTION_MANAGER.create_polled(nrt1to4bad5to6)
             time.sleep(0.1)
             all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
             self.__all_plus_exceptions_check(all_values)                
             time.sleep(0.1)
             all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
             self.__all_plus_exceptions_check(all_values)                
             return
         time.sleep(0.1)
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     if None in all_values.values():
         raise ("Never got values for all nodes: %r." % all_values)
     return
开发者ID:mcruse,项目名称:monotone,代码行数:47,代码来源:_test_case_subscription_manager.py

示例5: __values_changing

# 需要导入模块: from mpx.service.subscription_manager import SUBSCRIPTION_MANAGER [as 别名]
# 或者: from mpx.service.subscription_manager.SUBSCRIPTION_MANAGER import poll_all [as 别名]
 def __values_changing(self, sid):
     r1 = SUBSCRIPTION_MANAGER.poll_all(sid)
     t1 = time.time()
     while 1:
         changed_values = SUBSCRIPTION_MANAGER.poll_changed(sid)
         if len(changed_values):
             return
         if (time.time() - t1) > 1.0:
             raise "Never got changes for any of the values."
         time.sleep(0.1)
     assert 1, "Can't reach here."
开发者ID:mcruse,项目名称:monotone,代码行数:13,代码来源:_test_case_subscription_manager.py

示例6: resync

# 需要导入模块: from mpx.service.subscription_manager import SUBSCRIPTION_MANAGER [as 别名]
# 或者: from mpx.service.subscription_manager.SUBSCRIPTION_MANAGER import poll_all [as 别名]
 def resync(self):
     try:
         print 'resync'
         new_sheet = self.get_sheet()
         #subscribe to nodes that need to be read
         sub_dict = {} #dictionary to create subscriptions
         for row_index in new_sheet.keys():
             url, mode, value = new_sheet[row_index]
             if mode < 3: #need to subscribe to non-write-only
                 sub_dict[row_index] = url
             #for nodes that need to be set from values in the spreadsheet
             if mode == 2 or mode == 3: #need to set
                 try:
                     as_node(url).set(value) #value is a string or None
                 except:
                     msglog.exception()
         self.sheet = new_sheet
         if sub_dict: #create a new subscription then delete the old one
             sid = SM.create_polled(sub_dict)
             if self.sid:
                 SM.destroy(self.sid)
             self.sid = sid
             sub_dict = SM.poll_all(sid)
             self.node_values = sub_dict
             #update the spread sheet
             for row_index in sub_dict.keys():
                 url, mode, value = new_sheet[row_index]
                 if mode == 0 or mode == 1: #need to write
                     try:
                         self.set_cell(row_index, 3, sub_dict[row_index]['value']) 
                     except:
                         msglog.exception()
         #the spreadsheet and mediator should now be in sync
         self.scan()
     except:
         msglog.exception()
开发者ID:mcruse,项目名称:monotone,代码行数:38,代码来源:spreadsheet.py

示例7: invoke_batch_async

# 需要导入模块: from mpx.service.subscription_manager import SUBSCRIPTION_MANAGER [as 别名]
# 或者: from mpx.service.subscription_manager.SUBSCRIPTION_MANAGER import poll_all [as 别名]
  def invoke_batch_async(self, sessionID, *qualified_method_list):
    subscription = None
    if not self.manager().validate(sessionID, touch=1):
      if self._subscriptions.has_key(sessionID):
        try:
          subscription = self._subscriptions[sessionID]
          del self._subscriptions[sessionID]
          del self._qualified_method_list[sessionID]
          del self._services[sessionID]
          del self._methods[sessionID]
          SUBSCRIPTION_MANAGER.destroy(subscription)
        except:
          msglog.log('RNA_XMLRPC_Handler',msglog.types.WARN,
                     "Error destroying subscription %r on stale session %r." %
                     (subscription, sessionID))
          msglog.exception()
      raise EInvalidSession('Invalid session')

    if self._subscriptions.has_key(sessionID):
      subscription = self._subscriptions[sessionID]
      if (self._qualified_method_list[sessionID] != qualified_method_list):
        # New batch, destroy the out of date subscription.
        try:
          del self._subscriptions[sessionID]
          del self._qualified_method_list[sessionID]
          del self._services[sessionID]
          del self._methods[sessionID]
          SUBSCRIPTION_MANAGER.destroy(subscription)
        except:
          msglog.log('RNA_XMLRPC_Handler',msglog.types.WARN,
                     "Error destroying previous subscription %r." %
                     (subscription,))
          msglog.exception()
        subscription = None

    if subscription is None:
      #
      # No subscription matching the batch, create one!
      # Build a node_reference_table:
      subscription_map = {}
      services = []
      methods = []
      for i in range(0,len(qualified_method_list)):
        rna = qualified_method_list[i]
        i_method = rna.rfind(':')
        if i_method == -1 or (i_method == 3 and rna[:3] == "mpx"):
          # There is no method specified.
          rna_node = rna
          rna_method = ''
        else:
          rna_node = rna[:i_method]
          rna_method = rna[i_method+1:]
        services.append(rna_node)
        methods.append(rna_method)
        if methods[i] == 'get':
          subscription_map[services[i]] = services[i]
      # Create the subscription using the genereated node_reference_table:
      subscription = SUBSCRIPTION_MANAGER.create_polled(subscription_map,
                                                        5*60.0)
      self._subscriptions[sessionID] = subscription
      self._qualified_method_list[sessionID] = qualified_method_list
      self._services[sessionID] = services
      self._methods[sessionID] = methods
      #
      # Now that we've added our node's, validate the other sessions.
      #
      validate_list = []
      validate_list.extend(self._subscriptions.keys())
      for test_session in validate_list:
        if not self.manager().validate(test_session, touch=0):
          expired = None
          try:
            expired = self._subscriptions[test_session]
            del self._subscriptions[test_session]
            del self._qualified_method_list[test_session]
            del self._services[test_session]
            del self._methods[test_session]
            SUBSCRIPTION_MANAGER.destroy(expired)
          except:
            msglog.log('RNA_XMLRPC_Handler',msglog.types.WARN,
                       "Error destroying subscription %r on stale session %r." %
                       (expired, test_session))
            msglog.exception()
    # Get all 'ready' values.
    services = self._services[sessionID]
    methods = self._methods[sessionID]
    polled_values = SUBSCRIPTION_MANAGER.poll_all(subscription)
    results = []
    for i in range(0,len(services)):
      service = services[i]
      try:
        if methods[i] == 'get':
          result = polled_values[service]
          if result is None:
              result = 'error: Waiting for update...'
          else:
              result = result['value']
          if isinstance(result,Exception):
            result = self._exception_string(result)
        else:
#.........这里部分代码省略.........
开发者ID:mcruse,项目名称:monotone,代码行数:103,代码来源:rna_xmlrpc.py

示例8: subscription_poll_all

# 需要导入模块: from mpx.service.subscription_manager import SUBSCRIPTION_MANAGER [as 别名]
# 或者: from mpx.service.subscription_manager.SUBSCRIPTION_MANAGER import poll_all [as 别名]
 def subscription_poll_all(self, sessionID, sid):
   # Raise exception if this is not a valid session
   if not self.manager().validate(sessionID, touch=1):
     raise EInvalidSession('Invalid session')
   return SUBSCRIPTION_MANAGER.poll_all(sid)
开发者ID:mcruse,项目名称:monotone,代码行数:7,代码来源:rna_xmlrpc.py


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