directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r670090 - in /directory/studio/trunk: connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreparationTest.java
Date Fri, 20 Jun 2008 22:52:46 GMT
Author: seelmann
Date: Fri Jun 20 15:52:45 2008
New Revision: 670090

URL: http://svn.apache.org/viewvc?rev=670090&view=rev
Log:
Fix for DIRSTUDIO-319: Starting only one job for reporting progress and checking for cancellation,
reduces amount of started threads.

Modified:
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java
    directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreparationTest.java

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java?rev=670090&r1=670089&r2=670090&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java
(original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/StudioProgressMonitor.java
Fri Jun 20 15:52:45 2008
@@ -43,16 +43,75 @@
 public class StudioProgressMonitor extends ProgressMonitorWrapper
 {
 
+    /** The job reports progress and checks for cancellation. */
+    private static Job reportProgressAndCheckCancellationJob = new Job(
+        Messages.jobs__progressmonitor_check_cancellation )
+    {
+        protected IStatus run( IProgressMonitor monitor )
+        {
+            while ( true )
+            {
+                for ( Iterator<StudioProgressMonitor> it = monitors.iterator(); it.hasNext();
)
+                {
+                    StudioProgressMonitor spm = it.next();
+
+                    do
+                    {
+                        // check report progress message
+                        if ( !spm.done && spm.reportProgressMessage != null )
+                        {
+                            spm.subTask( spm.reportProgressMessage );
+                            spm.reportProgressMessage = null;
+                        }
+
+                        // check if canceled
+                        if ( spm.isCanceled() )
+                        {
+                            spm.fireCancelRequested();
+                            it.remove();
+                        }
+                        if ( spm.isCanceled() || spm.done )
+                        {
+                            it.remove();
+                        }
+
+                        if ( spm.getWrappedProgressMonitor() != null
+                            && spm.getWrappedProgressMonitor() instanceof StudioProgressMonitor
)
+                        {
+                            spm = ( StudioProgressMonitor ) spm.getWrappedProgressMonitor();
+                        }
+                        else
+                        {
+                            spm = null;
+                        }
+                    }
+                    while ( spm != null );
+                }
+
+                try
+                {
+                    Thread.sleep( 1000 );
+                }
+                catch ( InterruptedException e )
+                {
+                }
+            }
+        }
+    };
+    static
+    {
+        reportProgressAndCheckCancellationJob.setSystem( true );
+        reportProgressAndCheckCancellationJob.schedule();
+    }
+
+    private static List<StudioProgressMonitor> monitors = new ArrayList<StudioProgressMonitor>();
+
     private boolean done;
 
     private List<Status> errorStatusList;
 
     private List<CancelListener> cancelListenerList;
 
-    private Job checkCanceledJob;
-
-    private Job reportProgressJob = null;
-
     private String reportProgressMessage = null;
 
 
@@ -65,34 +124,7 @@
     {
         super( monitor );
         this.done = false;
-
-        this.checkCanceledJob = new Job( Messages.jobs__progressmonitor_check_cancellation
)
-        {
-            protected IStatus run( IProgressMonitor monitor )
-            {
-                while ( !done )
-                {
-                    if ( isCanceled() )
-                    {
-                        fireCancelRequested();
-                        break;
-                    }
-                    else
-                    {
-                        try
-                        {
-                            Thread.sleep( 1000 );
-                        }
-                        catch ( InterruptedException e )
-                        {
-                        }
-                    }
-                }
-                return Status.OK_STATUS;
-            }
-        };
-        this.checkCanceledJob.setSystem( true );
-        this.checkCanceledJob.schedule();
+        monitors.add( this );
     }
 
 
@@ -175,33 +207,7 @@
      */
     public void reportProgress( String message )
     {
-        synchronized ( this )
-        {
-            if ( !done )
-            {
-                if ( reportProgressJob == null )
-                {
-                    reportProgressJob = new Job( Messages.jobs__progressmonitor_report_progress
)
-                    {
-                        protected IStatus run( IProgressMonitor monitor )
-                        {
-                            synchronized ( StudioProgressMonitor.this )
-                            {
-                                if ( !done )
-                                {
-                                    subTask( reportProgressMessage );
-                                }
-                                return Status.OK_STATUS;
-                            }
-                        }
-                    };
-                    reportProgressJob.setSystem( true );
-                }
-
-                reportProgressMessage = message;
-                reportProgressJob.schedule( 1000 );
-            }
-        }
+        reportProgressMessage = message;
     }
 
 
@@ -330,8 +336,8 @@
         }
         return null;
     }
-    
-    
+
+
     /**
      * Resets this status.
      */

Modified: directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreparationTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreparationTest.java?rev=670090&r1=670089&r2=670090&view=diff
==============================================================================
--- directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreparationTest.java
(original)
+++ directory/studio/trunk/test-integration-ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreparationTest.java
Fri Jun 20 15:52:45 2008
@@ -21,10 +21,9 @@
 package org.apache.directory.studio.test.integration.ui;
 
 
+import junit.framework.TestCase;
 import net.sf.swtbot.eclipse.finder.SWTEclipseBot;
 
-import org.apache.directory.server.unit.AbstractServerTest;
-
 
 /**
  * Test preparation.
@@ -32,7 +31,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class PreparationTest extends AbstractServerTest
+public class PreparationTest extends TestCase
 {
 
     /**



Mime
View raw message