labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject svn commit: r568094 - in /labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet: ./ BacklogGraphReslet.java GraphRestletUtils.java PinpointGraphRestlet.java PinpointRestletApplication.java RootRestlet.java
Date Tue, 21 Aug 2007 12:21:13 GMT
Author: psmith
Date: Tue Aug 21 05:21:12 2007
New Revision: 568094

URL: http://svn.apache.org/viewvc?rev=568094&view=rev
Log:
And now for the all important Restlet's themselves... oops.


Added:
    labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/
    labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/BacklogGraphReslet.java
    labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/GraphRestletUtils.java
    labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/PinpointGraphRestlet.java
    labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/PinpointRestletApplication.java
    labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/RootRestlet.java

Added: labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/BacklogGraphReslet.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/BacklogGraphReslet.java?rev=568094&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/BacklogGraphReslet.java
(added)
+++ labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/BacklogGraphReslet.java
Tue Aug 21 05:21:12 2007
@@ -0,0 +1,27 @@
+package org.apache.logging.pinpoint.restlet;
+
+import org.apache.logging.pinpoint.metric.Counter;
+import org.apache.logging.pinpoint.metric.MetricChartUtils;
+import org.jfree.chart.JFreeChart;
+import org.restlet.Restlet;
+import org.restlet.data.Request;
+import org.restlet.data.Response;
+
+public class BacklogGraphReslet extends Restlet {
+
+    private final Counter receivedCounter;
+    private final Counter indexedCounter;
+
+    public BacklogGraphReslet(Counter receivedCounter, Counter indexedCounter) {
+        this.receivedCounter = receivedCounter;
+        this.indexedCounter = indexedCounter;
+    }
+
+    @Override
+    public void handle(Request request, Response response) {
+        JFreeChart backlogChart = MetricChartUtils.createBacklogChart(receivedCounter,
+                indexedCounter);
+        GraphRestletUtils.writeChart(backlogChart, response);
+    }
+
+}

Added: labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/GraphRestletUtils.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/GraphRestletUtils.java?rev=568094&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/GraphRestletUtils.java
(added)
+++ labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/GraphRestletUtils.java
Tue Aug 21 05:21:12 2007
@@ -0,0 +1,25 @@
+package org.apache.logging.pinpoint.restlet;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.jfree.chart.ChartUtilities;
+import org.jfree.chart.JFreeChart;
+import org.restlet.data.MediaType;
+import org.restlet.data.Response;
+import org.restlet.resource.InputRepresentation;
+
+public class GraphRestletUtils {
+
+    public static void writeChart(JFreeChart chart, Response response) {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try {
+            ChartUtilities.writeChartAsJPEG(baos, chart, 450, 300);
+            response.setEntity(new InputRepresentation(
+                    new ByteArrayInputStream(baos.toByteArray()), MediaType.IMAGE_JPEG));
+        } catch (IOException e) {
+            throw new RuntimeException("failed to write graph to Restlet response", e);
+        }
+    }
+}

Added: labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/PinpointGraphRestlet.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/PinpointGraphRestlet.java?rev=568094&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/PinpointGraphRestlet.java
(added)
+++ labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/PinpointGraphRestlet.java
Tue Aug 21 05:21:12 2007
@@ -0,0 +1,38 @@
+package org.apache.logging.pinpoint.restlet;
+
+import org.apache.log4j.Logger;
+import org.apache.logging.pinpoint.metric.Counter;
+import org.apache.logging.pinpoint.metric.MetricChartUtils;
+import org.apache.logging.pinpoint.utils.PinpointUtils;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.restlet.Restlet;
+import org.restlet.data.Request;
+import org.restlet.data.Response;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+
+public class PinpointGraphRestlet extends Restlet implements BeanFactoryAware {
+
+    private static final Logger LOG = PinpointUtils.getLogger(PinpointGraphRestlet.class);
+
+    private BeanFactory factory;
+
+    @Override
+    public void handle(Request request, Response response) {
+        String counterName = (String) request.getAttributes().get("counter");
+        Counter counter = (Counter) factory.getBean(counterName);
+
+        // TODO handle unknown
+        JFreeChart chart = ChartFactory.createTimeSeriesChart(counter.getMetricName(), "Time",
+                "Rate/second", MetricChartUtils.createRateTimeSeries(counter), false, false,
false);
+        GraphRestletUtils.writeChart(chart, response);
+
+    }
+
+    public void setBeanFactory(BeanFactory factory) throws BeansException {
+        this.factory = factory;
+    }
+
+}

Added: labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/PinpointRestletApplication.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/PinpointRestletApplication.java?rev=568094&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/PinpointRestletApplication.java
(added)
+++ labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/PinpointRestletApplication.java
Tue Aug 21 05:21:12 2007
@@ -0,0 +1,47 @@
+package org.apache.logging.pinpoint.restlet;
+
+import org.restlet.Application;
+import org.restlet.Component;
+import org.restlet.Restlet;
+import org.restlet.Router;
+import org.restlet.data.Protocol;
+
+public class PinpointRestletApplication extends Application {
+
+    private final Restlet pinpointGraphRestlet;
+    private final Component component;
+    private final Restlet backlogGraphRestlet;
+    private final Restlet rootRestlet;
+
+    public PinpointRestletApplication(Component component, Restlet rootRestlet,
+            PinpointGraphRestlet pinpointGraphRestlet, BacklogGraphReslet backlogGraphRestlet)
{
+        super(component.getContext());
+        this.pinpointGraphRestlet = pinpointGraphRestlet;
+        this.backlogGraphRestlet = backlogGraphRestlet;
+        this.rootRestlet = rootRestlet;
+        this.component = component;
+    }
+
+    @Override
+    public Restlet createRoot() {
+        Router router = new Router(getContext());
+
+        router.attach(rootRestlet);
+        router.attach("/counters/{counter}/", pinpointGraphRestlet);
+        router.attach("/backlog/", backlogGraphRestlet);
+        // Return the root router
+        return router;
+    }
+
+    public void go() {
+        component.getServers().add(Protocol.HTTP, 8182);
+        component.getDefaultHost().attach("", this);
+        component.getClients().add(Protocol.FILE);
+        try {
+            component.start();
+        } catch (Exception e) {
+            throw new RuntimeException("Failed to start Restlet Component", e);
+        }
+    }
+
+}

Added: labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/RootRestlet.java
URL: http://svn.apache.org/viewvc/labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/RootRestlet.java?rev=568094&view=auto
==============================================================================
--- labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/RootRestlet.java
(added)
+++ labs/pinpoint/trunk/pinpoint-service/src/main/java/org/apache/logging/pinpoint/restlet/RootRestlet.java
Tue Aug 21 05:21:12 2007
@@ -0,0 +1,47 @@
+package org.apache.logging.pinpoint.restlet;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.logging.pinpoint.metric.Counter;
+import org.restlet.Restlet;
+import org.restlet.data.MediaType;
+import org.restlet.data.Request;
+import org.restlet.data.Response;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.ListableBeanFactory;
+
+public class RootRestlet extends Restlet implements BeanFactoryAware {
+
+    private ListableBeanFactory ctx;
+
+    @Override
+    public void handle(Request request, Response response) {
+        StringBuilder sb = new StringBuilder(4096);
+
+        sb
+                .append("<html><head><title>Pinpoint-Service - Performance
Graphs</title><meta http-equiv=\"refresh\" content=\"5\"></head><body>");
+
+        sb.append("<h1>Pinpoint-Service - Performance Graphs</h1>");
+        sb.append("<img src=\"/backlog/\" <BR>");
+
+        Map counters = ctx.getBeansOfType(Counter.class);
+
+        for (Iterator iterator = counters.entrySet().iterator(); iterator.hasNext();) {
+            Map.Entry entry = (Entry) iterator.next();
+            sb.append("<img src=\"/counters/" + entry.getKey() + "/\"><BR>");
+
+        }
+        sb.append("</body></html>");
+        response.setEntity(sb.toString(), MediaType.TEXT_HTML);
+    }
+
+    public void setBeanFactory(BeanFactory factory) throws BeansException {
+        this.ctx = (ListableBeanFactory) factory;
+
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message