You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/18 23:24:53 UTC
[sling-org-apache-sling-reqanalyzer] branch master created (now
0df2ad9)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git.
at 0df2ad9 SLING-7167 Adjust READMEs
This branch includes the following new commits:
new 51b2b9b SLING-2516 Request Performance Analysis helper along with Java application to display the collected data
new 28ab4af Use latest parent pom everywhere
new 9d4cf19 Use latest releases and update to new parent pom
new 04ab306 Update to latest parent pom and use latest releases in launchpad
new 94bb949 Correct reactor pom and update to parent pom 16
new 6a50f0c Update to latest parent pom
new d780cb3 Update to parent pom 18
new a851074 SLING-3099 Expose the request analyzer log file through the Web Console
new a1e4342 SLING-3099 Expose the request analyzer log file through the Web Console
new ee56fbc Update to parent pom v19
new 5ba7908 Update to latest parent pom 20
new 42c5a27 Update to Sling Parent POM 22 with baselining enabled
new 8b3d469 Update contrib modules to Parent 23
new 2cbdc5c set parent version to 24 and add empty relativePath where missing
new b7e489a Update the contrib reactor to parent 25
new 1ff3bd5 Switch to parent pom 26
new 0aec958 SLING-6433 Request Processing Analyzer throws IOOB due to old format assumptions of RequestProgressTracker output
new 0df2ad9 SLING-7167 Adjust READMEs
The 18 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
--
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].
[sling-org-apache-sling-reqanalyzer] 06/18: Update to latest parent
pom
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 6a50f0c819613f5d2490004313e673083464be83
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Jul 19 07:04:15 2013 +0000
Update to latest parent pom
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1504788 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 1e7ccc6..9a34750 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>16</version>
+ <version>17</version>
</parent>
<artifactId>org.apache.sling.reqanalyzer</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 07/18: Update to parent pom 18
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit d780cb3fb066445331eccf478f66c2914f5174d5
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Sep 6 12:15:57 2013 +0000
Update to parent pom 18
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1520554 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 9a34750..55be5ec 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>17</version>
+ <version>18</version>
</parent>
<artifactId>org.apache.sling.reqanalyzer</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 08/18: SLING-3099 Expose the
request analyzer log file through the Web Console
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit a8510744e9025405e01c19b5c80ba707e99fdbb6
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Tue Sep 24 07:58:42 2013 +0000
SLING-3099 Expose the request analyzer log file through the Web Console
- Allow for plain text download
- Allow for zipped download
- Support launching the Swing GUI
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1525810 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 6 +
.../reqanalyzer/impl/RequestAnalysisLogger.java | 31 ++-
.../impl/RequestAnalyzerWebConsole.java | 250 +++++++++++++++++++++
.../apache/sling/reqanalyzer/impl/gui/Main.java | 10 +
.../sling/reqanalyzer/impl/gui/MainFrame.java | 12 +-
5 files changed, 295 insertions(+), 14 deletions(-)
diff --git a/pom.xml b/pom.xml
index 55be5ec..265702f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -132,6 +132,12 @@
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.2</version>
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalysisLogger.java b/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalysisLogger.java
index bcf98c4..db1efa6 100644
--- a/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalysisLogger.java
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalysisLogger.java
@@ -23,6 +23,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
+import java.util.Hashtable;
import java.util.Iterator;
import javax.servlet.Filter;
@@ -45,7 +46,9 @@ import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
import org.apache.sling.engine.EngineConstants;
import org.apache.sling.settings.SlingSettingsService;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
@Component(metatype = false)
@Service
@@ -59,18 +62,40 @@ public class RequestAnalysisLogger implements Filter {
private BufferedWriter logFile;
- @SuppressWarnings("unused")
+ private RequestAnalyzerWebConsole requestAnalyzerWebConsole;
+ private ServiceRegistration webConsolePlugin;
+
+ @SuppressWarnings({ "serial" })
@Activate
- private void activate() throws IOException {
+ private void activate(final BundleContext ctx) throws IOException {
final File logFile = new File(settings.getSlingHomePath(), "logs/requesttracker.txt");
logFile.getParentFile().mkdirs();
final FileOutputStream out = new FileOutputStream(logFile, true);
this.logFile = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
+
+ this.requestAnalyzerWebConsole = new RequestAnalyzerWebConsole(logFile);
+ this.webConsolePlugin = ctx.registerService("javax.servlet.Servlet", this.requestAnalyzerWebConsole,
+ new Hashtable<String, Object>() {
+ {
+ put("felix.webconsole.label", "requestanalyzer");
+ put("felix.webconsole.title", "Request Analyzer");
+ put("felix.webconsole.category", "Sling");
+ }
+ });
}
- @SuppressWarnings("unused")
@Deactivate
private void deactivate() throws IOException {
+ if (this.webConsolePlugin != null) {
+ this.webConsolePlugin.unregister();
+ this.webConsolePlugin = null;
+ }
+
+ if (this.requestAnalyzerWebConsole != null) {
+ this.requestAnalyzerWebConsole.dispose();
+ this.requestAnalyzerWebConsole = null;
+ }
+
if (this.logFile != null) {
this.logFile.close();
this.logFile = null;
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalyzerWebConsole.java b/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalyzerWebConsole.java
new file mode 100644
index 0000000..4c473e1
--- /dev/null
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalyzerWebConsole.java
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.reqanalyzer.impl;
+
+import java.awt.AWTEvent;
+import java.awt.Dimension;
+import java.awt.GraphicsEnvironment;
+import java.awt.Toolkit;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.zip.Deflater;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.sling.reqanalyzer.impl.gui.MainFrame;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@SuppressWarnings("serial")
+public class RequestAnalyzerWebConsole extends HttpServlet {
+
+ private static final String WINDOW_MARKER = ".showWindow";
+
+ private static final String RAW_FILE_MARKER = ".txt";
+
+ private static final String ZIP_FILE_MARKER = ".txt.zip";
+
+ /** default log */
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private final File logFile;
+
+ private final Set<MainFrame> frames;
+
+ RequestAnalyzerWebConsole(final File logFile) {
+ this.logFile = logFile;
+ this.frames = new HashSet<MainFrame>();
+ }
+
+ void dispose() {
+ final Set<MainFrame> frames = new HashSet<MainFrame>(this.frames);
+ this.frames.clear();
+ for (MainFrame mainFrame : frames) {
+ AWTEvent e = new WindowEvent(mainFrame, WindowEvent.WINDOW_CLOSING);
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
+ }
+ }
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ if (req.getRequestURI().endsWith(RAW_FILE_MARKER) || req.getRequestURI().endsWith(ZIP_FILE_MARKER)) {
+
+ InputStream input = null;
+ OutputStream output = null;
+ try {
+ input = new FileInputStream(this.logFile);
+ output = resp.getOutputStream();
+
+ if (req.getRequestURI().endsWith(ZIP_FILE_MARKER)) {
+ ZipOutputStream zip = new ZipOutputStream(output);
+ zip.setLevel(Deflater.BEST_SPEED);
+
+ ZipEntry entry = new ZipEntry(this.logFile.getName());
+ entry.setTime(this.logFile.lastModified());
+ entry.setMethod(ZipEntry.DEFLATED);
+
+ zip.putNextEntry(entry);
+
+ output = zip;
+ resp.setContentType("application/zip");
+ } else {
+ resp.setContentType("text/plain");
+ resp.setCharacterEncoding("UTF-8");
+ resp.setHeader("Content-Length", String.valueOf(this.logFile.length())); // might be bigger than
+ }
+ resp.setDateHeader("Last-Modified", this.logFile.lastModified());
+
+ IOUtils.copy(input, output);
+ } catch (IOException ioe) {
+ throw new ServletException("Cannot create copy of log file", ioe);
+ } finally {
+ IOUtils.closeQuietly(input);
+
+ if (output instanceof ZipOutputStream) {
+ ((ZipOutputStream) output).closeEntry();
+ ((ZipOutputStream) output).finish();
+ }
+ }
+
+ resp.flushBuffer();
+
+ } else if (req.getRequestURI().endsWith(WINDOW_MARKER) && !GraphicsEnvironment.isHeadless()) {
+
+ String target = req.getRequestURI();
+ target = target.substring(0, target.length() - WINDOW_MARKER.length());
+
+ showWindow();
+ resp.sendRedirect(target);
+ resp.flushBuffer();
+
+ } else {
+
+ super.service(req, resp);
+
+ }
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ PrintWriter pw = resp.getWriter();
+
+ final String fileSize = this.formatByteSize(this.logFile.length());
+ pw.printf("<p class='statline ui-state-highlight'>Request Log Size %s</p>%n", fileSize);
+
+ pw.println("<table class='nicetable ui-widget'>");
+ pw.println(" <thead>");
+ pw.println(" <tr>");
+ pw.println(" <th class='ui-widget-header'>Name</th>");
+ pw.println(" <th class='ui-widget-header'>Last Update</th>");
+ pw.println(" <th class='ui-widget-header'>Size</th>");
+ pw.println(" <th class='ui-widget-header'>Action</th>");
+ pw.println(" </tr>");
+ pw.println("</thead>");
+ pw.println("<tbody>");
+
+ pw.println("<tr>");
+
+ pw.printf("<td><a href='${pluginRoot}%s'>%s</a> (<a href='${pluginRoot}%s'>zipped</a>)</td>%n", RAW_FILE_MARKER, this.logFile.getName(), ZIP_FILE_MARKER);
+ pw.printf("<td>%s</td><td>%s</td>", new Date(this.logFile.lastModified()), fileSize);
+
+ pw.println("<td><ul class='icons ui-widget'>");
+ if (!GraphicsEnvironment.isHeadless()) {
+ pw.printf(
+ "<li title='Analyze Now' class='dynhover ui-state-default ui-corner-all'><a href='${pluginRoot}%s'><span class='ui-icon ui-icon-wrench'></span></a></li>%n",
+ WINDOW_MARKER);
+ // pw.printf(" (<a href='${pluginRoot}%s'>Analyze Now</a>)", WINDOW_MARKER);
+ }
+ // pw.println("<li title='Remove File' class='dynhover ui-state-default ui-corner-all'><span class='ui-icon ui-icon-trash'></span></li>");
+ pw.println("</ul></td>");
+
+ pw.println("</tr></tbody>");
+ pw.println("</table>");
+
+ }
+
+ private void showWindow() throws ServletException, IOException {
+ final File toAnalyze = this.getLogFileCopy();
+
+ final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ MainFrame frame = new MainFrame(toAnalyze, Integer.MAX_VALUE, screenSize);
+ frame.setVisible(true);
+ frame.toFront();
+
+ // exit the application if the main frame is closed
+ frame.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ if (toAnalyze.exists()) {
+ toAnalyze.delete();
+ }
+ }
+ });
+
+ this.frames.add(frame);
+ }
+
+ private final File getLogFileCopy() throws ServletException {
+ File result = null;
+ InputStream input = null;
+ OutputStream output = null;
+ try {
+ result = File.createTempFile(getServletName(), ".tmp");
+ input = new FileInputStream(this.logFile);
+ output = new FileOutputStream(result);
+ IOUtils.copy(input, output);
+ return result;
+ } catch (IOException ioe) {
+ throw new ServletException("Cannot create copy of log file", ioe);
+ } finally {
+ IOUtils.closeQuietly(input);
+ IOUtils.closeQuietly(output);
+ }
+ }
+
+ private String formatByteSize(final long value) {
+ final String suffix;
+ final String suffixedValue;
+
+ if (value >= 0) {
+ final BigDecimal KB = new BigDecimal(1000L);
+ final BigDecimal MB = new BigDecimal(1000L * 1000);
+ final BigDecimal GB = new BigDecimal(1000L * 1000 * 1000);
+
+ BigDecimal bd = new BigDecimal(value);
+ if (bd.compareTo(GB) > 0) {
+ bd = bd.divide(GB);
+ suffix = "GB";
+ } else if (bd.compareTo(MB) > 0) {
+ bd = bd.divide(MB);
+ suffix = "MB";
+ } else if (bd.compareTo(KB) > 0) {
+ bd = bd.divide(KB);
+ suffix = "kB";
+ } else {
+ suffix = "B";
+ }
+ suffixedValue = bd.setScale(2, RoundingMode.UP).toString();
+ } else {
+ suffixedValue = "n/a";
+ suffix = "";
+ }
+
+ return suffixedValue + suffix;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/Main.java b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/Main.java
index c0efcca..0459b04 100644
--- a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/Main.java
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/Main.java
@@ -21,6 +21,8 @@ package org.apache.sling.reqanalyzer.impl.gui;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
@@ -54,6 +56,14 @@ public class Main {
MainFrame frame = new MainFrame(file, limit, screenSize);
frame.setVisible(true);
+
+ // exit the application if the main frame is closed
+ frame.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
}
}
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/MainFrame.java b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/MainFrame.java
index 7feb4f1..eccf98c 100644
--- a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/MainFrame.java
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/MainFrame.java
@@ -20,8 +20,6 @@ package org.apache.sling.reqanalyzer.impl.gui;
import java.awt.Color;
import java.awt.Dimension;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -49,7 +47,7 @@ public class MainFrame extends JFrame {
JTextPane text = Util.showStartupDialog("Reading from " + file, screenSize);
final RequestTrackerFile dm = new RequestTrackerFile(file, limit, text);
-
+
final JTable table = new JTable(dm);
table.setAutoCreateRowSorter(true);
table.setGridColor(Color.GRAY);
@@ -65,14 +63,6 @@ public class MainFrame extends JFrame {
setTitle(file.getPath());
- // exit the application if the main frame is closed
- addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
-
// setup location and size and ensure updating preferences
Util.setupComponentLocationSize(this, MAIN_X, MAIN_Y, MAIN_WIDTH, MAIN_HEIGHT, (int) screenSize.getWidth() / 4,
0, (int) screenSize.getWidth() / 2, (int) screenSize.getHeight() / 4);
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 09/18: SLING-3099 Expose the
request analyzer log file through the Web Console
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit a1e4342ce759d1e5175fe23ac7944c37181a7697
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Tue Sep 24 15:07:23 2013 +0000
SLING-3099 Expose the request analyzer log file through the Web Console
- Only support GUI when requested via localhost adapter
- Only open a single window (show again if already open)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1525918 13f79535-47bb-0310-9956-ffa450edef68
---
.../impl/RequestAnalyzerWebConsole.java | 75 ++++++++++++++--------
1 file changed, 47 insertions(+), 28 deletions(-)
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalyzerWebConsole.java b/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalyzerWebConsole.java
index 4c473e1..15da4e4 100644
--- a/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalyzerWebConsole.java
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalyzerWebConsole.java
@@ -33,14 +33,15 @@ import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -64,18 +65,17 @@ public class RequestAnalyzerWebConsole extends HttpServlet {
private final File logFile;
- private final Set<MainFrame> frames;
+ private MainFrame frame;
RequestAnalyzerWebConsole(final File logFile) {
this.logFile = logFile;
- this.frames = new HashSet<MainFrame>();
}
void dispose() {
- final Set<MainFrame> frames = new HashSet<MainFrame>(this.frames);
- this.frames.clear();
- for (MainFrame mainFrame : frames) {
- AWTEvent e = new WindowEvent(mainFrame, WindowEvent.WINDOW_CLOSING);
+ if (this.frame != null) {
+ MainFrame frame = this.frame;
+ this.frame = null;
+ AWTEvent e = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
}
}
@@ -123,12 +123,14 @@ public class RequestAnalyzerWebConsole extends HttpServlet {
resp.flushBuffer();
- } else if (req.getRequestURI().endsWith(WINDOW_MARKER) && !GraphicsEnvironment.isHeadless()) {
+ } else if (req.getRequestURI().endsWith(WINDOW_MARKER)) {
+
+ if (canOpenSwingGui(req)) {
+ showWindow();
+ }
String target = req.getRequestURI();
target = target.substring(0, target.length() - WINDOW_MARKER.length());
-
- showWindow();
resp.sendRedirect(target);
resp.flushBuffer();
@@ -163,7 +165,7 @@ public class RequestAnalyzerWebConsole extends HttpServlet {
pw.printf("<td>%s</td><td>%s</td>", new Date(this.logFile.lastModified()), fileSize);
pw.println("<td><ul class='icons ui-widget'>");
- if (!GraphicsEnvironment.isHeadless()) {
+ if (canOpenSwingGui(req)) {
pw.printf(
"<li title='Analyze Now' class='dynhover ui-state-default ui-corner-all'><a href='${pluginRoot}%s'><span class='ui-icon ui-icon-wrench'></span></a></li>%n",
WINDOW_MARKER);
@@ -177,25 +179,42 @@ public class RequestAnalyzerWebConsole extends HttpServlet {
}
- private void showWindow() throws ServletException, IOException {
- final File toAnalyze = this.getLogFileCopy();
+ private synchronized void showWindow() throws ServletException, IOException {
+ if (this.frame == null) {
+ final File toAnalyze = this.getLogFileCopy();
+
+ final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ MainFrame frame = new MainFrame(toAnalyze, Integer.MAX_VALUE, screenSize);
+
+ // exit the application if the main frame is closed
+ frame.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ // remove the tmp file we showed
+ if (toAnalyze.exists()) {
+ toAnalyze.delete();
+ }
+ // clear the window reference
+ RequestAnalyzerWebConsole.this.frame = null;
+ }
+ });
- final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- MainFrame frame = new MainFrame(toAnalyze, Integer.MAX_VALUE, screenSize);
- frame.setVisible(true);
- frame.toFront();
+ this.frame = frame;
+ }
- // exit the application if the main frame is closed
- frame.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- if (toAnalyze.exists()) {
- toAnalyze.delete();
- }
- }
- });
+ // make sure the window is visible, try to bring to the front
+ this.frame.setVisible(true);
+ this.frame.toFront();
+ }
- this.frames.add(frame);
+ private boolean canOpenSwingGui(final ServletRequest request) {
+ try {
+ return !GraphicsEnvironment.isHeadless()
+ && InetAddress.getByName(request.getLocalAddr()).isLoopbackAddress();
+ } catch (UnknownHostException e) {
+ // unexpected, but still fall back to fail-safe false
+ return false;
+ }
}
private final File getLogFileCopy() throws ServletException {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 15/18: Update the contrib
reactor to parent 25
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit b7e489a744b1c1ea038c49512238127d155714ef
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Mon Oct 5 10:04:15 2015 +0000
Update the contrib reactor to parent 25
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1706781 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 30cbe6a..e4b5bcc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>24</version>
+ <version>25</version>
<relativePath/>
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 10/18: Update to parent pom v19
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit ee56fbc9a4dd6d3ce661eb880e2bc3d914db54fd
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Mar 31 14:39:20 2014 +0000
Update to parent pom v19
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1583337 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 265702f..ba36ca9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>18</version>
+ <version>19</version>
</parent>
<artifactId>org.apache.sling.reqanalyzer</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 14/18: set parent version to
24 and add empty relativePath where missing
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 2cbdc5ca7bd7d8f2b390233e6361dc67d8f69a31
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Tue Jul 7 07:36:29 2015 +0000
set parent version to 24 and add empty relativePath where missing
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1689588 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 84bb04f..30cbe6a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,8 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>23</version>
+ <version>24</version>
+ <relativePath/>
</parent>
<artifactId>org.apache.sling.reqanalyzer</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 12/18: Update to Sling Parent
POM 22 with baselining enabled
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 42c5a27a9aa95a50399538d2684a2c74e7b7852e
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Oct 1 06:52:29 2014 +0000
Update to Sling Parent POM 22 with baselining enabled
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1628620 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 83a457b..e5c37ad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>20</version>
+ <version>22</version>
</parent>
<artifactId>org.apache.sling.reqanalyzer</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 03/18: Use latest releases and
update to new parent pom
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 9d4cf19e52d372abfb940d56e42f66a372c80bce
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Dec 23 06:53:35 2012 +0000
Use latest releases and update to new parent pom
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1425425 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 37822b0..7b43395 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>13</version>
+ <version>14</version>
</parent>
<artifactId>org.apache.sling.reqanalyzer</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 16/18: Switch to parent pom 26
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 1ff3bd5432415f67c058a2ba454774412b67212d
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Jan 3 14:07:46 2016 +0000
Switch to parent pom 26
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1722720 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index e4b5bcc..52e307a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>25</version>
+ <version>26</version>
<relativePath/>
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 11/18: Update to latest parent
pom 20
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 5ba790865235294f749a90b2518efff6e7f5b0ce
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Sep 2 14:49:28 2014 +0000
Update to latest parent pom 20
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1622027 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index ba36ca9..83a457b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>19</version>
+ <version>20</version>
</parent>
<artifactId>org.apache.sling.reqanalyzer</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 04/18: Update to latest parent
pom and use latest releases in launchpad
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 04ab3064b65da7e24b1832ccfc8e0d488066c147
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Feb 18 08:38:52 2013 +0000
Update to latest parent pom and use latest releases in launchpad
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1447147 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 7b43395..d4ee84b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>14</version>
+ <version>15</version>
</parent>
<artifactId>org.apache.sling.reqanalyzer</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 17/18: SLING-6433 Request
Processing Analyzer throws IOOB due to old format assumptions of
RequestProgressTracker output
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 0aec958a908b36de831d90ad1ed5d1980c42b176
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Wed Jan 4 13:04:38 2017 +0000
SLING-6433 Request Processing Analyzer throws IOOB due to old format assumptions of RequestProgressTracker output
Apply patch by Krystian Nowak (thanks a lot)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1777305 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 10 +++++
.../reqanalyzer/impl/gui/RequestTableModel.java | 5 +--
.../impl/gui/RequestTableModelTest.java | 51 ++++++++++++++++++++++
src/test/resources/requesttracker.txt | 7 +++
4 files changed, 70 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index 52e307a..72d61ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -82,6 +82,16 @@
</signature>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <!-- text test resources -->
+ <exclude>src/test/resources/*.txt</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
</plugins>
</build>
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTableModel.java b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTableModel.java
index 078bdbe..27f69a2 100644
--- a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTableModel.java
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTableModel.java
@@ -30,11 +30,10 @@ public class RequestTableModel implements TableModel {
private long previousStamp;
void addRow(String row) {
- // split row: "%1$7d (%2$tF %2$tT) %3$s%n
+ // split row: "%1$7d %3$s%n
final String stampS = row.substring(0, 7);
- final int endTimeStamp = row.indexOf(')');
- final String message = row.substring(endTimeStamp+2);
+ final String message = row.substring(7);
long stamp = Long.parseLong(stampS.trim());
long delta = stamp - this.previousStamp;
diff --git a/src/test/java/org/apache/sling/reqanalyzer/impl/gui/RequestTableModelTest.java b/src/test/java/org/apache/sling/reqanalyzer/impl/gui/RequestTableModelTest.java
new file mode 100644
index 0000000..1bac9b3
--- /dev/null
+++ b/src/test/java/org/apache/sling/reqanalyzer/impl/gui/RequestTableModelTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.reqanalyzer.impl.gui;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import org.junit.Test;
+
+public class RequestTableModelTest {
+
+ private RequestTableModel rtm = new RequestTableModel();
+
+ @Test
+ public final void testAddRow() throws IOException {
+
+ BufferedReader r = new BufferedReader(
+ new InputStreamReader(getClass().getResourceAsStream("/requesttracker.txt")));
+
+ String line;
+ while ((line = r.readLine()) != null) {
+ if (line.charAt(0) == '!') {
+ rtm.addRow(line.substring(1));
+ }
+ }
+
+ r.close();
+
+ assertTrue(rtm.getRowCount() > 0);
+ }
+
+}
diff --git a/src/test/resources/requesttracker.txt b/src/test/resources/requesttracker.txt
new file mode 100644
index 0000000..a94a31f
--- /dev/null
+++ b/src/test/resources/requesttracker.txt
@@ -0,0 +1,7 @@
+:1483519553437:3:GET:/libs/mylib/data.json:application/json; charset=ISO-8859-1:200
+! 0 TIMER_START{Request Processing}
+! 2 COMMENT timer_end format is {<elapsed microseconds>,<timer name>} <optional message>
+! 11 LOG Method=GET, PathInfo=/libs/mylib/data.json
+! 16431 LOG Including resource MyResource, type=my/ohmy/type, superType=null, path=/libs/mylib:foo (SlingRequestPathInfo: path='/libs/mylib:foo', selectorString='null', extension='json', suffix='/my/my.html')
+! 925338 TIMER_START{resolveServlet(/my/servlet)}
+! 925353 TIMER_END{13,resolveServlet(/my/servlet)} Using servlet /libs/mylib/mylib.jsp
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 05/18: Correct reactor pom and
update to parent pom 16
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 94bb94978ec17dc2af18d2019fdaa653494ff17e
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun May 5 14:38:24 2013 +0000
Correct reactor pom and update to parent pom 16
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479333 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index d4ee84b..1e7ccc6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>15</version>
+ <version>16</version>
</parent>
<artifactId>org.apache.sling.reqanalyzer</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 13/18: Update contrib modules
to Parent 23
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 8b3d4692b9888e9ad41141c33068c2029691e7a2
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Jun 25 13:10:59 2015 +0000
Update contrib modules to Parent 23
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1687503 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index e5c37ad..84bb04f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>22</version>
+ <version>23</version>
</parent>
<artifactId>org.apache.sling.reqanalyzer</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 01/18: SLING-2516 Request
Performance Analysis helper along with Java application to display the
collected data
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 51b2b9be95e71c226871c4047c78c78c97523c6e
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Fri Jun 22 06:29:14 2012 +0000
SLING-2516 Request Performance Analysis helper along with Java application to display the collected data
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1352777 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 141 ++++++++++++++++
.../reqanalyzer/impl/RequestAnalysisLogger.java | 161 +++++++++++++++++++
.../apache/sling/reqanalyzer/impl/gui/Main.java | 59 +++++++
.../sling/reqanalyzer/impl/gui/MainFrame.java | 82 ++++++++++
.../impl/gui/RequestListSelectionListener.java | 107 +++++++++++++
.../reqanalyzer/impl/gui/RequestTableModel.java | 98 ++++++++++++
.../reqanalyzer/impl/gui/RequestTrackerFile.java | 105 ++++++++++++
.../impl/gui/RequestTrackerFileEntry.java | 118 ++++++++++++++
.../apache/sling/reqanalyzer/impl/gui/Util.java | 177 +++++++++++++++++++++
9 files changed, 1048 insertions(+)
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..0e99218
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>12</version>
+ </parent>
+
+ <artifactId>org.apache.sling.reqanalyzer</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Sling Request Processing Analyzer</name>
+ <description>
+ Helps analyzing the processing times of Sling
+ requests. Writes the following information into
+ a log file:
+ - request start timestamp
+ - request end timestamp
+ - request URL, user, response status
+ - request progresstracker
+ </description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/reqanalyzer</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/reqanalyzer</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/reqanalyzer</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>maven-sling-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Category>sling</Bundle-Category>
+ <Main-Class>
+ org.apache.sling.reqanalyzer.impl.gui.Main
+ </Main-Class>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>animal-sniffer-maven-plugin</artifactId>
+ <configuration>
+ <signature>
+ <groupId>org.codehaus.mojo.signature</groupId>
+ <artifactId>java16</artifactId>
+ <version>1.0</version>
+ </signature>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.engine</artifactId>
+ <version>2.2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
+ <version>2.1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.settings</artifactId>
+ <version>1.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalysisLogger.java b/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalysisLogger.java
new file mode 100644
index 0000000..bcf98c4
--- /dev/null
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/RequestAnalysisLogger.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.reqanalyzer.impl;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.util.Iterator;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
+import org.apache.sling.engine.EngineConstants;
+import org.apache.sling.settings.SlingSettingsService;
+import org.osgi.framework.Constants;
+
+@Component(metatype = false)
+@Service
+@Properties({ @Property(name = EngineConstants.FILTER_NAME, value = "RequestAnalysisLogger"),
+ @Property(name = EngineConstants.SLING_FILTER_SCOPE, value = EngineConstants.FILTER_SCOPE_REQUEST),
+ @Property(name = Constants.SERVICE_RANKING, intValue = Integer.MAX_VALUE) })
+public class RequestAnalysisLogger implements Filter {
+
+ @Reference
+ private SlingSettingsService settings;
+
+ private BufferedWriter logFile;
+
+ @SuppressWarnings("unused")
+ @Activate
+ private void activate() throws IOException {
+ final File logFile = new File(settings.getSlingHomePath(), "logs/requesttracker.txt");
+ logFile.getParentFile().mkdirs();
+ final FileOutputStream out = new FileOutputStream(logFile, true);
+ this.logFile = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
+ }
+
+ @SuppressWarnings("unused")
+ @Deactivate
+ private void deactivate() throws IOException {
+ if (this.logFile != null) {
+ this.logFile.close();
+ this.logFile = null;
+ }
+ }
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
+ ServletException {
+
+ if (request instanceof SlingHttpServletRequest) {
+ final long start = System.currentTimeMillis();
+ final AnylserSlingHttpServletResponse slingRes = new AnylserSlingHttpServletResponse(
+ (SlingHttpServletResponse) response);
+ try {
+ chain.doFilter(request, response);
+ } finally {
+ final long end = System.currentTimeMillis();
+ final SlingHttpServletRequest slingReq = (SlingHttpServletRequest) request;
+
+ StringBuilder pw = new StringBuilder(1024);
+ pw.append(String.format(":%d:%d:%s:%s:%s:%d%n", start, (end - start), slingReq.getMethod(),
+ slingReq.getRequestURI(), slingRes.getContentType(), slingRes.getStatus()));
+
+ final Iterator<String> entries = slingReq.getRequestProgressTracker().getMessages();
+ while (entries.hasNext()) {
+ pw.append('!').append(entries.next());
+ }
+
+ BufferedWriter out = this.logFile;
+ if (out != null) {
+ out.write(pw.toString());
+ out.flush();
+ }
+ }
+ } else {
+ chain.doFilter(request, response);
+ }
+ }
+
+ public void destroy() {
+ }
+
+ private static class AnylserSlingHttpServletResponse extends SlingHttpServletResponseWrapper {
+
+ private int status = 200;
+
+ public AnylserSlingHttpServletResponse(SlingHttpServletResponse wrappedResponse) {
+ super(wrappedResponse);
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ @Override
+ public void setStatus(int sc) {
+ this.status = sc;
+ super.setStatus(sc);
+ }
+
+ @Override
+ public void setStatus(int sc, String sm) {
+ this.status = sc;
+ super.setStatus(sc, sm);
+ }
+
+ @Override
+ public void sendError(int sc) throws IOException {
+ this.status = sc;
+ super.sendError(sc);
+ }
+
+ @Override
+ public void sendError(int sc, String msg) throws IOException {
+ this.status = sc;
+ super.sendError(sc, msg);
+ }
+
+ @Override
+ public void sendRedirect(String location) throws IOException {
+ this.status = HttpServletResponse.SC_FOUND;
+ super.sendRedirect(location);
+ }
+ }
+}
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/Main.java b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/Main.java
new file mode 100644
index 0000000..c0efcca
--- /dev/null
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/Main.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.reqanalyzer.impl.gui;
+
+import java.awt.Dimension;
+import java.awt.GraphicsEnvironment;
+import java.awt.Toolkit;
+import java.io.File;
+import java.io.IOException;
+
+public class Main {
+
+ public static void main(String[] args) throws IOException {
+ if (GraphicsEnvironment.isHeadless()) {
+ System.err.println("Cannot run in headless mode");
+ System.exit(1);
+ }
+
+ if (args.length == 0) {
+ System.err.println("Missing argument <file>");
+ System.exit(1);
+ }
+
+ File file = new File(args[0]);
+ if (!file.canRead()) {
+ System.err.println("Cannot read from file " + file);
+ System.exit(1);
+ }
+
+ final int limit;
+ if (args.length >= 2) {
+ limit = Integer.parseInt(args[1]);
+ } else {
+ limit = Integer.MAX_VALUE;
+ }
+
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+
+ MainFrame frame = new MainFrame(file, limit, screenSize);
+ frame.setVisible(true);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/MainFrame.java b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/MainFrame.java
new file mode 100644
index 0000000..7feb4f1
--- /dev/null
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/MainFrame.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.reqanalyzer.impl.gui;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextPane;
+import javax.swing.ListSelectionModel;
+import javax.swing.table.JTableHeader;
+
+public class MainFrame extends JFrame {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final String MAIN_Y = "main.y";
+ private static final String MAIN_X = "main.x";
+ private static final String MAIN_HEIGHT = "main.height";
+ private static final String MAIN_WIDTH = "main.width";
+ private static final String MAIN_COLS = "main.cols";
+
+ public MainFrame(final File file, final int limit, final Dimension screenSize) throws FileNotFoundException,
+ IOException {
+
+ JTextPane text = Util.showStartupDialog("Reading from " + file, screenSize);
+
+ final RequestTrackerFile dm = new RequestTrackerFile(file, limit, text);
+
+ final JTable table = new JTable(dm);
+ table.setAutoCreateRowSorter(true);
+ table.setGridColor(Color.GRAY);
+ table.setShowGrid(true);
+ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ table.setRowSelectionAllowed(true);
+ table.setTableHeader(new JTableHeader(table.getColumnModel()));
+ Util.setupColumnWidths(table.getColumnModel(), MAIN_COLS);
+// table.setFont(new Font("Monospaced", table.getFont().getStyle(), table.getFont().getSize()));
+ table.getSelectionModel().addListSelectionListener(new RequestListSelectionListener(this, table, screenSize));
+
+ add(new JScrollPane(table));
+
+ setTitle(file.getPath());
+
+ // exit the application if the main frame is closed
+ addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ // setup location and size and ensure updating preferences
+ Util.setupComponentLocationSize(this, MAIN_X, MAIN_Y, MAIN_WIDTH, MAIN_HEIGHT, (int) screenSize.getWidth() / 4,
+ 0, (int) screenSize.getWidth() / 2, (int) screenSize.getHeight() / 4);
+
+ Util.disposeStartupDialog(text);
+ }
+}
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestListSelectionListener.java b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestListSelectionListener.java
new file mode 100644
index 0000000..1c12ed2
--- /dev/null
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestListSelectionListener.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.reqanalyzer.impl.gui;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Window;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.IOException;
+
+import javax.swing.JDialog;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.table.JTableHeader;
+import javax.swing.table.TableModel;
+
+public class RequestListSelectionListener implements ListSelectionListener {
+
+ private static final String REQUEST_Y = "request.y";
+ private static final String REQUEST_X = "request.x";
+ private static final String REQUEST_HEIGHT = "request.height";
+ private static final String REQUEST_WIDTH = "request.width";
+ private static final String REQUEST_COLS = "request.cols";
+
+ private final Window parent;
+ private final JTable table;
+ private final Dimension screenSize;
+
+ private JTable dataField = null;
+
+ public RequestListSelectionListener(final Window parent, final JTable table, final Dimension screenSize) {
+ this.parent = parent;
+ this.table = table;
+ this.screenSize = screenSize;
+ }
+
+ public void valueChanged(ListSelectionEvent e) {
+ if (!e.getValueIsAdjusting()) {
+ ListSelectionModel lsm = (ListSelectionModel) e.getSource();
+ int idx = lsm.getMinSelectionIndex();
+ if (idx >= 0) {
+ try {
+ idx = table.getRowSorter().convertRowIndexToModel(idx);
+ TableModel tm = ((RequestTrackerFile) table.getModel()).getData(idx);
+ if (dataField == null) {
+ dataField = new JTable();
+ dataField.setAutoCreateRowSorter(true);
+ dataField.setGridColor(Color.GRAY);
+ dataField.setShowGrid(true);
+ dataField.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ dataField.setRowSelectionAllowed(true);
+ dataField.setTableHeader(new JTableHeader(dataField.getColumnModel()));
+ dataField.setFont(new Font("Monospaced", dataField.getFont().getStyle(), dataField.getFont().getSize()));
+ dataField.setShowHorizontalLines(false);
+// dataField.setIntercellSpacing(new Dimension(3, 5));
+
+ JDialog d = new JDialog(this.parent);
+ d.add(new JScrollPane(dataField));
+
+ d.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ dataField = null;
+ }
+ });
+
+ // setup location and size and ensure updating preferences
+ Util.setupComponentLocationSize(d, REQUEST_X, REQUEST_Y, REQUEST_WIDTH, REQUEST_HEIGHT,
+ (int) screenSize.getWidth() / 4, (int) screenSize.getHeight() / 4,
+ (int) screenSize.getWidth() / 2, (int) screenSize.getHeight() / 2);
+
+ d.setVisible(true);
+ }
+
+ dataField.setModel(tm);
+
+ Util.setupColumnWidths(dataField.getColumnModel(), REQUEST_COLS);
+
+ } catch (IOException e1) {
+ // ignore
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTableModel.java b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTableModel.java
new file mode 100644
index 0000000..078bdbe
--- /dev/null
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTableModel.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.reqanalyzer.impl.gui;
+
+import java.util.ArrayList;
+
+import javax.swing.event.TableModelListener;
+import javax.swing.table.TableModel;
+
+public class RequestTableModel implements TableModel {
+
+ private final ArrayList<Object[]> rows = new ArrayList<Object[]>();
+
+ private long previousStamp;
+
+ void addRow(String row) {
+ // split row: "%1$7d (%2$tF %2$tT) %3$s%n
+
+ final String stampS = row.substring(0, 7);
+ final int endTimeStamp = row.indexOf(')');
+ final String message = row.substring(endTimeStamp+2);
+
+ long stamp = Long.parseLong(stampS.trim());
+ long delta = stamp - this.previousStamp;
+ this.previousStamp = stamp;
+
+ final Object[] rowValue = new Object[]{ stamp, delta, message };
+ this.rows.add(rowValue);
+ }
+
+ public int getRowCount() {
+ return rows.size();
+ }
+
+ public int getColumnCount() {
+ return 3;
+ }
+
+ public String getColumnName(int columnIndex) {
+ switch (columnIndex) {
+ case 0:
+ return "Timestamp";
+ case 1:
+ return "Delta";
+ case 2:
+ return "Message";
+ default:
+ throw new IllegalArgumentException("columnIndex=" + columnIndex);
+ }
+ }
+
+ public Class<?> getColumnClass(int columnIndex) {
+ switch (columnIndex) {
+ case 0:
+ return Long.class;
+ case 1:
+ return Long.class;
+ case 2:
+ return String.class;
+ default:
+ throw new IllegalArgumentException("columnIndex=" + columnIndex);
+ }
+ }
+
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ return false;
+ }
+
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ Object[] row = rows.get(rowIndex);
+ return row[columnIndex];
+ }
+
+ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
+ }
+
+ public void addTableModelListener(TableModelListener l) {
+ }
+
+ public void removeTableModelListener(TableModelListener l) {
+ }
+}
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTrackerFile.java b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTrackerFile.java
new file mode 100644
index 0000000..7d20bec
--- /dev/null
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTrackerFile.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.reqanalyzer.impl.gui;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.JTextPane;
+import javax.swing.event.TableModelListener;
+import javax.swing.table.TableModel;
+
+public class RequestTrackerFile implements TableModel {
+
+ private final RandomAccessFile raFile;
+ private final List<RequestTrackerFileEntry> entries;
+
+ RequestTrackerFile(File file, int limit, JTextPane text) throws FileNotFoundException, IOException {
+ this.raFile = new RandomAccessFile(file, "r");
+ this.entries = new ArrayList<RequestTrackerFileEntry>();
+ String line;
+ for (int i = 0; i < limit && (line = this.raFile.readLine()) != null; ) {
+ if (line.charAt(0) == ':') {
+ try {
+ text.setText(line);
+ RequestTrackerFileEntry entry = new RequestTrackerFileEntry(line, this.raFile.getFilePointer());
+ this.entries.add(entry);
+ i++;
+ } catch (Exception e) {
+ System.err.println(e);
+ e.printStackTrace(System.err);
+ break;
+ }
+ }
+ }
+ }
+
+ TableModel getData(final int rowIndex) throws IOException {
+ final RequestTrackerFileEntry entry = this.entries.get(rowIndex);
+ final long offset = entry.getOffset();
+ RequestTableModel rtm = new RequestTableModel();
+ this.raFile.seek(offset);
+ String line;
+ while ((line = raFile.readLine()) != null && line.charAt(0) == '!') {
+ rtm.addRow(line.substring(1));
+ }
+ return rtm;
+ }
+
+ public int getRowCount() {
+ return this.entries.size();
+ }
+
+ public int getColumnCount() {
+ return RequestTrackerFileEntry.getColumnCount();
+ }
+
+ public String getColumnName(int columnIndex) {
+ return RequestTrackerFileEntry.getColumnName(columnIndex);
+ }
+
+ public Class<?> getColumnClass(int columnIndex) {
+ return RequestTrackerFileEntry.getColumnClass(columnIndex);
+ }
+
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ return false;
+ }
+
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ RequestTrackerFileEntry entry = this.entries.get(rowIndex);
+ return entry.getField(columnIndex);
+ }
+
+ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
+ throw new UnsupportedOperationException("setValue");
+ }
+
+ public void addTableModelListener(TableModelListener l) {
+ // not really ...
+ }
+
+ public void removeTableModelListener(TableModelListener l) {
+ // not really ...
+ }
+}
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTrackerFileEntry.java b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTrackerFileEntry.java
new file mode 100644
index 0000000..744e3d5
--- /dev/null
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/RequestTrackerFileEntry.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.reqanalyzer.impl.gui;
+
+public class RequestTrackerFileEntry {
+
+ /*
+ * Request Tracker Info Line:
+ *
+ * :1340236961239:235:GET:/healthck/healthck.html:text/html; charset=UTF-8:200
+ */
+
+ private final long start;
+ private final long duration;
+ private final String method;
+ private final String url;
+ private final String contentType;
+ private final int status;
+ private final long offset;
+
+ static int getColumnCount() {
+ return 6;
+ }
+
+ static String getColumnName(final int idx) {
+ switch (idx) {
+ case 0:
+ return "Start";
+ case 1:
+ return "Duration";
+ case 2:
+ return "Method";
+ case 3:
+ return "URL";
+ case 4:
+ return "Content Type";
+ case 5:
+ return "Status";
+ default:
+ throw new IllegalArgumentException("Unknown field index " + idx);
+ }
+ }
+
+ static Class<?> getColumnClass(final int idx) {
+ switch (idx) {
+ case 0:
+ return Long.class;
+ case 1:
+ return Long.class;
+ case 2:
+ return String.class;
+ case 3:
+ return String.class;
+ case 4:
+ return String.class;
+ case 5:
+ return Integer.class;
+ default:
+ throw new IllegalArgumentException("Unknown field index " + idx);
+ }
+ }
+
+ RequestTrackerFileEntry(final String statusLine, final long offset) {
+ String[] parts = statusLine.split(":");
+ this.start = Long.parseLong(parts[1]);
+ this.duration = Long.parseLong(parts[2]);
+ this.method = parts[3];
+
+ String url = parts[4];
+ for (int i = 5; i < parts.length - 2; i++) {
+ url += ":" + parts[i];
+ }
+ this.url = url;
+
+ this.contentType = parts[parts.length-2];
+ this.status = Integer.parseInt(parts[parts.length-1]);
+ this.offset = offset;
+ }
+
+ Object getField(final int idx) {
+ switch (idx) {
+ case 0:
+ return start;
+ case 1:
+ return duration;
+ case 2:
+ return method;
+ case 3:
+ return url;
+ case 4:
+ return contentType;
+ case 5:
+ return status;
+ default:
+ throw new IllegalArgumentException("Unknown field index " + idx);
+ }
+ }
+
+ long getOffset() {
+ return offset;
+ }
+}
diff --git a/src/main/java/org/apache/sling/reqanalyzer/impl/gui/Util.java b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/Util.java
new file mode 100644
index 0000000..4f10539
--- /dev/null
+++ b/src/main/java/org/apache/sling/reqanalyzer/impl/gui/Util.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.reqanalyzer.impl.gui;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Window;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.Preferences;
+
+import javax.swing.JDialog;
+import javax.swing.JTextPane;
+import javax.swing.table.TableColumnModel;
+
+public class Util {
+
+ private Util() {
+ }
+
+ static JTextPane showStartupDialog(final String title, final Dimension screenSize) {
+ JTextPane text = new JTextPane();
+ text.setText("...");
+
+ JDialog d = new JDialog((Window) null);
+ d.setTitle(title);
+ d.add(text);
+ d.setSize((int) screenSize.getWidth() / 2, 30);
+ d.setLocation((int) screenSize.getWidth() / 4, (int) screenSize.getHeight() / 2 - 15);
+ d.setVisible(true);
+
+ return text;
+ }
+
+ static void disposeStartupDialog(final Component comp) {
+ Container parent = comp.getParent();
+ while (parent != null && !(parent instanceof Window)) {
+ parent = parent.getParent();
+ }
+ if (parent instanceof Window) {
+ ((Window) parent).dispose();
+ }
+ }
+
+ static void setupComponentLocationSize(final Component comp, final String propX, final String propY,
+ final String propWidth, final String propHeight, final int defaultX, final int defaultY,
+ final int defaultWidth, final int defaultHeight) {
+
+ comp.setLocation(getPreference(propX, defaultY), getPreference(propY, defaultX));
+ comp.setSize(getPreference(propWidth, defaultWidth), getPreference(propHeight, defaultHeight));
+
+ comp.addComponentListener(new ComponentAdapter() {
+ @Override
+ public void componentMoved(ComponentEvent e) {
+ setPreference(propX, e.getComponent().getX(), false);
+ setPreference(propY, e.getComponent().getY(), true);
+ }
+
+ @Override
+ public void componentResized(ComponentEvent e) {
+ setPreference(propWidth, e.getComponent().getWidth(), false);
+ setPreference(propHeight, e.getComponent().getHeight(), true);
+ }
+ });
+ }
+
+ static void setupColumnWidths(final TableColumnModel tcm, final String propertyName) {
+ PropertyChangeListener pcl = new PropertyChangeListener() {
+ private final String pclPropName = propertyName;
+ private final TableColumnModel pclTcm = tcm;
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ if ("width".equals(evt.getPropertyName())) {
+ int[] colWidths = new int[pclTcm.getColumnCount()];
+ for (int i = 0; i < colWidths.length; i++) {
+ colWidths[i] = pclTcm.getColumn(i).getWidth();
+ }
+ setPreference(pclPropName, colWidths, true);
+ }
+ }
+ };
+
+ int[] colWidths = getPreference(propertyName, new int[0]);
+ for (int i = 0; i < colWidths.length && i < tcm.getColumnCount(); i++) {
+ tcm.getColumn(i).setPreferredWidth(colWidths[i]);
+ }
+ for (int i = 0; i < tcm.getColumnCount(); i++) {
+ tcm.getColumn(i).addPropertyChangeListener(pcl);
+ }
+ }
+
+ static void setPreference(final String name, final Object value, final boolean flush) {
+ Preferences prefs = getPreferences();
+ try {
+ prefs.sync();
+ if (value instanceof Long) {
+ prefs.putLong(name, (Long) value);
+ } else if (value instanceof Integer) {
+ prefs.putInt(name, (Integer) value);
+ } else if (value instanceof int[]) {
+ String string = null;
+ for (int val : (int[]) value) {
+ if (string == null) {
+ string = String.valueOf(val);
+ } else {
+ string += "," + val;
+ }
+ }
+ prefs.put(name, string);
+ } else if (value != null) {
+ prefs.put(name, value.toString());
+ }
+
+ if (flush) {
+ prefs.flush();
+ }
+ } catch (BackingStoreException ioe) {
+ // ignore
+ }
+ }
+
+ static int getPreference(final String name, final int defaultValue) {
+ Preferences prefs = getPreferences();
+ try {
+ prefs.sync();
+ return prefs.getInt(name, defaultValue);
+ } catch (BackingStoreException ioe) {
+ // ignore
+ }
+ return defaultValue;
+ }
+
+ static int[] getPreference(final String name, final int[] defaultValues) {
+ Preferences prefs = getPreferences();
+ try {
+ prefs.sync();
+ String value = prefs.get(name, null);
+ if (value != null) {
+ String[] values = value.split(",");
+ int[] result = new int[values.length];
+ for (int i = 0; i < values.length; i++) {
+ result[i] = Integer.parseInt(values[i]);
+ }
+ return result;
+ }
+ } catch (BackingStoreException ioe) {
+ // ignore
+ } catch (NumberFormatException nfe) {
+ // ignore
+ }
+ return defaultValues;
+ }
+
+ static Preferences getPreferences() {
+ return Preferences.userNodeForPackage(Util.class);
+ }
+}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 02/18: Use latest parent pom
everywhere
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 28ab4af4033861f0a78e342a93acb64d7e9f2aa2
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Aug 1 13:53:43 2012 +0000
Use latest parent pom everywhere
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1367998 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 0e99218..37822b0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>12</version>
+ <version>13</version>
</parent>
<artifactId>org.apache.sling.reqanalyzer</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-reqanalyzer] 18/18: SLING-7167 Adjust
READMEs
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-reqanalyzer.git
commit 0df2ad9f0b2109ba67c9c98a20f984859da92835
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Tue Oct 3 09:29:49 2017 +0000
SLING-7167 Adjust READMEs
add missing README
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1810741 13f79535-47bb-0310-9956-ffa450edef68
---
README.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..fb71951
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# Apache Sling Request Processing Analyzer
+
+This module is part of the [Apache Sling](https://sling.apache.org) project.
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.