User: juhalindfors
  Date: 01/04/22 06:01:28

  Modified:    src/org/jboss/admin/monitor/graph DefaultGraphModel.java
  Log:
  Using BoundBuffer instead of ArrayList.
  append() should now be thread safe.
  
  Revision  Changes    Path
  1.4       +23 -15    admin/src/org/jboss/admin/monitor/graph/DefaultGraphModel.java
  
  Index: DefaultGraphModel.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/admin/src/org/jboss/admin/monitor/graph/DefaultGraphModel.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultGraphModel.java    2001/04/16 21:55:20     1.3
  +++ DefaultGraphModel.java    2001/04/22 13:01:28     1.4
  @@ -3,18 +3,20 @@
   // standard imports
   import java.awt.Point;
   import java.util.ArrayList;
  +import java.util.Arrays;
   import java.util.List;
   import java.util.Collection;
   import java.util.Collections;
   
  +import javax.swing.SwingUtilities;
   import javax.swing.event.EventListenerList;
   
   // non-standard class dependencies
   import org.jboss.admin.monitor.event.GraphModelListener;
   import org.jboss.admin.monitor.event.GraphModelEvent;
  +import org.gjt.lindfors.util.BoundBuffer;
   
   
  -
   /**
    *
    *
  @@ -22,16 +24,12 @@
    */
   public class DefaultGraphModel implements GraphModel {
   
  -    
  -    protected Collection xAxis = Collections.synchronizedList(new ArrayList());
  -    
  +    protected Collection xAxis = Collections.synchronizedCollection(new 
BoundBuffer(1000));
       protected EventListenerList listenerList = new EventListenerList();
       
       protected double max = 1.0;
       protected double min = 0.0;
       
  -    /* lazy create */
  -// hmm?    protected GraphModelEvent graphModelEvent = null;
       
   /*
    *************************************************************************
  @@ -89,22 +87,36 @@
    */
    
       /*
  -     * append is synchronized
  +     * append is thread safe
        * will automatically set max
        */
       public void append(Number number) {
  +        
           xAxis.add(number);        
  -        double value = number.doubleValue();
  +        final double value = number.doubleValue();
  +
  +        if (!SwingUtilities.isEventDispatchThread()) {
  +            SwingUtilities.invokeLater(new Runnable() {
  +                public void run() {
  +                    append(value);
  +                }
  +            });
  +        }
  +        else
  +            append(value);
  +    }
           
  +    private void append(double value) {        
           if (value  > getVerticalMax())
               setVerticalMax(value);
               
           fireValueAppended(value);
       }
       
  +    /*
  +     */
       public Collection getPlotPoints() {
           Object[] points = xAxis.toArray();
  -        
           ArrayList plots = new ArrayList();
           
           for (int i = 0; i < points.length; ++i)
  @@ -131,9 +143,7 @@
    
       /*
        * Notify all listeners that have registered interest for
  -     * notification on this event type.  The event instance 
  -     * is lazily created using the parameters passed into 
  -     * the fire method.
  +     * notification on this event type.
        */
       protected void fireValueAppended(double value) {
           // Guaranteed to return a non-null array
  @@ -154,9 +164,7 @@
   
       /*
        * Notify all listeners that have registered interest for
  -     * notification on this event type.  The event instance 
  -     * is lazily created using the parameters passed into 
  -     * the fire method.
  +     * notification on this event type.
        */
       protected void fireLimitChanged(double value, int target) {
           // Guaranteed to return a non-null array
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to