def publisher_subscribe(listener_id):
    """Subscribe a new listener.

    Args:
        listener_id: string that identifies the new listeners.

    Returns:
        new queue.Queue instance from which the listener can get messages.
    """

    global STOPPING
    if STOPPING:
        return None
    
    _new_queue = queue.Queue()

    # At least, we want new listeners to know who we are, so the first message
    # we put in the queue is our own identification:
    _new_queue.put(actions.decode(actions.send_buildinfo(BUILDINFO)))

    # We now register the new queue in our LISTENERS dict. Remember that this
    # function is intended to be used as a callback and will be called from a
    # thread. Thanks to Python's Global Interpreter Lock, the following is
    # atomic and will not corrupt the queue, even if multiple threads subscribe
    # at the "same" time
    LISTENERS[listener_id] = _new_queue

    # Threads that fill the queue are assumed to wait until EVENT is set.
    # Currently, the rule engine is honoring that assumption.
    print("SET EVENT!!!!")
    if not EVENT.is_set():
        EVENT.set()

    return _new_queue
Example #2
0
def put_initial_messages(_new_queue):
    memusage_chart_options = {"chart": {"type": "spline",
                                     "animation": "Highcharts.svg"
                                   },
                           "title": {"text": "Max RSS of server"},
                           "xAxis": {"type": "datetime",
                                     "tickPixelInterval": 150
                                    },
                           "yAxis": {"title": {"text": "Max RSS in kB"},
                                     "plotLines": [{
                                                    "value": 0,
                                                    "width": 1,
                                                    "color": "#808080"
                                                    }]
                                     },
                           "series": [{"name": "maxrss",
                                       "data": []}]
                           }

    listeners_chart_options = {"chart": {"type": "spline",
                                         "animation": "Highcharts.svg"
                                         },
                               "title": {"text": "Number of listeners"},
                               "xAxis": {"type": "datetime",
                                         "tickPixelInterval": 150
                                         },
                               "yAxis": {"title": {"text": "Listeners"},
                                         "plotLines": [{
                                                        "value": 0,
                                                        "width": 1,
                                                        "color": "#808080"
                                                        }]
                                         },
                               "series": [{"name": "Listeners",
                                           "data": [{"x": (int(time.time()) - 1)
                                                     * 1000, "y":
                                                     random.random()},
                                                    {"x": int(time.time()) *
                                                     1000, "y":
                                                     random.random()}]}]
                               }

    map_options = {"map": {"options": {"zoom": 4,
                                       "center": [78.840319, 16.585922]
                                       }
                           }
                   }

    example_wordcloud = [{"text": "Amsterdam", "weight": 15},
                         {"text": "Rotterdam", "weight": 15},
                         {"text": "Den Haag", "weight": 8},
                         {"text": "Enschede", "weight": 3},
                         {"text": "Hengelo", "weight": 1.5}]

    for index in range(-19, 0):
        new_point = {"x": (int(time.time()) + index) * 1000,
                     "y": random.random()}
        memusage_chart_options["series"][0]["data"].append(new_point)

#     for index in range(-19, 0):
#         new_point = {"x": (int(time.time()) + index) * 1000,
#                      "y": random.random()}
#         listeners_chart_options["series"][0]["data"].append(new_point)

    _new_queue.put(actions.decode(actions.create_alert_gadget("cell0",
                                      "myAlerter", "Alert!")))
    _new_queue.put(actions.decode(actions.create_alert_gadget("cell9",
                                      "serverinfo", "Server information")))
    _new_queue.put(actions.decode(actions.alert("Server started!",
                                                "serverinfo")))
    _new_queue.put(actions.decode(actions.create_maps_gadget("cell3", "myMap1",
                                                             "Tweet geos",
                                                             map_options)))
    _new_queue.put(actions.decode(actions.add_maps_marker("myMap1", 78.840319,
                                        16.585922, "Jan was here!")))
    _new_queue.put(actions.decode(actions.create_tweetlist_gadget("cell4",
                                        "allTweets", "Random tweets")))
    # _new_queue.put(actions.decode(actions.create_wordcloud_gadget("cell5",
                                        # "myWordCloud", "Dutch cities",
                                        # example_wordcloud)))
    _new_queue.put(actions.decode(actions.create_general_chart("cell1",
                                        "memusage", "Server max RSS",
                                        memusage_chart_options)))
    _new_queue.put(actions.decode(actions.create_general_chart("cell2",
                                        "listeners", "Number of listeners",
                                        listeners_chart_options)))
def produce_function(message):
	decoded = actions.decode(message)
	# logger.info('PUBLISH: '+str(decoded))
	if debug_publish:
		print('PUBLISH: '+str(decoded))
	_send_to_all_listeners(decoded)
def put_initial_messages(_new_queue):
    memusage_chart_options = {
        "chart": {
            "type": "spline",
            "animation": "Highcharts.svg"
        },
        "title": {
            "text": "Max RSS of server"
        },
        "xAxis": {
            "type": "datetime",
            "tickPixelInterval": 150
        },
        "yAxis": {
            "title": {
                "text": "Max RSS in kB"
            },
            "plotLines": [{
                "value": 0,
                "width": 1,
                "color": "#808080"
            }]
        },
        "series": [{
            "name": "maxrss",
            "data": []
        }]
    }

    listeners_chart_options = {
        "chart": {
            "type": "spline",
            "animation": "Highcharts.svg"
        },
        "title": {
            "text": "Number of listeners"
        },
        "xAxis": {
            "type": "datetime",
            "tickPixelInterval": 150
        },
        "yAxis": {
            "title": {
                "text": "Listeners"
            },
            "plotLines": [{
                "value": 0,
                "width": 1,
                "color": "#808080"
            }]
        },
        "series": [{
            "name":
            "Listeners",
            "data": [{
                "x": (int(time.time()) - 1) * 1000,
                "y": random.random()
            }, {
                "x": int(time.time()) * 1000,
                "y": random.random()
            }]
        }]
    }

    map_options = {
        "map": {
            "options": {
                "zoom": 4,
                "center": [78.840319, 16.585922]
            }
        }
    }

    example_wordcloud = [{
        "text": "Amsterdam",
        "weight": 15
    }, {
        "text": "Rotterdam",
        "weight": 15
    }, {
        "text": "Den Haag",
        "weight": 8
    }, {
        "text": "Enschede",
        "weight": 3
    }, {
        "text": "Hengelo",
        "weight": 1.5
    }]

    for index in range(-19, 0):
        new_point = {
            "x": (int(time.time()) + index) * 1000,
            "y": random.random()
        }
        memusage_chart_options["series"][0]["data"].append(new_point)

#     for index in range(-19, 0):
#         new_point = {"x": (int(time.time()) + index) * 1000,
#                      "y": random.random()}
#         listeners_chart_options["series"][0]["data"].append(new_point)

    _new_queue.put(
        actions.decode(
            actions.create_alert_gadget("cell0", "myAlerter", "Alert!")))
    _new_queue.put(
        actions.decode(
            actions.create_alert_gadget("cell9", "serverinfo",
                                        "Server information")))
    _new_queue.put(
        actions.decode(actions.alert("Server started!", "serverinfo")))
    _new_queue.put(
        actions.decode(
            actions.create_maps_gadget("cell3", "myMap1", "Tweet geos",
                                       map_options)))
    _new_queue.put(
        actions.decode(
            actions.add_maps_marker("myMap1", 78.840319, 16.585922,
                                    "Jan was here!")))
    _new_queue.put(
        actions.decode(
            actions.create_tweetlist_gadget("cell4", "allTweets",
                                            "Random tweets")))
    # _new_queue.put(actions.decode(actions.create_wordcloud_gadget("cell5",
    # "myWordCloud", "Dutch cities",
    # example_wordcloud)))
    _new_queue.put(
        actions.decode(
            actions.create_general_chart("cell1", "memusage", "Server max RSS",
                                         memusage_chart_options)))
    _new_queue.put(
        actions.decode(
            actions.create_general_chart("cell2", "listeners",
                                         "Number of listeners",
                                         listeners_chart_options)))
Example #5
0
def debug_produce_function(message):
	decoded = actions.decode(message)
	print('TO-BROWSER: '+str(decoded))
Example #6
0
def debug_produce_function(message):
    decoded = actions.decode(message)
    print('TO-BROWSER: ' + str(decoded))