src/org/objectweb/cjdbc/controller/backup/BackupManager.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.controller.backup; 00026 00027 import java.io.File; 00028 import java.io.FilenameFilter; 00029 import java.util.ArrayList; 00030 import java.util.Hashtable; 00031 00032 import org.objectweb.cjdbc.common.exceptions.BackupException; 00033 import org.objectweb.cjdbc.common.exceptions.OctopusException; 00034 import org.objectweb.cjdbc.common.i18n.Translate; 00035 import org.objectweb.cjdbc.common.log.Trace; 00036 import org.objectweb.cjdbc.common.shared.BackupListener; 00037 import org.objectweb.cjdbc.common.util.ZipMe; 00038 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 00039 import org.objectweb.cjdbc.common.xml.XmlComponent; 00040 import org.objectweb.cjdbc.controller.backend.DatabaseBackend; 00041 import org.objectweb.cjdbc.controller.core.ControllerConstants; 00042 00049 public class BackupManager implements XmlComponent 00050 { 00051 static Trace logger = Trace.getLogger(BackupManager.class 00052 .getName()); 00053 private String backupDir = ControllerConstants.DEFAULT_BACKUP_DIR; 00054 private boolean cleanBackupFiles = true; 00055 private boolean zipBackupFiles = true; 00056 private int numberOfBackups = -1; 00057 00058 private Hashtable threads; 00059 00068 public BackupManager(String backupDir, boolean cleanBackupFiles, 00069 boolean zipBackupFiles, int numberOfBackups) 00070 { 00071 this(); 00072 this.backupDir = backupDir; 00073 this.cleanBackupFiles = cleanBackupFiles; 00074 this.zipBackupFiles = zipBackupFiles; 00075 this.numberOfBackups = numberOfBackups; 00076 00077 } 00078 00082 public BackupManager() 00083 { 00084 threads = new Hashtable(); 00085 } 00086 00096 public void backup(DatabaseBackend backend, String checkpoint, 00097 ArrayList tables,BackupListener listener) throws BackupException 00098 { 00099 logger.info(Translate.get("backup.manager.backuping.backend", new String[]{ 00100 backend.getName(), checkpoint})); 00101 Octopus octopus = new Octopus(backend, checkpoint, tables); 00102 octopus.setZipOctopus(zipBackupFiles); 00103 octopus.setCleanOctopus(cleanBackupFiles); 00104 octopus.setOctopusMode(true); 00105 if(listener!=null) 00106 octopus.setListener(listener); 00107 threads.put(backend, octopus); 00108 octopus.start(); 00109 } 00110 00119 public synchronized void getResult(DatabaseBackend backend, long waitTime) 00120 throws BackupException, OctopusException 00121 { 00122 logger.info(Translate.get("backup.manager.waiting.backend.result", 00123 new String[]{backend.getName(), "" + (waitTime / 1000)})); 00124 Octopus backup = (Octopus) threads.get(backend); 00125 try 00126 { 00127 backup.join(waitTime); 00128 } 00129 catch (InterruptedException e) 00130 { 00131 logger.error("Interrupted while joining on backend:"+backend.getName(),e); 00132 } 00133 Exception e = backup.getRunException(); 00134 if (e != null) 00135 { 00136 if (e instanceof BackupException) 00137 throw (BackupException) e; 00138 else if (e instanceof OctopusException) 00139 throw (OctopusException) e; 00140 } 00141 00142 } 00143 00153 public void restore(DatabaseBackend backend, String checkpoint, 00154 ArrayList tables,BackupListener listener) throws BackupException 00155 { 00156 logger.info(Translate.get("backup.manager.restoring.backend", new String[]{ 00157 backend.getName(), checkpoint})); 00158 Octopus octopus = new Octopus(backend, checkpoint, tables); 00159 octopus.setZipOctopus(zipBackupFiles); 00160 octopus.setCleanOctopus(cleanBackupFiles); 00161 if(listener!=null) 00162 octopus.setListener(listener); 00163 octopus.setOctopusMode(false); 00164 threads.put(backend, octopus); 00165 octopus.start(); 00166 } 00167 00174 public File[] listAvailableDumpFiles() 00175 { 00176 File f = new File(backupDir); 00177 if (f.exists()) 00178 { 00179 return f.listFiles(new FilenameFilter() 00180 { 00184 public boolean accept(File dir, String name) 00185 { 00186 if (name.endsWith(ZipMe.ZIP_EXT)) 00187 return true; 00188 else 00189 return false; 00190 } 00191 }); 00192 } 00193 else 00194 return new File[0]; 00195 } 00196 00202 public String getBackupDir() 00203 { 00204 return backupDir; 00205 } 00206 00212 public void setBackupDir(String backupDir) 00213 { 00214 this.backupDir = backupDir; 00215 } 00216 00222 public boolean isCleanBackupFiles() 00223 { 00224 return cleanBackupFiles; 00225 } 00226 00232 public void setCleanBackupFiles(boolean cleanBackupFiles) 00233 { 00234 this.cleanBackupFiles = cleanBackupFiles; 00235 } 00236 00242 public int getNumberOfBackups() 00243 { 00244 return numberOfBackups; 00245 } 00246 00252 public void setNumberOfBackups(int numberOfBackups) 00253 { 00254 this.numberOfBackups = numberOfBackups; 00255 } 00256 00262 public boolean isZipBackupFiles() 00263 { 00264 return zipBackupFiles; 00265 } 00266 00272 public void setZipBackupFiles(boolean zipBackupFiles) 00273 { 00274 this.zipBackupFiles = zipBackupFiles; 00275 } 00276 00280 public String getXml() 00281 { 00282 return "<" + DatabasesXmlTags.ELT_BACKUP + " " 00283 + DatabasesXmlTags.ATT_BACKUP_DIR + "=\"" + backupDir + "\" " 00284 + DatabasesXmlTags.ATT_BACKUP_CLEAN + "=\"" + cleanBackupFiles + "\" " 00285 + DatabasesXmlTags.ATT_BACKUP_ZIP + "=\"" + zipBackupFiles + "\" " 00286 + "/>"; 00287 } 00288 }

CJDBCversion1.0.4に対してTue Oct 12 15:16:00 2004に生成されました。 doxygen 1.3.8