Esempio n. 1
0
def handler(msg):
    print "Received message"
    flights = JsonArray()
    for flight in msg.body:
        the_flight = JsonObject()
        #print str(flight)
        #the_flight.putString("name", flight.getString("callsign"))
        #the_flight.putString("planeType", flight.getString("equipment") )
        the_flight.putString("speed", flight.get("properties").get("direction"))
        the_flight.putString("alt",  flight.get("properties").get("route"))
        position_array =  flight.get("geometry").get("coordinates")
        #print position_array

        #There can sometimes be two positions readings but I am not sure what they do so I am just going to take the first
        #position =  position_array[0]

        the_flight.putNumber("lat", position_array[1])
        the_flight.putNumber("lon", position_array[0])
        
        #build the object to persist to mongo
        forMongo = JsonObject()
        forMongo.putString("action", "save")
        forMongo.putString("collection", "buses")
        forMongo.putObject("document", the_flight)
        #persist it
        EventBus.publish('vertx.mongopersistor', forMongo)

        #add now to the array
        flights.addObject(the_flight)

    #Sent the array on the EventBus - this is the one the page should subscribe to
    EventBus.publish('flights.updated', flights)
    print("published the flights")
Esempio n. 2
0
def handler(msg):
    print "Received message"
    flights = JsonArray()
    for flight in msg.body:
        the_flight = JsonObject()
        #print str(flight)
        #the_flight.putString("name", flight.getString("callsign"))
        #the_flight.putString("planeType", flight.getString("equipment") )
        the_flight.putString("speed",
                             flight.get("properties").get("direction"))
        the_flight.putString("alt", flight.get("properties").get("route"))
        position_array = flight.get("geometry").get("coordinates")
        #print position_array

        #There can sometimes be two positions readings but I am not sure what they do so I am just going to take the first
        #position =  position_array[0]

        the_flight.putNumber("lat", position_array[1])
        the_flight.putNumber("lon", position_array[0])

        #build the object to persist to mongo
        forMongo = JsonObject()
        forMongo.putString("action", "save")
        forMongo.putString("collection", "buses")
        forMongo.putObject("document", the_flight)
        #persist it
        EventBus.publish('vertx.mongopersistor', forMongo)

        #add now to the array
        flights.addObject(the_flight)

    #Sent the array on the EventBus - this is the one the page should subscribe to
    EventBus.publish('flights.updated', flights)
    print("published the flights")
Esempio n. 3
0
def login_handler(msg):
    user = msg.body
    id = vertx.config()['user-prefix'] + str(uuid.uuid4())
    users.add(user)
    EventBus.register_handler(id, 
                              handler=lambda msg: command_handler(user, msg))
    EventBus.publish(vertx.config()['users-address'], user)
    msg.reply({'id': id, 'users': list(users)})
Esempio n. 4
0
def command_handler(user, msg):
    body = msg.body
    status = 'unknown-command'
    if (body['command'] == 'say'):
        EventBus.publish(vertx.config()['messages-address'], 
                         {'user': user, 
                          'message': body['payload']})
        status = 'ok'
    msg.reply({'status': status})
Esempio n. 5
0
def init_test_setup(config):
    if not config.get('testmode', False):
        return 

    def register(addr):
        def _wrapper(func):
            EventBus.register_handler(addr, handler=func)
            return func
        return _wrapper

    @register('test.tweets')
    def tweet_handler(msg):
        print msg.body

    @functools.partial(vertx.set_periodic, 1000)
    def status(tid):
        EventBus.publish(HBCAgent.STATUS_ADDRESS, dict(replyTo="test.status"))

    @register('test.status')
    def print_status(msg):
        print "Status >>>", msg.body

    @register('test.shutdown')
    def on_shutdown(msg):
        print "Shutdown >>>", msg.body
        vertx.exit()
        
    # simple shutdown hook
    exit_after = config.get('testmode').get('exitAfter', 10)
    if exit_after:
        vertx.set_timer(exit_after * 1000, 
                        lambda x: EventBus.publish(HBCAgent.SHUTDOWN_ADDRESS, 
                                                   dict(replyTo="test.shutdown")))
    def test_send_multiple_matching_handlers(self):
        json = {'message' : 'hello world!'}
        address = "some-address"
        num_handlers = 10
        count = [0] # use an array to ensure pass by ref

        for i in range(0,num_handlers):
            class Handler(object):
                def __init__(self, count):
                    self.count = count
                def handler_func(self, msg):
                    tu.azzert(msg.body['message'] == json['message'])
                    EventBus.unregister_handler(self.id)
                    self.count[0] += 1
                    if self.count[0] == num_handlers:
                        tu.test_complete()
            handler = Handler(count)
            handler.id = EventBus.register_handler(address, handler=handler.handler_func)
        EventBus.publish(address, json)
def handler(msg):
    print 'Received message'
    flights = JsonArray()
    for flight in msg.body:
        the_flight = JsonObject()
        the_flight.putString("name", flight.getString("callsign"))
        the_flight.putString("planeType", flight.getString("equipment") )
        position_array =  flight.getArray("positions").toArray()

        #There can sometimes be two positions readings but I am not sure what they do so I am just going to take the first
        position =  position_array[0]

        the_flight.putNumber("lat", position.get("lat"))
        the_flight.putNumber("lon", position.get("lon"))
        the_flight.putNumber("speed", position.get("speedMph"))
        the_flight.putNumber("alt",  position.get("altitudeFt"))


        flights.addObject(the_flight)

    #Sent the array on the EventBus - this is the one the page should subscribe to
    EventBus.publish('flights.updated', flights)
    print("published the flights")
Esempio n. 8
0
    def test_send_multiple_matching_handlers(self):
        json = {'message': 'hello world!'}
        address = "some-address"
        num_handlers = 10
        count = [0]  # use an array to ensure pass by ref

        for i in range(0, num_handlers):

            class Handler(object):
                def __init__(self, count):
                    self.count = count

                def handler_func(self, msg):
                    tu.azzert(msg.body['message'] == json['message'])
                    EventBus.unregister_handler(self.id)
                    self.count[0] += 1
                    if self.count[0] == num_handlers:
                        tu.test_complete()

            handler = Handler(count)
            handler.id = EventBus.register_handler(
                address, handler=handler.handler_func)
        EventBus.publish(address, json)
Esempio n. 9
0
 def offer(self, item, *args):
     EventBus.publish(self.channel, JsonObject(item))
Esempio n. 10
0
 def shutdown_handler(self, msg):
     EventBus.publish(msg.body['replyTo'], self._shutdown())
Esempio n. 11
0
def timer_handler(timer_id):
    print "Python sending..."
    EventBus.publish('news-feed', 'Power Python')
Esempio n. 12
0
def timer_handler(timer_id):
    EventBus.publish('news-feed', 'Python!')
Esempio n. 13
0
def timer_handler(timer_id):
	print "Python sending..."
	EventBus.publish('news-feed', 'Power Python')
Esempio n. 14
0
def handler(tid):
    EventBus.publish("data.source.raw", create_package())

    print 'And every second this is printed'
Esempio n. 15
0
def timer_handler(timer_id):
    EventBus.publish('news-feed', 'Some News!')
Esempio n. 16
0
 def status_handler(self, msg):
     EventBus.publish(msg.body['replyTo'], self._status())
Esempio n. 17
0
 def status(tid):
     EventBus.publish(HBCAgent.STATUS_ADDRESS, dict(replyTo="test.status"))
Esempio n. 18
0
def handler(msg):
	my_ip = urllib2.urlopen('http://ip.42.pl/raw').read()
	print ("myIp:" + my_ip)
	EventBus.publish('send-chat', my_ip);
Esempio n. 19
0
def handler(tid):
    EventBus.publish("data.source.raw", create_package())
Esempio n. 20
0
def timer_handler(timer_id):
    EventBus.publish('examples.message', 'Message from Jython')