← Back to team overview

gnome-split-team team mailing list archive

[Branch ~respawneral/gnome-split/mainline] Rev 231: Speed improvement for IO operations.

 

------------------------------------------------------------
revno: 231
committer: Guillaume Mazoyer <respawneral@xxxxxxxxx>
branch nick: gnome-split
timestamp: Thu 2010-09-09 00:17:00 +0200
message:
  Speed improvement for IO operations.
  
  Change the way to notify the view from the
  progress of an action. Instead of notifying the
  view every write operations, it now uses a
  scheduled task that notify the view every 250 ms.
  After few tests, it seems that the time to split
  and merge files has been divided by 2.
modified:
  configure
  po/gnome-split.pot
  src/org/gnome/split/core/DefaultEngine.java
  src/org/gnome/split/core/merger/DefaultMergeEngine.java
  src/org/gnome/split/core/splitter/DefaultSplitEngine.java
  src/org/gnome/split/gtk/DefaultEngineListener.java


--
lp:gnome-split
https://code.launchpad.net/~respawneral/gnome-split/mainline

Your team GNOME Split developers is subscribed to branch lp:gnome-split.
To unsubscribe from this branch go to https://code.launchpad.net/~respawneral/gnome-split/mainline/+edit-subscription
=== modified file 'configure'
--- configure	2010-06-27 10:10:48 +0000
+++ configure	2010-09-08 22:17:00 +0000
@@ -453,7 +453,7 @@
 } elsif (-f "/etc/redhat-release") {
     output "RedHat";
     $os = "fedora";
-} elsif ( -f "/etc/java/jpackage-release" ) {
+} elsif (-f "/etc/java/jpackage-release") {
     output "JPackage";
     $os = "fedora";
 }

=== modified file 'po/gnome-split.pot'
--- po/gnome-split.pot	2010-08-30 23:42:33 +0000
+++ po/gnome-split.pot	2010-09-08 22:17:00 +0000
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2010-08-31 01:41+0200\n"
+"POT-Creation-Date: 2010-09-08 23:41+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@xxxxxx>\n"
@@ -157,12 +157,12 @@
 "You must specify a size which is lower than the size of the file to split."
 msgstr ""
 
-#: src/org/gnome/split/core/merger/DefaultMergeEngine.java:156
+#: src/org/gnome/split/core/merger/DefaultMergeEngine.java:166
 #, java-format
 msgid "Merging {0}"
 msgstr ""
 
-#: src/org/gnome/split/core/splitter/DefaultSplitEngine.java:96
+#: src/org/gnome/split/core/splitter/DefaultSplitEngine.java:106
 #, java-format
 msgid "Splitting {0}"
 msgstr ""
@@ -171,22 +171,22 @@
 msgid "GNOME Split activity"
 msgstr ""
 
-#: src/org/gnome/split/GnomeSplit.java:108
+#: src/org/gnome/split/GnomeSplit.java:109
 msgid "More than one instance."
 msgstr ""
 
-#: src/org/gnome/split/GnomeSplit.java:109
+#: src/org/gnome/split/GnomeSplit.java:110
 msgid ""
 "Only one instance of GNOME Split can be executed at a time. If you want to "
 "run multiple instances, edit the preferences. Remember that it is never safe "
 "to run more than one instance of GNOME Split."
 msgstr ""
 
-#: src/org/gnome/split/GnomeSplit.java:250
+#: src/org/gnome/split/GnomeSplit.java:276
 msgid "Quit GNOME Split."
 msgstr ""
 
-#: src/org/gnome/split/GnomeSplit.java:251
+#: src/org/gnome/split/GnomeSplit.java:277
 msgid ""
 "An action is currently being perfomed. Do you really want to quit GNOME "
 "Split?"
@@ -516,7 +516,7 @@
 
 #: src/org/gnome/split/gtk/DefaultEngineListener.java:157
 #, java-format
-msgid "Writting {0}."
+msgid "Writing {0}."
 msgstr ""
 
 #: src/org/gnome/split/gtk/DefaultEngineListener.java:168

=== modified file 'src/org/gnome/split/core/DefaultEngine.java'
--- src/org/gnome/split/core/DefaultEngine.java	2010-08-28 20:14:10 +0000
+++ src/org/gnome/split/core/DefaultEngine.java	2010-09-08 22:17:00 +0000
@@ -168,7 +168,7 @@
     }
 
     /**
-     * A class which calculate the speed of the action.
+     * A class that calculate the speed of the action.
      * 
      * @author Guillaume Mazoyer
      */

=== modified file 'src/org/gnome/split/core/merger/DefaultMergeEngine.java'
--- src/org/gnome/split/core/merger/DefaultMergeEngine.java	2010-08-28 20:14:10 +0000
+++ src/org/gnome/split/core/merger/DefaultMergeEngine.java	2010-09-08 22:17:00 +0000
@@ -25,6 +25,8 @@
 import java.io.RandomAccessFile;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
 
 import org.gnome.split.core.DefaultEngine;
 import org.gnome.split.core.Engine;
@@ -71,6 +73,11 @@
     protected String md5sum;
 
     /**
+     * A timer to update the progress of the view.
+     */
+    private Timer progress;
+
+    /**
      * Create a new merge {@link Engine engine} using a first
      * <code>file</code> to merge.
      */
@@ -78,6 +85,7 @@
         super(app);
         this.file = file;
         this.filename = filename;
+        this.progress = null;
 
         if (filename != null) {
             this.directory = filename.substring(0, filename.lastIndexOf(File.separator));
@@ -134,7 +142,8 @@
     @Override
     public void run() {
         synchronized (mutex) {
-            // Start the speed calculator
+            // Start the indicators
+            this.startProgressUpdater();
             this.startSpeedCalculator();
 
             try {
@@ -144,7 +153,8 @@
                 // Handle the error
                 this.fireEngineError(new EngineException(e));
             } finally {
-                // Stop the speed calculator
+                // Stop the indicators
+                this.stopProgressUpdater();
                 this.stopSpeedCalculator();
             }
         }
@@ -192,6 +202,27 @@
     public abstract void merge() throws IOException;
 
     /**
+     * Start the progress updater which should notify the view from the
+     * progress of the action.
+     */
+    private void startProgressUpdater() {
+        // Create a new timer and start its task
+        progress = new Timer("Progress updater");
+        progress.scheduleAtFixedRate(new ProgressUpdaterTask(), 1, 250);
+    }
+
+    /**
+     * Stop the progress updater.
+     */
+    private void stopProgressUpdater() {
+        // Stop the timer
+        if (progress != null) {
+            progress.cancel();
+            progress = null;
+        }
+    }
+
+    /**
      * Notify the view that a part is being read.
      */
     protected void fireEnginePartRead(String filename) {
@@ -202,6 +233,7 @@
      * Notify the view that the MD5 sum calculation has started.
      */
     protected void fireMD5SumStarted() {
+        this.stopProgressUpdater();
         app.getEngineListener().engineMD5SumStarted();
     }
 
@@ -209,6 +241,7 @@
      * Notify the view that the MD5 sum calculation has ended.
      */
     protected void fireMD5SumEnded() {
+        this.startProgressUpdater();
         app.getEngineListener().engineMD5SumEnded();
     }
 
@@ -283,9 +316,6 @@
             // Update read and write status
             read += buffer.length;
             total += buffer.length;
-
-            // Notify the view
-            this.fireEngineDone(total, fileLength);
         }
 
         // Success
@@ -306,4 +336,21 @@
     public boolean useMD5() {
         return md5;
     }
+
+    /**
+     * A class that notify the view from the progress of the action.
+     * 
+     * @author Guillaume Mazoyer
+     */
+    private class ProgressUpdaterTask extends TimerTask
+    {
+        private ProgressUpdaterTask() {
+
+        }
+
+        @Override
+        public void run() {
+            fireEngineDone(total, fileLength);
+        }
+    }
 }

=== modified file 'src/org/gnome/split/core/splitter/DefaultSplitEngine.java'
--- src/org/gnome/split/core/splitter/DefaultSplitEngine.java	2010-08-28 20:14:10 +0000
+++ src/org/gnome/split/core/splitter/DefaultSplitEngine.java	2010-09-08 22:17:00 +0000
@@ -23,6 +23,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.RandomAccessFile;
+import java.util.Timer;
+import java.util.TimerTask;
 
 import org.gnome.split.GnomeSplit;
 import org.gnome.split.core.DefaultEngine;
@@ -55,6 +57,11 @@
     protected String destination;
 
     /**
+     * A timer to update the progress of the view.
+     */
+    private Timer progress;
+
+    /**
      * Create a new split {@link Engine engine} using a <code>file</code> to
      * split and a maximum <code>size</code> for each chunk.
      */
@@ -64,6 +71,7 @@
         this.file = file;
         this.size = size;
         this.destination = destination;
+        this.progress = null;
     }
 
     @Override
@@ -75,7 +83,8 @@
                 return;
             }
 
-            // Start the speed calculator
+            // Start the indicators
+            this.startProgressUpdater();
             this.startSpeedCalculator();
 
             try {
@@ -85,7 +94,8 @@
                 // Handle the error
                 this.fireEngineError(new EngineException(e));
             } finally {
-                // Stop the speed calculator
+                // Stop the indicators
+                this.stopProgressUpdater();
                 this.stopSpeedCalculator();
             }
         }
@@ -129,6 +139,27 @@
     public abstract void split() throws IOException;
 
     /**
+     * Start the progress updater which should notify the view from the
+     * progress of the action.
+     */
+    private void startProgressUpdater() {
+        // Create a new timer and start its task
+        progress = new Timer("Progress updater");
+        progress.scheduleAtFixedRate(new ProgressUpdaterTask(), 1, 250);
+    }
+
+    /**
+     * Stop the progress updater.
+     */
+    private void stopProgressUpdater() {
+        // Stop the timer
+        if (progress != null) {
+            progress.cancel();
+            progress = null;
+        }
+    }
+
+    /**
      * Notify the view that a part has been created.
      */
     protected void fireEnginePartCreated(String filename) {
@@ -146,6 +177,7 @@
      * Notify the view that the MD5 sum calculation has started.
      */
     protected void fireMD5SumStarted() {
+        this.stopProgressUpdater();
         app.getEngineListener().engineMD5SumStarted();
     }
 
@@ -153,6 +185,7 @@
      * Notify the view that the MD5 sum calculation has ended.
      */
     protected void fireMD5SumEnded() {
+        this.startProgressUpdater();
         app.getEngineListener().engineMD5SumEnded();
     }
 
@@ -221,12 +254,26 @@
             // Update read and write status
             read += buffer.length;
             total += buffer.length;
-
-            // Notify the view
-            this.fireEngineDone(total, file.length());
         }
 
         // Success
         return true;
     }
+
+    /**
+     * A class that notify the view from the progress of the action.
+     * 
+     * @author Guillaume Mazoyer
+     */
+    private class ProgressUpdaterTask extends TimerTask
+    {
+        private ProgressUpdaterTask() {
+
+        }
+
+        @Override
+        public void run() {
+            fireEngineDone(total, file.length());
+        }
+    }
 }

=== modified file 'src/org/gnome/split/gtk/DefaultEngineListener.java'
--- src/org/gnome/split/gtk/DefaultEngineListener.java	2010-08-30 23:42:33 +0000
+++ src/org/gnome/split/gtk/DefaultEngineListener.java	2010-09-08 22:17:00 +0000
@@ -154,7 +154,7 @@
     @Override
     public void enginePartCreated(String filename) {
         // Update the status widget
-        gtk.getStatusWidget().updateText(_("Writting {0}.", filename));
+        gtk.getStatusWidget().updateText(_("Writing {0}.", filename));
     }
 
     @Override