Search in sources :

Example 1 with ResourceListener

use of com.ning.metrics.meteo.publishers.ResourceListener in project meteo by pierre.

the class StreamResource method getSamplesByRoute.

/**
     * Get the data points associated with a field in an Esper query.
     * For this to work, you need to add ResourceListener as a publisher and configure it in a stream:
     * {
     * "name": "Jansky",
     * "type": "com.ning.metrics.meteo.publishers.ResourceListener",
     * "@class": "com.ning.metrics.meteo.publishers.ResourcePublisherConfig"
     * }
     *
     * @param callback  Javascript callback
     * @param stream Stream name
     * @param attribute the SQL alias of an Esper query
     * @return jsonp representation of the data points in memory
     */
@GET
@Path("/{stream}/{attribute}")
@Produces(MediaType.APPLICATION_JSON)
public Response getSamplesByRoute(@QueryParam("callback") @DefaultValue("callback") final String callback, @PathParam("stream") final String stream, @PathParam("attribute") final String attribute) {
    Cache<Object, Object> samplesCache = null;
    final ResourceListener resourceListener = (ResourceListener) compiler.getPublisherInstances().get(stream);
    if (resourceListener != null) {
        final Map<String, Cache<Object, Object>> samples = resourceListener.getSamplesCache();
        samplesCache = samples.get(attribute);
    }
    return buildJsonpResponse(attribute, samplesCache, callback);
}
Also used : ResourceListener(com.ning.metrics.meteo.publishers.ResourceListener) JSONPObject(org.codehaus.jackson.map.util.JSONPObject) Cache(com.google.common.cache.Cache) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Cache (com.google.common.cache.Cache)1 ResourceListener (com.ning.metrics.meteo.publishers.ResourceListener)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 JSONPObject (org.codehaus.jackson.map.util.JSONPObject)1