PHP Classes

File: test/

Recommend this page to a friend!
  Classes of Nikos M.  >  PHP Publish Subscribe  >  test/  >  Download  
File: test/
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP Publish Subscribe
Register and call handlers of events by name
Author: By
Last change:
Date: 1 year ago
Size: 1,872 bytes


Class file image Download
#!/usr/bin/env python

import os, sys
import pprint

# import the engine (as a) module, probably you will want to place this in another dir/package
import imp
PBSModulePath = os.path.join(os.path.dirname(__file__), '../src/python/')
    PBSFp, PBSPath, PBSDesc  = imp.find_module('PublishSubscribe', [PBSModulePath])
    PublishSubscribe = getattr( imp.load_module('PublishSubscribe', PBSFp, PBSPath, PBSDesc), 'PublishSubscribe' )
except ImportError as exc:
    PublishSubscribe = None
    sys.stderr.write("Error: failed to import module ({})".format(exc))
    if PBSFp: PBSFp.close()

if not PublishSubscribe:
    print ('Could not load the PublishSubscribe Module')
    print ('PublishSubscribe Module loaded succesfully')

print('PublishSubscribe.VERSION = ' + PublishSubscribe.VERSION + "\n")

def _log( evt):
    print( pprint.pformat({'topic': evt.topic, 'originalTopic': evt.originalTopic, 'tags': evt.tags, 'namespaces': evt.namespaces, 'timestamp': evt.timestamp}, 4) )
    print( pprint.pformat(, 4) )
def handler1(evt):
    print('Handler1' + "\n")
    _log( evt)
    # event abort
    #evt.abort( )
    # stop bubble propagation
    #evt.propagate( False )
    # stop propagation on same event
    #evt.stop( )
    #return False

def handler2(evt):
    print('Handler2' + "\n")
    _log( evt)

def handler3(evt):
    print('Handler3' + "\n")
    _log( evt)

def handler4(evt):
    print('Handler4' + "\n")
    _log( evt)

pb = PublishSubscribe( )
pb.on('Topic1/SubTopic11#Tag1#Tag2', handler1).on1('Topic1/SubTopic11#Tag1#Tag2@NS1', handler2).on('Topic1/SubTopic11#Tag1#Tag2@NS1@NS2', handler3).off('@NS1@NS2').pipeline('Topic1/SubTopic11#Tag2#Tag1', {'key1': 'value1'}).pipeline('Topic1/SubTopic11#Tag2#Tag1@NS1', {'key1': 'value1'})
For more information send a message to info at phpclasses dot org.