From: Pavel V. <va...@us...> - 2002-07-31 16:52:40
|
Update of /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/views In directory usw-pr-cvs1:/tmp/cvs-serv17145 Modified Files: AllocHistogramTableModel.java Log Message: added dispose(), using HasChildrenInterface() Index: AllocHistogramTableModel.java =================================================================== RCS file: /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/views/AllocHistogramTableModel.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** AllocHistogramTableModel.java 27 Jul 2002 22:27:03 -0000 1.5 --- AllocHistogramTableModel.java 31 Jul 2002 16:52:37 -0000 1.6 *************** *** 25,32 **** import javax.swing.table.AbstractTableModel; import net.sourceforge.javaprofiler.jpi.*; - import java.lang.reflect.*; - //PENDING remove java.reflection ! /** * * @author Pavel Vacha --- 25,32 ---- import javax.swing.table.AbstractTableModel; import net.sourceforge.javaprofiler.jpi.*; ! /**Model for table that shows instances count and "histogram" of instances count. ! * Columns contains name_of_type, instaces_count, count_of_all_instances_ever_created_in_VM, ! * histogram_of_instances_count, size_of_instances, size_off_all_instances_ever_created_in_VM * * @author Pavel Vacha *************** *** 34,61 **** public class AllocHistogramTableModel extends AbstractTableModel { private List allocStats; ! private String columnNames[] = { "name", "count", "total count", "histogram", "space", "total space" }; private Class columnClasses[] = { String.class, Long.class, Long.class, AllocStat.class, Long.class, Long.class }; ! private AllocStatListener statListener; //private Method method_getName; ! /** Creates a new instance of HistogramTableModel *@param allocStats list of <code> AllocStat </code> objects that have <code> getType() </code> method *@param parent Parent where <code> allosStats </code> list resides. (We need subscribe for changes in this list). ! *@param listType this param is passed as type to <code> parent.addChildrenListener </code> method. Its constant from * <code> net.sourceforge.javaprofiler.jpi.Constants </code> */ ! public AllocHistogramTableModel(List allocStats, HasChildren parent, int type) { this.allocStats = allocStats; statListener = new HistogramStatListener(); ! ListIterator iter = allocStats.listIterator(); ! while ( iter.hasNext() ) { ! ((AllocStat) iter.next()).addAllocStatListener( statListener ); ! } ! ! parent.addChildrenListener( type, new HistogramChildrenListener() ); } public int getColumnCount() { return columnNames.length; --- 34,70 ---- public class AllocHistogramTableModel extends AbstractTableModel { private List allocStats; ! private String columnNames[] = { "name", "count", "total count", "histogram", "space", "total space" }; private Class columnClasses[] = { String.class, Long.class, Long.class, AllocStat.class, Long.class, Long.class }; ! ! private AllocStatListener statListener; ! private ChildrenListener childrenListener; ! ! private int subscribeType; ! private HasChildren parent; //private Method method_getName; ! /** Creates a new instance of HistogramTableModel. When you stop using this model, please call dispose() to ! * allow removing of this instance during gabage collection. *@param allocStats list of <code> AllocStat </code> objects that have <code> getType() </code> method *@param parent Parent where <code> allosStats </code> list resides. (We need subscribe for changes in this list). ! *@param subscribeType this param is passed as type to <code> parent.addChildrenListener </code> method. Its constant from * <code> net.sourceforge.javaprofiler.jpi.Constants </code> */ ! public AllocHistogramTableModel(List allocStats, HasChildren parent, int subscribeType) { this.allocStats = allocStats; statListener = new HistogramStatListener(); + childrenListener = new HistogramChildrenListener(); ! subscribeToJpi( allocStats, parent, subscribeType ); } + /** Call dispose() when you stop using this model. It unsubsribe listeners and therefore + * it allows removing of this instance during gabage collection. + */ + public void dispose() { + unsubscribeFromJpi(); + } + public int getColumnCount() { return columnNames.length; *************** *** 162,167 **** }; } - ! //pending unsubscribing } --- 171,192 ---- }; } ! //subcribing, unsubscribing ! protected void subscribeToJpi( List allocStats, HasChildren parent, int subscribeType ) { ! this.parent = parent; ! this.subscribeType = subscribeType; ! ListIterator iter = allocStats.listIterator(); ! while ( iter.hasNext() ) { ! ((AllocStat) iter.next()).addAllocStatListener( statListener ); ! } ! parent.addChildrenListener( subscribeType, childrenListener ); ! } ! ! protected void unsubscribeFromJpi() { ! parent.removeChildrenListener( subscribeType, childrenListener ); ! ListIterator iter = allocStats.listIterator(); ! while ( iter.hasNext() ) { ! ((AllocStat) iter.next()).removeAllocStatListener( statListener ); ! } ! } } |