You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by sd...@apache.org on 2004/01/07 02:08:05 UTC
cvs commit: logging-log4j/src/java/org/apache/log4j/spi LoggingEvent.java
sdeboy 2004/01/06 17:08:05
Modified: src/java/org/apache/log4j/chainsaw
ChainsawCyclicBufferTableModel.java LogPanel.java
ColumnComparator.java ChainsawTabbedPane.java
EventContainer.java CyclicBufferList.java
src/java/org/apache/log4j/spi LoggingEvent.java
Removed: src/java/org/apache/log4j/chainsaw
FilterChangedListener.java
Log:
A rather large commit focused on improved performance of batch inserts into the tablemodel, better support for sorting, cyclic buffer/unlimited toggling and getting rid of the annoying -blink- when rows are added as much as possible.
- added sort support for most all columns, including mdc columns (required passing in the column name to the columncomparator)
- revamped cyclictablemodel tablemodel event firing logic to only generate firexxx events when the batch is complete
- modified eventcontainer to provide the index of the last inserted event (needed to better handle cyclic buffer event firing), a more intelligent table event firing mechanism when inserting events in batch, and to add better support for sorting
- removed unused filterchangedlistener
- updated cyclicbufferlist to return the index of last insert (needed for batch inserts)
- updated displayed values in table for mdc and properties to show name and values
Revision Changes Path
1.18 +116 -127 logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
Index: ChainsawCyclicBufferTableModel.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ChainsawCyclicBufferTableModel.java 2 Jan 2004 06:28:03 -0000 1.17
+++ ChainsawCyclicBufferTableModel.java 7 Jan 2004 01:08:05 -0000 1.18
@@ -63,7 +63,6 @@
import java.util.Set;
import javax.swing.ProgressMonitor;
-import javax.swing.SwingUtilities;
import javax.swing.event.EventListenerList;
import javax.swing.table.AbstractTableModel;
@@ -99,9 +98,8 @@
private int currentSortColumn;
private EventListenerList eventListenerList = new EventListenerList();
private List columnNames = new ArrayList(ChainsawColumns.getColumnsNames());
- private final FilterChangeExecutor filterExecutor =
- new FilterChangeExecutor();
private boolean sortEnabled = false;
+ private boolean reachedCapacity = false;
// protected final Object syncLock = new Object();
private LoggerNameModel loggerNameModelDelegate =
@@ -125,7 +123,31 @@
unfilteredList = new CyclicBufferList(capacity);
filteredList = new CyclicBufferList(capacity);
}
-
+
+ /* (non-Javadoc)
+ * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent evt) {
+ if (evt.getSource() instanceof Rule) {
+ reFilter();
+ }
+ }
+
+ private void reFilter() {
+ synchronized(unfilteredList) {
+ filteredList.clear();
+ Iterator iter = unfilteredList.iterator();
+ while (iter.hasNext()) {
+ LoggingEvent e = (LoggingEvent)iter.next();
+ if ((displayRule == null) || (displayRule.evaluate(e))) {
+ filteredList.add(e);
+ }
+ }
+ fireTableDataChanged();
+ notifyCountListeners();
+ }
+ }
+
/**
* @param l
*/
@@ -159,10 +181,6 @@
eventListenerList.add(EventCountListener.class, listener);
}
- public void filterChanged() {
- SwingUtilities.invokeLater(filterExecutor);
- }
-
public boolean isSortable(int col) {
return true;
}
@@ -195,19 +213,9 @@
if (this.displayRule != null) {
this.displayRule.addPropertyChangeListener(this);
}
-
reFilter();
}
- /**
- *
- */
- private void reFilter() {
- Thread thread = new Thread(filterExecutor);
- thread.setPriority(Thread.MIN_PRIORITY);
- thread.start();
- }
-
/* (non-Javadoc)
* @see org.apache.log4j.chainsaw.EventContainer#sort()
*/
@@ -217,17 +225,19 @@
synchronized (filteredList) {
Collections.sort(
filteredList,
- new ColumnComparator(currentSortColumn, currentSortAscending));
+ new ColumnComparator(getColumnName(currentSortColumn), currentSortColumn, currentSortAscending));
}
-
- fireTableDataChanged();
+ fireTableRowsUpdated(0, Math.max(filteredList.size() - 1, 0));
}
}
+
+ public boolean isSortEnabled() {
+ return sortEnabled;
+ }
public void sortColumn(int col, boolean ascending) {
LogLog.debug(
- "request to sort col=" + col + ", which is "
- + ChainsawColumns.getColumnsNames().get(col));
+ "request to sort col=" + col);
currentSortAscending = ascending;
currentSortColumn = col;
sortEnabled = true;
@@ -238,13 +248,13 @@
* @see org.apache.log4j.chainsaw.EventContainer#clear()
*/
public void clearModel() {
+ reachedCapacity = false;
synchronized (unfilteredList) {
unfilteredList.clear();
filteredList.clear();
idSet.clear();
uniqueRow = 0;
}
-
fireTableDataChanged();
notifyCountListeners();
}
@@ -371,13 +381,13 @@
return event.getRenderedMessage();
case ChainsawColumns.INDEX_MDC_COL_NAME:
- return event.getMDCKeySet();
+ return getMDC(event);
case ChainsawColumns.INDEX_NDC_COL_NAME:
return event.getNDC();
case ChainsawColumns.INDEX_PROPERTIES_COL_NAME:
- return event.getPropertyKeySet();
+ return getProperties(event);
case ChainsawColumns.INDEX_THREAD_COL_NAME:
return event.getThreadName();
@@ -386,16 +396,16 @@
return event.getThrowableStrRep();
case ChainsawColumns.INDEX_CLASS_COL_NAME:
- return (info == null) ? "" : info.getClassName();
+ return (info == null || (info != null && info.getClassName().equals("?"))) ? "" : info.getClassName();
case ChainsawColumns.INDEX_FILE_COL_NAME:
- return (info == null) ? "" : info.getFileName();
+ return (info == null || (info != null && info.getFileName().equals("?"))) ? "" : info.getFileName();
case ChainsawColumns.INDEX_LINE_COL_NAME:
- return (info == null) ? "" : info.getLineNumber();
+ return (info == null || (info != null && info.getLineNumber().equals("?"))) ? "" : info.getLineNumber();
case ChainsawColumns.INDEX_METHOD_COL_NAME:
- return (info == null) ? "" : info.getMethodName();
+ return (info == null || (info != null && info.getMethodName().equals("?"))) ? "" : info.getMethodName();
default:
@@ -406,6 +416,38 @@
return "";
}
+
+ private String getMDC(LoggingEvent event) {
+ Iterator iter = event.getMDCKeySet().iterator();
+ StringBuffer mdc = new StringBuffer("{");
+
+ while (iter.hasNext()) {
+ mdc.append("{");
+ Object key = iter.next();
+ mdc.append(key);
+ mdc.append(",");
+ mdc.append(event.getMDC(key.toString()));
+ mdc.append("}");
+ }
+ mdc.append("}");
+ return mdc.toString();
+ }
+
+ private String getProperties(LoggingEvent event) {
+ Iterator iter = event.getPropertyKeySet().iterator();
+ StringBuffer prop = new StringBuffer("{");
+
+ while (iter.hasNext()) {
+ prop.append("{");
+ Object key = iter.next();
+ prop.append(key);
+ prop.append(",");
+ prop.append(event.getProperty(key.toString()));
+ prop.append("}");
+ }
+ prop.append("}");
+ return prop.toString();
+ }
public boolean isAddRow(LoggingEvent e, boolean valueIsAdjusting) {
boolean rowAdded = false;
@@ -423,16 +465,11 @@
}
idSet.add(id);
unfilteredList.add(e);
- rowAdded = true;
if ((displayRule == null) || (displayRule.evaluate(e))) {
synchronized (filteredList) {
filteredList.add(e);
- if (filteredList.size() < capacity) {
- fireTableRowsInserted(filteredList.size(), filteredList.size());
- } else {
- fireTableDataChanged();
- }
+ rowAdded = true;
}
}
@@ -457,9 +494,43 @@
}
}
}
+ if (!valueIsAdjusting) {
+ int lastAdded = getLastAdded();
+ fireTableEvent(lastAdded, lastAdded, 1);
+ }
return rowAdded;
}
+
+ public int getLastAdded() {
+ int last = 0;
+ if (cyclic) {
+ last = ((CyclicBufferList)filteredList).getLast();
+ } else {
+ last = filteredList.size();
+ }
+ return last;
+ }
+
+ public void fireTableEvent(int begin, int end, int count) {
+ if (cyclic) {
+ if (!reachedCapacity) {
+ //if we didn't loop and it's the 1st time, insert
+ if (begin + count < capacity) {
+ fireTableRowsInserted(begin, end);
+ } else {
+ //we did loop - insert and then update rows
+ fireTableRowsInserted(begin, capacity);
+ fireTableRowsUpdated(0, capacity);
+ reachedCapacity = true;
+ }
+ } else {
+ fireTableRowsUpdated(0, capacity);
+ }
+ } else {
+ fireTableRowsInserted(begin, end);
+ }
+ }
/**
* @param key
@@ -486,14 +557,7 @@
* @return
*/
public int getMaxSize() {
- synchronized (unfilteredList) {
- if (!isCyclic()) {
- throw new IllegalStateException(
- "You cannot call getMaxSize() when the model is not cyclic");
- }
-
- return ((CyclicBufferList) unfilteredList).getMaxSize();
- }
+ return capacity;
}
/* (non-Javadoc)
@@ -511,15 +575,6 @@
}
/* (non-Javadoc)
- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent evt) {
- if (evt.getSource() instanceof Rule) {
- reFilter();
- }
- }
-
- /* (non-Javadoc)
* @see javax.swing.table.TableModel#isCellEditable(int, int)
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
@@ -534,14 +589,13 @@
/* (non-Javadoc)
* @see org.apache.log4j.chainsaw.EventContainer#setCyclic(boolean)
*/
- public void setCyclic(boolean cyclic) {
+ public void setCyclic(final boolean cyclic) {
if (this.cyclic == cyclic) {
return;
}
-
- boolean old = this.cyclic;
+ final boolean old = this.cyclic;
this.cyclic = cyclic;
- propertySupport.firePropertyChange("cyclic", old, this.cyclic);
+ propertySupport.firePropertyChange("cyclic", old, cyclic);
}
/* (non-Javadoc)
@@ -566,76 +620,6 @@
return unfilteredList.size();
}
- class FilterChangeExecutor implements Runnable {
- /**
- * Update filtered rows.
- */
- FilterChangeExecutor() {
- }
-
- public synchronized void run() {
- ProgressMonitor monitor = null;
- LogLog.debug("Filtering");
-
- try {
- monitor =
- new ProgressMonitor(
- null, "Please wait...", "Filtering display", 0,
- unfilteredList.size());
- monitor.setMillisToPopup(250);
-
- int index = 0;
-
- List newFilteredList = null;
-
- if (isCyclic()) {
- newFilteredList = new CyclicBufferList(capacity);
- } else {
- newFilteredList = new ArrayList(capacity);
- }
-
- synchronized (unfilteredList) {
- if (displayRule != null) {
- LoggingEvent event = null;
- Iterator iter = unfilteredList.iterator();
-
- while (iter.hasNext()) {
- event = (LoggingEvent) iter.next();
-
- if (displayRule.evaluate(event)) {
- newFilteredList.add(event);
- }
-
- monitor.setProgress(index++);
- }
- } else {
- newFilteredList.addAll(unfilteredList);
- }
-
- synchronized (filteredList) {
- filteredList = newFilteredList;
- }
- }
- } finally {
- if (monitor != null) {
- monitor.close();
- }
- }
-
- if (sortEnabled) {
- sort();
- }
-
- SwingUtilities.invokeLater(
- new Runnable() {
- public void run() {
- fireTableDataChanged();
- notifyCountListeners();
- }
- });
- }
- }
-
private class ModelChanger implements PropertyChangeListener {
/* (non-Javadoc)
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
@@ -662,13 +646,16 @@
"Changing Model, isCyclic is now " + isCyclic());
List newUnfilteredList = null;
+ List newFilteredList = null;
HashSet newIDSet = null;
newIDSet = new HashSet(capacity);
if (isCyclic()) {
newUnfilteredList = new CyclicBufferList(capacity);
+ newFilteredList = new CyclicBufferList(capacity);
} else {
newUnfilteredList = new ArrayList(capacity);
+ newFilteredList = new ArrayList(capacity);
}
int increment = 0;
@@ -686,11 +673,13 @@
}
unfilteredList = newUnfilteredList;
+ filteredList = newFilteredList;
idSet = newIDSet;
}
monitor.setNote("Refiltering...");
reFilter();
+
monitor.setProgress(index++);
} finally {
monitor.close();
1.46 +12 -8 logging-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java
Index: LogPanel.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- LogPanel.java 31 Dec 2003 19:31:16 -0000 1.45
+++ LogPanel.java 7 Jan 2004 01:08:05 -0000 1.46
@@ -1708,15 +1708,15 @@
//table.getSelectionModel().setValueIsAdjusting(true);
boolean rowAdded = false;
- int currentRow = getCurrentRow();
+ int first = tableModel.getLastAdded() + 1;
+
for (Iterator iter = eventBatchEntrys.iterator(); iter.hasNext();) {
ChainsawEventBatchEntry entry = (ChainsawEventBatchEntry) iter.next();
updateOtherModels(entry);
- boolean isCurrentRowAdded = tableModel.isAddRow(entry.getEvent(),
- true);
+ boolean isCurrentRowAdded = tableModel.isAddRow(entry.getEvent(), true);
rowAdded = rowAdded ? true : isCurrentRowAdded;
}
table.getSelectionModel().setValueIsAdjusting(false);
@@ -1725,15 +1725,19 @@
tableModel.notifyCountListeners();
if (rowAdded) {
- tableModel.sort();
+ int currentRow = getCurrentRow();
+ if (tableModel.isSortEnabled()) {
+ tableModel.sort();
+ }
+ tableModel.fireTableEvent(first, tableModel.getLastAdded(), eventBatchEntrys.size());
if (scrollToBottom.isScrolled() && !scrollToBottom.isBypassed()) {
table.scrollToBottom(table.columnAtPoint(
- table.getVisibleRect().getLocation()));
+ table.getVisibleRect().getLocation()));
} else {
- table.scrollToRow(currentRow,
- table.columnAtPoint(table.getVisibleRect().getLocation()));
- detailPaneUpdater.setSelectedRow(currentRow);
+ table.scrollToRow(currentRow,
+ table.columnAtPoint(table.getVisibleRect().getLocation()));
+ detailPaneUpdater.setSelectedRow(currentRow);
}
}
}
1.4 +57 -3 logging-log4j/src/java/org/apache/log4j/chainsaw/ColumnComparator.java
Index: ColumnComparator.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/ColumnComparator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ColumnComparator.java 2 Nov 2003 19:53:47 -0000 1.3
+++ ColumnComparator.java 7 Jan 2004 01:08:05 -0000 1.4
@@ -49,10 +49,10 @@
package org.apache.log4j.chainsaw;
-import org.apache.log4j.spi.LoggingEvent;
-
import java.util.Comparator;
+import org.apache.log4j.spi.LoggingEvent;
+
/**
*
@@ -63,8 +63,10 @@
public class ColumnComparator implements Comparator {
protected int index;
protected boolean ascending;
+ protected String columnName;
- public ColumnComparator(int index, boolean ascending) {
+ public ColumnComparator(String columnName, int index, boolean ascending) {
+ this.columnName = columnName;
this.index = index;
this.ascending = ascending;
}
@@ -97,6 +99,15 @@
break;
+ case ChainsawColumns.INDEX_NDC_COL_NAME:
+ if (e1.getNDC() != null && e2.getNDC() != null) {
+ sort =
+ e1.getNDC().compareToIgnoreCase(
+ e2.getNDC());
+ }
+
+ break;
+
case ChainsawColumns.INDEX_METHOD_COL_NAME:
if (
@@ -140,6 +151,49 @@
case ChainsawColumns.INDEX_THREAD_COL_NAME:
sort = e1.getThreadName().compareToIgnoreCase(e2.getThreadName());
break;
+
+ case ChainsawColumns.INDEX_ID_COL_NAME:
+ int id1 = Integer.parseInt(e1.getProperty(ChainsawConstants.LOG4J_ID_KEY));
+ int id2 = Integer.parseInt(e2.getProperty(ChainsawConstants.LOG4J_ID_KEY));
+ if (id1 == id2) {
+ sort = 0;
+ } else if (id1 < id2) {
+ sort = 1;
+ } else {
+ sort = -1;
+ }
+ break;
+
+ case ChainsawColumns.INDEX_THROWABLE_COL_NAME:
+ if (e1.getThrowableStrRep() != null && e2.getThrowableStrRep() != null) {
+ String[] s1 = e1.getThrowableStrRep();
+ String[] s2 = e2.getThrowableStrRep();
+ boolean foundDiff = false;
+ for (int i = 0;i<s1.length;i++) {
+ if (foundDiff || i > s2.length) {
+ break;
+ }
+ sort = s1[i].compareToIgnoreCase(s2[i]);
+ foundDiff = sort != 0;
+ }
+ }
+ break;
+
+ case ChainsawColumns.INDEX_LINE_COL_NAME:
+ if (
+ (e1.locationInformationExists())
+ & (e2.locationInformationExists())) {
+ sort =
+ e1.getLocationInformation().getLineNumber().compareToIgnoreCase(
+ e2.getLocationInformation().getLineNumber());
+ }
+ break;
+
+ //other columns may be MDC values - see if there is an MDC value matching column name
+ default:
+ if (e1.getMDC(columnName) != null && e2.getMDC(columnName) != null) {
+ sort = e1.getMDC(columnName).toString().compareToIgnoreCase(e2.getMDC(columnName).toString());
+ }
}
}
1.3 +1 -1 logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawTabbedPane.java
Index: ChainsawTabbedPane.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawTabbedPane.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ChainsawTabbedPane.java 22 Jul 2003 03:07:47 -0000 1.2
+++ ChainsawTabbedPane.java 7 Jan 2004 01:08:05 -0000 1.3
@@ -119,7 +119,7 @@
super.insertTab(name, icon, component, null, 0);
//only select the previously existing tab if there is more than one tab
if (getTabCount() > 1) {
- setSelectedIndex(selectedIndex + 1);
+ setSelectedIndex(Math.min(selectedIndex + 1, getTabCount() - 1));
}
super.fireStateChanged();
1.10 +15 -2 logging-log4j/src/java/org/apache/log4j/chainsaw/EventContainer.java
Index: EventContainer.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/EventContainer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- EventContainer.java 14 Dec 2003 20:35:09 -0000 1.9
+++ EventContainer.java 7 Jan 2004 01:08:05 -0000 1.10
@@ -65,8 +65,7 @@
* @author Scott Deboy <sd...@apache.org>
*
*/
-public interface EventContainer extends SortTableModel, FilterChangedListener,
- LoggerNameModel {
+public interface EventContainer extends SortTableModel, LoggerNameModel {
/**
* Adds an EventCountListener, to be notified when the # of events changes
* @param listener
@@ -144,6 +143,11 @@
* Returns the vector representing the row.
*/
LoggingEvent getRow(int row);
+
+ /**
+ * Return the last added row.
+ */
+ int getLastAdded();
/**
* Adds a row to the model.
@@ -153,6 +157,15 @@
*/
boolean isAddRow(LoggingEvent e, boolean valueIsAdjusting);
+ /**
+ * Return whether or not this container is sorting.
+ */
+ boolean isSortEnabled();
+
+ /**
+ * Fire appropriate table update events for the range.
+ */
+ void fireTableEvent(int begin, int end, int count);
/**
* Allow a forced notification of the EventCountListeners
*
1.3 +4 -0 logging-log4j/src/java/org/apache/log4j/chainsaw/CyclicBufferList.java
Index: CyclicBufferList.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/CyclicBufferList.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CyclicBufferList.java 20 Dec 2003 00:20:24 -0000 1.2
+++ CyclicBufferList.java 7 Jan 2004 01:08:05 -0000 1.3
@@ -176,6 +176,10 @@
public int getMaxSize() {
return maxSize;
}
+
+ public int getLast() {
+ return last;
+ }
/**
Get the oldest (first) element in the buffer. The oldest element
1.45 +2 -1 logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
Index: LoggingEvent.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- LoggingEvent.java 9 Dec 2003 21:28:28 -0000 1.44
+++ LoggingEvent.java 7 Jan 2004 01:08:05 -0000 1.45
@@ -533,7 +533,8 @@
/**
* Returns the set of of the key values in the properties
- * for the event. The returned set is unmodifiable by the caller.
+ * for the event or Collections.EMPTY_SET if properties do not exist.
+ * The returned set is unmodifiable by the caller.
*
* @return Set an unmodifiable set of the property keys.
* @since 1.3
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org