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 ps...@apache.org on 2003/09/19 05:55:23 UTC
cvs commit: jakarta-log4j/src/java/org/apache/log4j/chainsaw ChainsawCyclicBufferTableModel.java
psmith 2003/09/18 20:55:23
Modified: src/java/org/apache/log4j/chainsaw
ChainsawCyclicBufferTableModel.java
Log:
* removed a few methods that were accidently overridden
as part of an Eclipse delegate refactor, my bad.
* Removed some unneed code used for sorting, and generally tweaked the way it worked
* Refactored the synchronization methods to improve display and filtering performance.
Currently there is one outstanding bug with this change. Switching
between Cyclic and Unlimited mode can cause a ClassCastException
because isCyclic returns true, but the subsequent cast
doesn't work because the model has been changed in between. Still working on this.
Revision Changes Path
1.10 +151 -133 jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
Index: ChainsawCyclicBufferTableModel.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ChainsawCyclicBufferTableModel.java 17 Sep 2003 01:13:41 -0000 1.9
+++ ChainsawCyclicBufferTableModel.java 19 Sep 2003 03:55:23 -0000 1.10
@@ -68,6 +68,7 @@
import java.util.ListIterator;
import java.util.Set;
+import javax.swing.ProgressMonitor;
import javax.swing.SwingUtilities;
import javax.swing.event.EventListenerList;
import javax.swing.table.AbstractTableModel;
@@ -99,7 +100,8 @@
private final FilterChangeExecutor filterExecutor =
new FilterChangeExecutor();
private boolean sortEnabled = false;
- protected final Object syncLock = new Object();
+
+ // protected final Object syncLock = new Object();
private LoggerNameModel loggerNameModelDelegate =
new LoggerNameModelSupport();
@@ -122,13 +124,6 @@
loggerNameModelDelegate.removeLoggerNameListener(l);
}
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return loggerNameModelDelegate.hashCode();
- }
-
/**
* @param loggerName
* @return
@@ -137,13 +132,6 @@
return loggerNameModelDelegate.addLoggerName(loggerName);
}
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return loggerNameModelDelegate.toString();
- }
-
/**
* @param l
*/
@@ -158,13 +146,6 @@
return loggerNameModelDelegate.getLoggerNames();
}
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- return loggerNameModelDelegate.equals(obj);
- }
-
public void addEventCountListener(EventCountListener listener) {
eventListenerList.add(EventCountListener.class, listener);
}
@@ -213,7 +194,9 @@
*
*/
private void reFilter() {
- new Thread(filterExecutor).start();
+ Thread thread = new Thread(filterExecutor);
+ thread.setPriority(Thread.MIN_PRIORITY);
+ thread.start();
}
/* (non-Javadoc)
@@ -221,27 +204,34 @@
*/
public void sort() {
if (sortEnabled) {
- synchronized (syncLock) {
+ int size = 0;
+
+ synchronized (filteredList) {
+ size = filteredList.size();
Collections.sort(
filteredList,
new ColumnComparator(currentSortColumn, currentSortAscending));
}
+
+ fireTableRowsUpdated(0, size);
}
}
- public void sortColumn(
- JSortTable table, int col, int row, boolean ascending) {
+ public void sortColumn(int col, boolean ascending) {
LogLog.debug(
"request to sort col=" + col + ", which is "
+ ChainsawColumns.getColumnsNames().get(col));
- SwingUtilities.invokeLater(new SortExecutor(table, col, row, ascending));
+ currentSortAscending = ascending;
+ currentSortColumn = col;
+ sortEnabled = true;
+ sort();
}
/* (non-Javadoc)
* @see org.apache.log4j.chainsaw.EventContainer#clear()
*/
public void clearModel() {
- synchronized (syncLock) {
+ synchronized (unfilteredList) {
unfilteredList.clear();
filteredList.clear();
uniqueRow = 0;
@@ -266,7 +256,7 @@
int currentRow = -1;
String thisVal = null;
- synchronized (syncLock) {
+ synchronized (filteredList) {
ListIterator iter = filteredList.listIterator();
while (iter.hasNext()) {
@@ -290,7 +280,7 @@
public List getAllEvents() {
List list = new ArrayList(unfilteredList.size());
- synchronized (syncLock) {
+ synchronized (unfilteredList) {
list.addAll(unfilteredList);
}
@@ -298,7 +288,7 @@
}
public int getRowIndex(LoggingEvent e) {
- synchronized (syncLock) {
+ synchronized (filteredList) {
return filteredList.indexOf(e);
}
}
@@ -312,17 +302,29 @@
}
public LoggingEvent getRow(int row) {
- return (LoggingEvent) filteredList.get(row);
+ synchronized (filteredList) {
+ if (row < filteredList.size()) {
+ return (LoggingEvent) filteredList.get(row);
+ }
+ }
+
+ return null;
}
public int getRowCount() {
- synchronized (syncLock) {
+ synchronized (filteredList) {
return filteredList.size();
}
}
public Object getValueAt(int rowIndex, int columnIndex) {
- LoggingEvent event = (LoggingEvent) filteredList.get(rowIndex);
+ LoggingEvent event = null;
+
+ synchronized (filteredList) {
+ if (rowIndex < filteredList.size()) {
+ event = (LoggingEvent) filteredList.get(rowIndex);
+ }
+ }
if (event == null) {
return null;
@@ -398,36 +400,36 @@
public boolean isAddRow(LoggingEvent e, boolean valueIsAdjusting) {
boolean rowAdded = false;
- synchronized (syncLock) {
- Object id = e.getProperty(ChainsawConstants.LOG4J_ID_KEY);
+ int newRow = 0;
+ Object id = e.getProperty(ChainsawConstants.LOG4J_ID_KEY);
- if (id == null) {
- id = new Integer(++uniqueRow);
- e.setProperty(ChainsawConstants.LOG4J_ID_KEY, id.toString());
- }
+ if (id == null) {
+ id = new Integer(++uniqueRow);
+ e.setProperty(ChainsawConstants.LOG4J_ID_KEY, id.toString());
+ }
- //prevent duplicate rows
- if (unfilteredList.contains(e)) {
- return false;
- }
+ //prevent duplicate rows
+ if (unfilteredList.contains(e)) {
+ return false;
+ }
- unfilteredList.add(e);
+ unfilteredList.add(e);
- rowAdded = true;
+ rowAdded = true;
- if ((displayRule == null) || (displayRule.evaluate(e))) {
+ if ((displayRule == null) || (displayRule.evaluate(e))) {
+ synchronized (filteredList) {
filteredList.add(e);
-
- rowAdded = true;
+ newRow = filteredList.size() - 1;
}
+
+ rowAdded = true;
}
if (!valueIsAdjusting) {
notifyCountListeners();
}
- int newRow = filteredList.size() - 1;
-
/**
* Is this a new MDC key we haven't seen before?
*/
@@ -489,12 +491,14 @@
* @return
*/
public int getMaxSize() {
- if (!isCyclic()) {
- throw new IllegalStateException(
- "You cannot call getMaxSize() when the model is not cyclic");
- }
+ synchronized (unfilteredList) {
+ if (!isCyclic()) {
+ throw new IllegalStateException(
+ "You cannot call getMaxSize() when the model is not cyclic");
+ }
- return ((CyclicBufferList) unfilteredList).getMaxSize();
+ return ((CyclicBufferList) unfilteredList).getMaxSize();
+ }
}
/* (non-Javadoc)
@@ -567,82 +571,66 @@
return unfilteredList.size();
}
- class SortExecutor implements Runnable {
- private JSortTable table;
- private int col;
- private int currentRow;
- private boolean ascending;
-
+ class FilterChangeExecutor implements Runnable {
/**
- * Re-apply current sort column in the same order, and re-select the row.
+ * Update filtered rows.
*/
- public SortExecutor(
- JSortTable table, int col, int currentRow, boolean ascending) {
- this.table = table;
- this.col = col;
- this.currentRow = currentRow;
- this.ascending = ascending;
+ FilterChangeExecutor() {
}
- public void run() {
- synchronized (syncLock) {
- LoggingEvent v = null;
+ 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);
- if ((currentRow > -1) && (currentRow < filteredList.size())) {
- v = (LoggingEvent) filteredList.get(currentRow);
- }
+ int index = 0;
- sortEnabled = true;
- currentSortColumn = col;
- currentSortAscending = ascending;
+ List newFilteredList = null;
- if (col > -1) {
- sort();
- }
-
- if (v == null) {
- table.scrollToRow(
- -1, table.columnAtPoint(table.getVisibleRect().getLocation()));
+ if (isCyclic()) {
+ newFilteredList = new CyclicBufferList(INITIAL_CAPACITY);
} else {
- table.scrollToRow(
- filteredList.indexOf(v),
- table.columnAtPoint(table.getVisibleRect().getLocation()));
+ newFilteredList = new ArrayList(INITIAL_CAPACITY);
}
- }
- }
- }
- class FilterChangeExecutor implements Runnable {
- /**
- * Update filtered rows.
- */
- FilterChangeExecutor() {
- }
+ 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);
+ }
- public void run() {
- synchronized (syncLock) {
- filteredList.clear();
-
- if (displayRule != null) {
- LoggingEvent event = null;
- Iterator iter = unfilteredList.iterator();
-
- while (iter.hasNext()) {
- event = (LoggingEvent) iter.next();
-
- if (displayRule.evaluate(event)) {
- filteredList.add(event);
+ monitor.setProgress(index++);
}
+ } else {
+ newFilteredList.addAll(unfilteredList);
}
- } else {
- filteredList.addAll(unfilteredList);
- }
- if (sortEnabled) {
- sort();
+ synchronized (filteredList) {
+ filteredList = newFilteredList;
+ }
+ }
+ } finally {
+ if (monitor != null) {
+ monitor.close();
}
}
+ if (sortEnabled) {
+ sort();
+ }
+
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
@@ -658,25 +646,55 @@
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent arg0) {
- synchronized (syncLock) {
- LogLog.debug("Changing Model, isCyclic is now " + isCyclic());
+ Thread thread =
+ new Thread(
+ new Runnable() {
+ public void run() {
+ ProgressMonitor monitor = null;
+
+ int index = 0;
+
+ try {
+ synchronized (unfilteredList) {
+ monitor =
+ new ProgressMonitor(
+ null, "Switching models...",
+ "Transferring between data structures, please wait...", 0,
+ unfilteredList.size() + 1);
+ monitor.setMillisToDecideToPopup(250);
+ monitor.setMillisToPopup(100);
+ LogLog.debug(
+ "Changing Model, isCyclic is now " + isCyclic());
+
+ List newUnfilteredList = null;
+
+ if (isCyclic()) {
+ newUnfilteredList = new CyclicBufferList(INITIAL_CAPACITY);
+ } else {
+ newUnfilteredList = new ArrayList(INITIAL_CAPACITY);
+ }
+
+ for (Iterator iter = unfilteredList.iterator();
+ iter.hasNext();) {
+ newUnfilteredList.add(iter.next());
+ monitor.setProgress(index++);
+ }
+
+ unfilteredList = newUnfilteredList;
+ }
+
+ monitor.setNote("Refiltering...");
+ filterExecutor.run();
+ monitor.setProgress(index++);
+ } finally {
+ monitor.close();
+ }
- List oldUnfilteredList = unfilteredList;
- List oldFilteredList = filteredList;
-
- if (isCyclic()) {
- unfilteredList = new CyclicBufferList(INITIAL_CAPACITY);
- filteredList = new CyclicBufferList(INITIAL_CAPACITY);
- } else {
- unfilteredList = new ArrayList(INITIAL_CAPACITY);
- filteredList = new ArrayList(INITIAL_CAPACITY);
- }
-
- unfilteredList.addAll(oldUnfilteredList);
- filteredList.addAll(oldFilteredList);
- }
-
- LogLog.debug("Model Change completed");
+ LogLog.debug("Model Change completed");
+ }
+ });
+ thread.setPriority(Thread.MIN_PRIORITY + 1);
+ thread.start();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org