jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1782509 - /jmeter/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java
Date Fri, 10 Feb 2017 19:46:02 GMT
Author: fschumacher
Date: Fri Feb 10 19:46:02 2017
New Revision: 1782509

URL: http://svn.apache.org/viewvc?rev=1782509&view=rev
Log:
Simplify implementation.

Bugzilla Id: 60687

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java?rev=1782509&r1=1782508&r2=1782509&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java Fri Feb 10 19:46:02 2017
@@ -20,7 +20,6 @@ package org.apache.jmeter.gui;
 
 import java.awt.BorderLayout;
 import java.awt.Insets;
-import java.util.Iterator;
 
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
@@ -28,7 +27,9 @@ import javax.swing.JTextArea;
 import javax.swing.ScrollPaneConstants;
 import javax.swing.Timer;
 
-import org.apache.commons.collections.buffer.BoundedFifoBuffer;
+import org.apache.commons.collections.Buffer;
+import org.apache.commons.collections.buffer.CircularFifoBuffer;
+import org.apache.commons.collections.buffer.UnboundedFifoBuffer;
 import org.apache.jmeter.gui.logging.GuiLogEventListener;
 import org.apache.jmeter.gui.logging.LogEventObject;
 import org.apache.jmeter.gui.util.JSyntaxTextArea;
@@ -57,25 +58,21 @@ public class LoggerPanel extends JPanel
     private static final int LOGGER_PANEL_REFRESH_PERIOD =
             JMeterUtils.getPropDefault("jmeter.loggerpanel.refresh_period", 500); // $NON-NLS-1$
 
-    private final BoundedFifoBuffer events =
-            new BoundedFifoBuffer(valueOrMax(LOGGER_PANEL_MAX_LINES, 2000)); // $NON-NLS-1$
+    private final Buffer events;
 
     private volatile boolean logChanged = false;
 
-    private Timer timer;
-
     /**
      * Pane for display JMeter log file
      */
     public LoggerPanel() {
-        textArea = init();
-    }
-
-    private static int valueOrMax(int value, int max) {
-        if (value > 0) {
-            return value;
+        if (LOGGER_PANEL_MAX_LINES > 0) {
+            events =
+                    new CircularFifoBuffer(LOGGER_PANEL_MAX_LINES);
+        } else {
+            events = new UnboundedFifoBuffer();
         }
-        return max;
+        textArea = init();
     }
 
     private JTextArea init() { // WARNING: called from ctor so must not be overridden (i.e.
must be private or final)
@@ -121,9 +118,6 @@ public class LoggerPanel extends JPanel
 
         String logMessage = logEventObject.toString();
         synchronized (events) {
-            if (events.isFull()) {
-                events.remove();
-            }
             events.add(logMessage);
         }
 
@@ -131,36 +125,34 @@ public class LoggerPanel extends JPanel
     }
 
     private void initWorker() {
-        timer = new Timer(
+        Timer timer = new Timer(
             LOGGER_PANEL_REFRESH_PERIOD,
-            e -> {
-                if (logChanged) {
-                    logChanged = false;
-                    StringBuilder builder = new StringBuilder();
-                    synchronized (events) {
-                        Iterator<String> lines = events.iterator();
-                        while (lines.hasNext()) {
-                            builder.append(lines.next());
-                        }
-                    }
-                    String logText = builder.toString();
-                    synchronized (textArea) {
-                        int currentLength;
-                        if (LOGGER_PANEL_MAX_LINES > 0) {
-                            textArea.setText(logText);
-                            currentLength = logText.length();
-                        } else {
-                            textArea.append(logText);
-                            currentLength = textArea.getText().length();
-                        }
-                        textArea.setCaretPosition(currentLength);
-                    }
-                }
-            }
-        );
+            e -> updateLogEntries());
         timer.start();
     }
 
+    private void updateLogEntries() {
+        if (!logChanged) {
+            return;
+        }
+        logChanged = false;
+        StringBuilder builder = new StringBuilder();
+        synchronized (events) {
+            for (Object line: events) {
+                builder.append((String) line);
+            }
+        }
+        String logText = builder.toString();
+        synchronized (textArea) {
+            if (LOGGER_PANEL_MAX_LINES > 0) {
+                textArea.setText(logText);
+            } else {
+                textArea.append(logText);
+            }
+            textArea.setCaretPosition(textArea.getText().length());
+        }
+    }
+
     /**
      * Clear panel content
      */



Mime
View raw message