All pastes #898009 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-10 00:17 UTC
rendered paste body
Index: /home/ijuma/workspaces/rssowl2/org.rssowl.core/src/org/rssowl/core/internal/persist/service/DBManager.java
===================================================================
--- /home/ijuma/workspaces/rssowl2/org.rssowl.core/src/org/rssowl/core/internal/persist/service/DBManager.java	(revision 5037)
+++ /home/ijuma/workspaces/rssowl2/org.rssowl.core/src/org/rssowl/core/internal/persist/service/DBManager.java	(working copy)
@@ -28,6 +28,7 @@
 import org.eclipse.core.runtime.SafeRunner;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.core.runtime.internal.stats.StatsManager;
 import org.eclipse.core.runtime.jobs.Job;
 import org.rssowl.core.internal.Activator;
 import org.rssowl.core.internal.InternalOwl;
@@ -101,10 +102,12 @@
    * contributed DataBase.
    */
   public void startup(LongOperationMonitor monitor) throws PersistenceException {
+    long time = System.currentTimeMillis();
     /* Initialise */
     EventManager.getInstance();
 
     createDatabase(monitor);
+    System.out.println("Time to start-up: " + (System.currentTimeMillis() - time));
   }
 
   public void addEntityStoreListener(DatabaseListener listener) {
@@ -130,12 +133,23 @@
   }
 
   private ObjectContainer createObjectContainer(Configuration config) {
-    BackupService backupService = createOnlineBackupService();
-    if (backupService != null)
-      backupService.backup(true);
-
+    final BackupService backupService = createOnlineBackupService();
     try {
+      long time = System.currentTimeMillis();
       fObjectContainer = Db4o.openFile(config, getDBFilePath());
+      System.out.println("Time to open container: " + (System.currentTimeMillis() - time));
+
+      if (backupService != null) {
+        new Job("") {
+          @Override
+          protected IStatus run(IProgressMonitor monitor) {
+            long time = System.currentTimeMillis();
+            backupService.backup(true);
+            System.out.println("Time to create backup service: " + (System.currentTimeMillis() - time));
+            return Status.OK_STATUS;
+          }
+        }.schedule(25000);
+      }
     } catch (Exception e) {
       if (backupService == null || e instanceof DatabaseFileLockedException)
         throw new PersistenceException(e);
@@ -172,6 +186,16 @@
       return null;
 
     BackupService backupService = new BackupService(file, ".onlinebak", 2);
+    backupService.setBackupStrategy(new BackupService.BackupStrategy() {
+      public void backup(File originFile, File destinationFile) {
+        try {
+          /* Relies on fObjectContainer being set before calling backup */
+          fObjectContainer.ext().backup(destinationFile.getAbsolutePath());
+        } catch (IOException e) {
+          throw new PersistenceException(e);
+        }
+      }
+    });
     return backupService;
   }
 
Index: /home/ijuma/workspaces/rssowl2/org.rssowl.core/src/org/rssowl/core/internal/persist/service/DBHelper.java
===================================================================
--- /home/ijuma/workspaces/rssowl2/org.rssowl.core/src/org/rssowl/core/internal/persist/service/DBHelper.java	(revision 5037)
+++ /home/ijuma/workspaces/rssowl2/org.rssowl.core/src/org/rssowl/core/internal/persist/service/DBHelper.java	(working copy)
@@ -123,6 +123,7 @@
     FileInputStream inputStream = null;
     FileOutputStream outputStream = null;
     try {
+      long time = System.currentTimeMillis();
       inputStream = new FileInputStream(originFile);
       FileChannel srcChannel = inputStream.getChannel();
 
@@ -131,7 +132,9 @@
 
       outputStream = new FileOutputStream(destinationFile);
       FileChannel dstChannel = outputStream.getChannel();
+      System.out.println("Time to open channels: " + (System.currentTimeMillis() - time));
 
+      time = System.currentTimeMillis();
       long bytesToTransfer = srcChannel.size();
       long position = 0;
       while (bytesToTransfer > 0) {
@@ -139,12 +142,14 @@
         position += bytesTransferred;
         bytesToTransfer -= bytesTransferred;
       }
-
+      System.out.println("Time to copy file: " + (System.currentTimeMillis() - time));
     } catch (IOException e) {
       throw new PersistenceException(e);
     } finally {
+      long time = System.currentTimeMillis();
       closeQuietly(inputStream);
       closeQuietly(outputStream);
+      System.out.println("Time to close file: " + (System.currentTimeMillis() - time));
     }
   }
 
Index: /home/ijuma/workspaces/rssowl2/org.rssowl.core/src/org/rssowl/core/internal/persist/service/BackupService.java
===================================================================
--- /home/ijuma/workspaces/rssowl2/org.rssowl.core/src/org/rssowl/core/internal/persist/service/BackupService.java	(revision 5037)
+++ /home/ijuma/workspaces/rssowl2/org.rssowl.core/src/org/rssowl/core/internal/persist/service/BackupService.java	(working copy)
@@ -33,6 +33,10 @@
 
 public final class BackupService {
 
+  interface BackupStrategy    {
+    void backup(File originFile, File destinationFile);
+  }
+
   interface BackupLayoutStrategy    {
     List<File> findBackupFiles();
 
@@ -92,6 +96,7 @@
 
   private BackupLayoutStrategy fLayoutStrategy;
   private File fFileToBackupAlias;
+  private BackupStrategy fBackupStrategy;
 
   public BackupService(File fileToBackup, String backupFileSuffix, int maxBackupsCount) {
     this(fileToBackup, backupFileSuffix, maxBackupsCount, null, null);
@@ -113,8 +118,17 @@
     fBackupFrequency = backupFrequency;
 
     fLayoutStrategy = new DefaultBackupLayoutStrategy(getBackupFile());
+    fBackupStrategy = new BackupStrategy() {
+      public void backup(File originFile, File destinationFile) {
+        DBHelper.copyFile(originFile, destinationFile);
+      }
+    };
   }
 
+  public void setBackupStrategy(BackupStrategy backupStrategy) {
+    fBackupStrategy = backupStrategy;
+  }
+
   /**
    * This overrides where the back-up is made from. It's useful if fileToBackup
    * is being used, there's a copy available and the back-up file name should
@@ -165,14 +179,18 @@
     if (!shouldBackup(force))
       return false;
 
+    long time = System.currentTimeMillis();
     prepareBackup();
+    System.out.println("Time to prepare backup: " + (System.currentTimeMillis() - time));
 
     File sourceFile = fFileToBackup;
     if (fFileToBackupAlias != null)
       sourceFile = fFileToBackupAlias;
 
-    DBHelper.copyFile(sourceFile, getBackupFile());
+    fBackupStrategy.backup(sourceFile, getBackupFile());
+    time = System.currentTimeMillis();
     writeBackupTimestamp();
+    System.out.println("Time to write backup timestamp: " + (System.currentTimeMillis() - time));
     return true;
   }