Exemplo n.º 1
0
def main(mode):
    comm = iinic.USBComm() if Config.ON_DEVICE else iinic.NetComm()
    nic = iinic.NIC(comm)
    frameLayer = FrameLayer(nic)
    myId = frameLayer.getMyId()
    print >> sys.stderr, 'NIC initialized. My id is', frameLayer.getMyId()
    dispatcher = Dispatcher(frameLayer)
    
    if mode == 'd':
        sample = SampleProto()
        dispatcher.registerProto(sample, 'sample')
        
        pp = PingPongProto()
        dispatcher.registerProto(pp, 'ping-pong')
        
        try:
            dispatcher.registerProto(sample, 'sample')
        except:
            pass # yes, we expected you, Mr. Exception
        
        dispatcher.scheduleCallback(sample.sampleCallback, time.time()+1)
        dispatcher.scheduleCallback(sampleCallback, time.time()+2)
        dispatcher.scheduleRepeatingCallback(sampleCallback, time.time()+3, 10)
        dispatcher.loop()
    
    if mode == 'r':
        monitor = MonitorProto()
        dispatcher.registerProto(monitor, 'monitor')
        dispatcher.loop()

    if mode == 's':
        frameLayer.sendFrame('s', myId, 0, 'blah')
        approx = frameLayer.nic.get_approx_timing() # TODO: expose this method
        frameLayer.sendFrame('x', myId, 0, 'blah blah', approx + 2000000)
Exemplo n.º 2
0
    def __init__(self, logger, hardware, scheduler):
        # Logger
        self._logger = logger

        # Inicio el Hardware que me llega por parametros
        self._hardware = hardware

        # Software
        self._dispatcher = Dispatcher(self._hardware.cpu, self._hardware.mmu,
                                      self._hardware.timer)  #para continuo
        # self._dispatcher = DispatcherPages(self._hardware.cpu, self._hardware.mmu, self._hardware.timer) #para paginacion
        self._scheduler = scheduler
        self._pcbTable = PCBTable()
        self._interruptVector = hardware.interruptVector

        self._interruptVector.setKernel(self)

        # IRQ
        #  self._newIRQ = IRQ("NEW")
        self._killIRQ = IRQ("KILL")
        #  self._ioInIRQ = IRQ("IO_IN")
        #  self._ioOutIRQ = IRQ("IO_OUT")
        #  self._timeOut = IRQ("TIME_OUT")

        # Por ahora interruptVector es un hibrido (Hard/Soft)
        #self._interruptVector.sekernel = self

        # Interrupt Handlers config
        self._interruptVector.register(self._killIRQ.type, KillHandler(self))
 def simulate_partial(self, rho, i, output: list, overheads: list, jbt, custom, seed):
     dispatcher = Dispatcher(self.number_of_tasks,
                             self.number_of_servers,
                             rho, self.d, seed,
                             jbt=jbt, custom=custom)
     mean_sys_delay, overhead = dispatcher.execute_simulation()
     output.append((i, mean_sys_delay))
     overheads.append((i, overhead))
Exemplo n.º 4
0
 def initData(self, serverIP, serverPort, sleepInterval, parent):
     self.serverIP = serverIP
     self.serverPort = serverPort
     self.sleepInterval = sleepInterval
     self.dispatcher = Dispatcher()
     self.parent = parent
     self.isAlive = True
     self.hasBegan = False
Exemplo n.º 5
0
def main():
    #interface on which capture packets
    interface = input('interface: ')
    if len(interface) == 0:
        print('Not valid interface.')
        sys.exit()

    #own ip
    ipaddress = ni.ifaddresses(interface)[ni.AF_INET][0]['addr']

    #-------------------------------------------------------------------------------------------#
    #two data structure used to analyze packets and store the flows
    global buff
    buff = Buffer()
    pkt_str = PacketsStr()

    #threads used to analyze the flows and their content
    dispatcher = Dispatcher(buff, pkt_str, ipaddress)
    scanner = PortScanner(pkt_str)
    visual = Visual(pkt_str)

    dispatcher.start()
    scanner.start()
    visual.start()

    #starting to sniff packets
    capture = sniff(filter='ip',
                    session=IPSession,
                    prn=traffic_handler,
                    count=0,
                    iface=interface)

    #at the and of the sniff, when Ctrl+C key is pressed, termination variable is set to notify threads
    dispatcher.term.set()
    scanner.term.set()
    visual.term.set()

    #to wake the threads which are waiting for new packets
    time.sleep(1)
    with buff._mutex:
        buff._mutex.notify()

    with pkt_str._lockPkts:
        pkt_str._lockPkts.notify()

    dispatcher.join()
    scanner.join()
    visual.join()

    #print some information about the number of unknown and known packets
    print("\nUnknown packets: %d" % len(pkt_str.unknown))
    print("Packets of unknown process: %d" % len(pkt_str.unanalizedPkt))
    print("Total packets: %d" % len(capture))
Exemplo n.º 6
0
def startup(args: argparse.Namespace, **kwargs: Dict[str, Any]) -> None:
    global announce, dispatcher, group, httpServer, notification, validator
    global registration, remote, security, statistics, storage, event
    global rootDirectory
    global aeStatistics

    rootDirectory = os.getcwd()  # get the root directory
    os.environ[
        "FLASK_ENV"] = "development"  # get rid if the warning message from flask.
    # Hopefully it is clear at this point that this is not a production CSE

    # Handle command line arguments and load the configuration
    if args is None:
        args = argparse.Namespace(
        )  # In case args is None create a new args object and populate it
        args.configfile = None
        args.resetdb = False
        args.loglevel = None
        for key, value in kwargs.items():
            args.__setattr__(key, value)

    if not Configuration.init(args):
        return

    # init Logging
    Logging.init()
    Logging.log('============')
    Logging.log('Starting CSE')
    Logging.log('CSE-Type: %s' % C.cseTypes[Configuration.get('cse.type')])
    Logging.log(Configuration.print())

    # Initiatlize the resource storage
    storage = Storage()

    # Initialize the event manager
    event = EventManager()

    # Initialize the statistics system
    statistics = Statistics()

    # Initialize the registration manager
    registration = RegistrationManager()

    # Initialize the resource validator
    validator = Validator()

    # Initialize the resource dispatcher
    dispatcher = Dispatcher()

    # Initialize the security manager
    security = SecurityManager()

    # Initialize the HTTP server
    httpServer = HttpServer()

    # Initialize the notification manager
    notification = NotificationManager()

    # Initialize the announcement manager
    announce = AnnouncementManager()

    # Initialize the group manager
    group = GroupManager()

    # Import a default set of resources, e.g. the CSE, first ACP or resource structure
    importer = Importer()
    if not importer.importResources():
        return

    # Initialize the remote CSE manager
    remote = RemoteCSEManager()
    remote.start()

    # Start AEs
    startAppsDelayed(
    )  # the Apps are actually started after the CSE finished the startup

    # Start the HTTP server
    event.cseStartup()  # type: ignore
    Logging.log('CSE started')
    httpServer.run()  # This does NOT return
Exemplo n.º 7
0
# __BEGIN_LICENSE__
# Copyright (C) 2008-2010 United States Government as represented by
# the Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
# __END_LICENSE__

from Dispatcher import Dispatcher
import exampleConfig


def handleConnect(sock):
    print 'got connection'


def handleLine(sock, line):
    print 'got:', line
    sock.write('ciao\n')

com = Dispatcher(moduleName='exampleServer')
if exampleConfig.NOTIFY_ENDPOINT:
    com.connectToNotificationService(exampleConfig.NOTIFY_ENDPOINT)
com.listen(exampleConfig.SERVER_ENDPOINT,
           connectHandler=handleConnect,
           lineHandler=handleLine)
if exampleConfig.USE_SERVICE_DISCOVERY:
    com.findServices(protoName=exampleConfig.PROTOCOL, announceServices=[exampleConfig.SERVER_ENDPOINT])
com.runForever()
Exemplo n.º 8
0
 def registerExtenderCallbacks(self, callbacks):
     self.mCallBacks = callbacks
     self.config = Config(callbacks)
     self.loader = Loader(self.config)
     self.dispatcher = Dispatcher(self.config, self.loader.getPlugins())
Exemplo n.º 9
0
def main():
    program = Program()
    cs_id = 0
    random.seed()
    while True:
        try:
            filename = input("Program name: ")
            file = open(filename, 'r')
            break
        except FileNotFoundError:
            print("File not found!")
    program.number_of_processes = int(input("Number of processes: "))
    tables.memory = int(input("Memory Size: "))
    instructions = []
    for line in file:
        if line == 'EXE':
            break
        elif 'Name: ' in line:
            program.name = line.split(' ', 1)[1].splitlines()[0]
        elif 'Total runtime: ' in line:
            program.runtime = int(line.split(': ')[1])
        elif 'Memory: ' in line:
            program.memory = int(line.split(': ')[1])
        elif line != '\n':
            current_line = line.split()
            if "CRITICAL BEGIN" in line:
                begin_idx = len(instructions)
                cs = CriticalSection(cs_id, begin_idx)
                program.critical_sections.append(cs)
                tables.critical_sections[cs.id] = cs
                instructions.append(Instruction("CRITICAL BEGIN", cs_id))
                cs_id += 1
            elif "CRITICAL END" in line:
                end_idx = len(instructions)
                for cs in program.critical_sections:
                    if cs.id == cs_id - 1:
                        cs.end_idx = end_idx
                        instructions.append(Instruction("CRITICAL END", cs.id))
                        tables.critical_sections[cs.id].end_idx = end_idx
                        break
            elif len(current_line) == 1:
                instructions.append(Instruction(current_line[0], 0))
            else:
                instructions.append(
                    Instruction(current_line[0], int(current_line[1])))
    program.instructions = instructions

    missing_end_tags = 0
    for cs in program.critical_sections:
        if cs.end_idx == -1:
            missing_end_tags += 1
    if missing_end_tags > 0:
        print(
            f'{missing_end_tags} critical section(s) are missing \'CRITICAL END\' commands'
        )
        exit()

    print(f'Program loaded: {program.name}({program.number_of_processes})')

    processes = [
        Process(copy.deepcopy(program), pid)
        for pid in range(program.number_of_processes)
    ]
    print('Randomizing...')
    for process in processes:
        # random.shuffle(process.program.instructions)
        for instruction in\
                (instruction for instruction in process.program.instructions if instruction.command == 'CALCULATE'):
            instruction.value = random.randint(
                math.floor(instruction.value / 2), instruction.value * 2)
    pcbs = [PCB(process) for process in processes]
    for pcb in pcbs:
        pcb.process.pcb = pcb

    for pcb in pcbs:
        print(f'------Process {pcb.process.pid}------')
        for instruction in pcb.process.program.instructions:
            print(f'{instruction.command}: {instruction.value}')
        print(f'---------------------')
    input('Press enter/return to start execution...')

    dispatcher = Dispatcher()
    scheduler = Scheduler(dispatcher)
    dispatcher.connect_scheduler(scheduler)
    scheduler.start()
    tables.PCBs = pcbs
    scheduler.pcb_lock.set()

    gui = ProcessGUI()
    gui.start()

    scheduler.run_thread.join()
Exemplo n.º 10
0
def handleLine(sock, line):
    print 'got:', line


def handleService(finder, serviceName, serviceEvent):
    print 'handling notification of service %s at event %s' % (serviceName,
                                                               serviceEvent)
    if serviceName == exampleConfig.SERVER_ENDPOINT:
        com.connect(serviceEvent,
                    connectHandler=handleConnect,
                    lineHandler=handleLine)


def handleStdin(sock, line):
    print 'you said:', line


com = Dispatcher(moduleName='exampleClient')
if exampleConfig.NOTIFY_ENDPOINT:
    com.connectToNotificationService(exampleConfig.NOTIFY_ENDPOINT)
if exampleConfig.USE_SERVICE_DISCOVERY:
    com.findServices(protoName=exampleConfig.PROTOCOL,
                     serviceHandler=handleService)
else:
    handleService(None, exampleConfig.SERVER_ENDPOINT,
                  exampleConfig.SERVER_ENDPOINT)
com.connect('console:', lineHandler=handleStdin)

com.runForever()
Exemplo n.º 11
0
from Dispatcher import Dispatcher
from CalculationUnit import CalculationUnit
from MyProcess import MyProcess
from Table import Table

dispatcher = Dispatcher()
unite1 = CalculationUnit("127.0.0.1", 4898)
#unite2 = CalculationUnit("127.0.0.1", 4899)
processMultiplyArray = MyProcess()

unite1.attach_process(processMultiplyArray)
#unite2.attach_process(processMultiplyArray)

#  unite2 = CalculationUnit("192.168.1.12", 4898)
#  unite1.attach_process(processMultiplyArray)

dispatcher.add_calculation_unit(unite1)
#dispatcher.add_calculation_unit(unite2)


def endTask(resultat):
    print(resultat.to_string())


t1 = Table(1, 64)
for i in range(0, 64):
    t1.append(i)

if dispatcher.prepare():
    print("YES")
    dispatcher.distribute_data(t1)
Exemplo n.º 12
0
	Logger()
	parser = optparse.OptionParser()
	parser.add_option('-C', '--city', action='store', dest='city', help='set city')
	parser.add_option('-c', '--community_spider', action='store_true', dest='community_spider', help='enable spider of all community')
	parser.add_option('-d', '--deal_spider', action='store_true', dest='deal_spider', help='enable spider of deal')
	parser.add_option('-H', '--house_spider', action='store_true', dest='house_spider', help='enable spider of house')
	parser.add_option('-a', '--analyze_deal', action='store_true', dest='analyze_deal', help='enable analyze deal')
	parser.add_option('-m', '--music', action='store', dest='music', help='play music when end')
	parser.add_option('-P', '--post_handle', action='store_true', dest='post_handle', help='enable post handle')
	parser.add_option('-t', '--test', action='store_true', dest='test', help='enable test')
	parser.add_option('-b', '--book', action='store_true', dest='book', help='enable book')
	parser.add_option('-n', '--new_community', action='store_true', dest='new_community', help='enable new_community')
	parser.add_option('-T', '--tag', action='store', dest='tag', help='tag')
	options, args = parser.parse_args()

	dispatcher = Dispatcher(options.tag or '')
	dispatcher.set_network_service(NetworkService())

	if options.city:
		cities = options.city.split()
	else:
		cities = ('cd', )
	if options.community_spider:
		logging.info('using community spider')
		for city in cities:
			community(dispatcher, city)
	if options.house_spider:
		logging.info('using house spider')
		for city in cities:
			house(dispatcher, city)
	if options.deal_spider:
Exemplo n.º 13
0
def startup(args: argparse.Namespace, **kwargs: Dict[str, Any]) -> None:
    global announce, dispatcher, group, httpServer, notification, validator
    global registration, remote, request, security, statistics, storage, event
    global rootDirectory
    global aeStatistics
    global supportedReleaseVersions, cseType, defaultSerialization, cseCsi, cseRi, cseRn
    global cseOriginator
    global isHeadless

    rootDirectory = os.getcwd()  # get the root directory
    os.environ[
        "FLASK_ENV"] = "development"  # get rid if the warning message from flask.
    # Hopefully it is clear at this point that this is not a production CSE

    # Handle command line arguments and load the configuration
    if args is None:
        args = argparse.Namespace(
        )  # In case args is None create a new args object and populate it
        args.configfile = None
        args.resetdb = False
        args.loglevel = None
        args.headless = False
        for key, value in kwargs.items():
            args.__setattr__(key, value)
    isHeadless = args.headless

    if not Configuration.init(args):
        return

    # Initialize configurable constants
    supportedReleaseVersions = Configuration.get(
        'cse.supportedReleaseVersions')
    cseType = Configuration.get('cse.type')
    cseCsi = Configuration.get('cse.csi')
    cseRi = Configuration.get('cse.ri')
    cseRn = Configuration.get('cse.rn')
    cseOriginator = Configuration.get('cse.originator')

    defaultSerialization = Configuration.get('cse.defaultSerialization')

    # init Logging
    Logging.init()
    if not args.headless:
        Logging.console('Press ? for help')
    Logging.log('============')
    Logging.log('Starting CSE')
    Logging.log(f'CSE-Type: {cseType.name}')
    Logging.log('Configuration:')
    Logging.log(Configuration.print())

    # Initiatlize the resource storage
    storage = Storage()

    # Initialize the event manager
    event = EventManager()

    # Initialize the statistics system
    statistics = Statistics()

    # Initialize the registration manager
    registration = RegistrationManager()

    # Initialize the resource validator
    validator = Validator()

    # Initialize the resource dispatcher
    dispatcher = Dispatcher()

    # Initialize the request manager
    request = RequestManager()

    # Initialize the security manager
    security = SecurityManager()

    # Initialize the HTTP server
    httpServer = HttpServer()

    # Initialize the notification manager
    notification = NotificationManager()

    # Initialize the group manager
    group = GroupManager()

    # Import a default set of resources, e.g. the CSE, first ACP or resource structure
    # Import extra attribute policies for specializations first
    importer = Importer()
    if not importer.importAttributePolicies() or not importer.importResources(
    ):
        return

    # Initialize the remote CSE manager
    remote = RemoteCSEManager()

    # Initialize the announcement manager
    announce = AnnouncementManager()

    # Start AEs
    startAppsDelayed(
    )  # the Apps are actually started after the CSE finished the startup

    # Start the HTTP server
    event.cseStartup()  # type: ignore
    httpServer.run()  # This does return (!)

    Logging.log('CSE started')
    if isHeadless:
        # when in headless mode give the CSE a moment (2s) to experience fatal errors before printing the start message
        BackgroundWorkerPool.newActor(
            delay=2,
            workerCallback=lambda: Logging.console('CSE started')
            if not shuttingDown else None).start()

    #
    #	Enter an endless loop.
    #	Execute keyboard commands in the keyboardHandler's loop() function.
    #
    commands = {
        '?': _keyHelp,
        'h': _keyHelp,
        '\n': lambda c: print(),  # 1 empty line
        '\x03': _keyShutdownCSE,  # See handler below
        'c': _keyConfiguration,
        'C': _keyClearScreen,
        'D': _keyDeleteResource,
        'i': _keyInspectResource,
        'l': _keyToggleLogging,
        'Q': _keyShutdownCSE,  # See handler below
        'r': _keyCSERegistrations,
        's': _keyStatistics,
        't': _keyResourceTree,
        'T': _keyChildResourceTree,
        'w': _keyWorkers,
    }

    #	Endless runtime loop. This handles key input & commands
    #	The CSE's shutdown happens in one of the key handlers below
    loop(commands, catchKeyboardInterrupt=True, headless=args.headless)
    shutdown()
Exemplo n.º 14
0
	socket.setdefaulttimeout(5)
	web_addr = urlopen('http://automation.whatismyip.com/n09230945.asp').read()
	socket.setdefaulttimeout(timeout)
	_root.console_write(web_addr)
except:
	web_addr = local_addr
	_root.console_write('not online')
_root.console_write()

_root.local_ip = local_addr
_root.online_ip = web_addr

_root.console_write('Listening for clients on port %i'%port)
_root.console_write('Using %i client handling thread(s).'%_root.max_threads)

dispatcher = Dispatcher(_root, server)
_root.dispatcher = dispatcher

chanserv = True
if chanserv:
	address = ((web_addr or local_addr), 0)
	chanserv = ChanServ.ChanServClient(_root, address, _root.session_id)
	dispatcher.addClient(chanserv)
	_root.chanserv = chanserv

try:
	dispatcher.pump()
except KeyboardInterrupt:
	_root.console_write()
	_root.console_write('Server killed by keyboard interrupt.')
except:
Exemplo n.º 15
0
# __BEGIN_LICENSE__
# Copyright (C) 2008-2010 United States Government as represented by
# the Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
# __END_LICENSE__

from Dispatcher import Dispatcher
from SharedScheduler import scheduler
import exampleConfig


def publishMessage():
    com.publish('%s:foo' % exampleConfig.PROTOCOL, 'bar')
    print 'published message'


com = Dispatcher(moduleName='examplePublisher')
com.connectToNotificationService(exampleConfig.NOTIFY_ENDPOINT)
scheduler.enterPeriodic(period=1.0, action=publishMessage)
scheduler.runForever()
def Listner(Host, Port, SSL, QueueName, ExchangeName, ConfigPaths):

    #Choosing between normal connection to secure connection
    if SSL:
        connection = pika.BlockingConnection(
            pika.ConnectionParameters(Host, Port, ssl=True, ssl_options=SSL))
    else:
        connection = pika.BlockingConnection(
            pika.ConnectionParameters(Host, Port))

    channel = connection.channel()

    disp = Dispatcher(ConfigPaths)
    #Loading Algorithms configurations
    disp.loadAlgorithms(ConfigPaths['prefix'] +
                        ConfigPaths['ConfigAlgorithms'] + '/Algorithms.yml')
    #Loading Commands configurations
    disp.loadCommands(ConfigPaths['prefix'] + ConfigPaths['ConfigAlgorithms'] +
                      '/Commands.json')

    channel.exchange_declare(exchange=ExchangeName, durable=True)
    channel.queue_declare(queue=QueueName)

    channel.queue_bind(exchange=ExchangeName, queue=QueueName)

    channel.exchange_declare(exchange='rpc_queue')
    channel.queue_declare(queue='rpc_queue')

    channel.queue_bind(exchange='rpc_queue', queue='rpc_queue')

    print(' [*] Waiting for messages. To exit press CTRL+C')

    #Method for NO-RPC call
    def callback(ch, method, properties, body):

        text = body.decode(encoding="utf-8", errors="strict")
        print(text)
        if (text == 'Hello World!') or (text == 'hello'):
            ch.basic_ack(delivery_tag=method.delivery_tag)
            return
        Stringio = StringIO(body)
        data = json.load(Stringio)

        if data['Command'] == disp.getCommand('Add Participant'):
            print('Add-Participant')
            print(disp.addParticipant(data['Participant']))
            print('Everything OK')

        if data['Command'] == disp.getCommand('Insert Event'):
            print('Add-Compute')
            global ids
            data['Event']['ID'] = str(ids)
            ids = ids + 1

            eve = disp.insertEvent(data['Participant'], data['Event'])
            if not eve:
                print("Somenthing wrong!!")
            else:
                print("EventID:" + str(eve[0]))
                disp.compute(data['Participant'], eve)

        print(" [x] Done!")
        ch.basic_ack(delivery_tag=method.delivery_tag)

    #Method for RPC CALL
    def on_request(ch, method, props, body):

        try:

            text = body.decode(encoding="utf-8", errors="strict")

            #parsing data
            Stringio = StringIO(text)
            data = json.load(Stringio)

            #print(data)
            if data['Command'] == disp.getCommand('Add Participant'):
                print('Add Participant')
                ret = disp.addParticipant(data['Participant'])
                if ret:
                    response = 'ACK From Add Participant'
                else:
                    response = 'NACK From Add Participant'

            if data['Command'] == disp.getCommand('Insert Event'):
                print('Insert Event')

                global ids
                data['Event']['ID'] = str(
                    ids) + '_' + data['TimeStamp'] + '_' + data['Participant']
                ids = ids + 1

                eve = disp.insertEvent(data['Participant'], data['Event'])
                if not eve:
                    response = 'NACK From Insert Event'
                else:
                    print("EventID:" + str(eve[0]))
                    response = 'ID:' + str(eve[0])
                    disp.compute(data['Participant'], eve)

            if data['Command'] == disp.getCommand('List Event'):

                response = ''

                for event in disp.getAllEventFromParticipant(
                        data['Participant']):
                    #print(event)
                    printevent = event.getPrintEvent()
                    response = response + str(printevent) + '\n'

                if response == '':
                    response = 'Nothing to show From List Event'

            if data['Command'] == disp.getCommand('Delete Event'):

                ret = disp.deleteEvent(data['Participant'], data['ID'])
                if ret:
                    response = 'ACK From List Event'
                else:
                    response = 'NACK From List Event'

            if data['Command'] == disp.getCommand('Delete Password'):
                ret = disp.deletePassword(data['Participant'],
                                          data['Event']['HashPassword'])
                if ret:
                    response = 'ACK From Delete Password'
                else:
                    response = 'NACK Frome Delete Password'

            if data['Command'] == disp.getCommand('Delete WebSite'):
                disp.deleteWebsite(data['Participant'],
                                   data['Event']['Website'])

            if data['Command'] == disp.getCommand('Delete All Event'):
                ret = True

                for event in disp.getAllEventFromParticipant(
                        data['Participant']):
                    #print(event)
                    ret = ret and disp.deleteEvent(data['Participant'],
                                                   event.data['ID'])
                if ret:
                    response = 'ACK From All Event'
                else:
                    response = 'NACK From All Event'

            if data['Command'] == disp.getCommand('Delete Participant'):

                ret = disp.deleteParticipant(data['Participant'])
                if ret:
                    response = 'ACK From Delete Participant'
                else:
                    response = 'NACK From Delete Participant'

            #sending response
            ch.basic_publish(exchange='',
                             routing_key=props.reply_to,
                             properties=pika.BasicProperties(
                                 correlation_id=props.correlation_id),
                             body=response)
            ch.basic_ack(delivery_tag=method.delivery_tag)
            print(response)
        except:
            traceback.print_exc(file=sys.stdout)
            ch.basic_publish(exchange='',
                             routing_key=props.reply_to,
                             properties=pika.BasicProperties(
                                 correlation_id=props.correlation_id),
                             body='ERROR SOMETHING GOES WRONG!')
            ch.basic_ack(delivery_tag=method.delivery_tag)

    channel.basic_qos(prefetch_count=1)
    channel.basic_consume(on_request, queue='rpc_queue')
    channel.start_consuming()
Exemplo n.º 17
0
# __BEGIN_LICENSE__
# Copyright (C) 2008-2010 United States Government as represented by
# the Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
# __END_LICENSE__

from Dispatcher import Dispatcher
from SharedScheduler import scheduler
import exampleConfig


def fooHandler(name, data):
    print 'got "%s" "%s"' % (name, data)

com = Dispatcher(moduleName='exampleSubscriber')
com.connectToNotificationService(exampleConfig.NOTIFY_ENDPOINT)
com.subscribe('%s:foo' % exampleConfig.PROTOCOL, fooHandler)
scheduler.runForever()