Changes between Version 2 and Version 3 of IpaacaTutorial


Ignore:
Timestamp:
12/10/13 11:54:24 (6 years ago)
Author:
yaghoubzadeh
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IpaacaTutorial

    v2 v3  
    4949 
    5050def my_first_iu_handler(iu, event_type, local): 
    51         if event_type in ['ADDED', 'MESSAGE']: 
    52                 print( u'Received a new IU or Message of category: ' + iu.category ) 
     51        # event_type is one of ADDED, UPDATED, RETRACTED, MESSAGE 
     52        if event_type == 'ADDED': 
     53                # you can also branch iu.category if you have more than one interest for the buffer 
     54                print( u'Received a new IU of category: ' + iu.category ) 
    5355                print( u'  The UID is: ' + iu.uid ) 
    5456                print( u'  The payload is: ' + unicode(iu.payload) ) 
    55                  
     57                # accessing fields 
     58                old_value = iu.payload['someKey'] 
     59                # the next line is a remote write and will only succeed for IUs (not Messages) 
     60                iu.payload['someKey'] = 'updatedByMeJustNow' 
     61                # Note: you also should embed remote writes in a try block catching any 
     62                # IUUpdateFailedError (meaning the IU has been changed remotely in the mean time) 
    5663 
     64# make a new InputBuffer (you can produce any number), with the category interests as a second argument 
    5765my_inbuffer = ipaaca.InputBuffer('MyArbitraryName', ['interestingCategory']) 
     66# register an IU event handler (you can register more than one) 
    5867my_inbuffer.register_handler(my_first_iu_handler) 
    5968