KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > backup > phase > UndoRestorePhases


1 /*
2  * BackupPhases.java
3  *
4  * Created on December 24, 2003, 10:07 AM
5  */

6
7 package com.sun.enterprise.config.backup.phase;
8
9 import com.sun.enterprise.config.backup.status.UndoRestoreStatus;
10 import com.sun.enterprise.config.backup.status.Status;
11 import com.sun.enterprise.config.backup.status.StatusConstants;
12 import com.sun.enterprise.config.backup.StatusRegistry;
13 import com.sun.enterprise.config.backup.utils.LocalStringsHelper;
14 import com.sun.enterprise.config.backup.utils.LoggerHelper;
15 import com.sun.enterprise.config.backup.pluggable.BackupStorage;
16 import com.sun.enterprise.config.backup.BackupAbortException;
17 import com.sun.enterprise.config.backup.BackupException;
18 import com.sun.enterprise.config.backup.utils.BackupHelper;
19 import com.sun.enterprise.config.backup.utils.FactoryHelper;
20 import java.io.File JavaDoc;
21
22 /**
23  *
24  * @author sridatta
25  */

26 public class UndoRestorePhases extends PhasesBase {
27     
28     /** Creates a new instance of BackupPhases */
29     public UndoRestorePhases() {
30     }
31     
32     public void assertStatusNotNull(UndoRestoreStatus rs) {
33         if(rs == null) {
34             LoggerHelper.info("null_status_in_restore");
35             //should never happen
36
UndoRestoreStatus rs1 = new UndoRestoreStatus();
37             Exception JavaDoc e = new BackupException(
38                 "error_invoking_restore",
39                 LocalStringsHelper.getString("error_invoking_restore"));
40             BackupHelper.setExceptionInStatus(rs1, e);
41             setStatusInRegistry(rs1);
42             throw new BackupAbortException(
43                 "restore_status_null",
44                 LocalStringsHelper.getString("restore_status_null"));
45         }
46     }
47     
48     public UndoRestoreStatus getStatus() {
49         return (UndoRestoreStatus)getStatusFromRegistry();
50     }
51     
52     /*
53     public void monitorBackupDir() {
54         try {
55             FactoryHelper.getMaxBackupMonitor().run();
56         } catch(Exception e) {
57             //log it
58             LoggerHelper.warning("error_monitoring_backup_dir");
59             LoggerHelper.fine("error_monitoring_backup_dir", e);
60         }
61     }
62     
63      */

64     
65     //restore methods
66

67     /**
68      * history is not maintained for snapshots. It is done internally
69      * through the system
70      */

71     /*
72     public void takeSnapShot() {
73         try {
74             String absSnapShotFileName = BackupHelper.getAbsoluteSnapshotFileName();
75             SnapShotStatus ss = new SnapShotStatus(true);
76             long size = backup(absSnapShotFileName, ss);
77             ss.setStatusCode(StatusConstants.STATUS_SUCCESS);
78             LoggerHelper.fine("snapshot info= " + ss);
79             FactoryHelper.getMaxSnapShotMonitor().run();
80         } catch(Exception e1) {
81             LoggerHelper.info("ignore_error_taking_snapshot ", e1);
82         }
83     }
84     
85     private long backup(String absSnapShotFileName, SnapShotStatus ss) throws Exception {
86         String[] srcDirs = ss.getDirectoriesToBackup();
87               LoggerHelper.fine("Source Directory for snapshot is "
88                                 + BackupHelper.ArrayToString(srcDirs));
89              
90               String absTargetFile = ss.getAbsoluteBackupFileName();
91               //get the correct storage class
92               BackupStorage backupStorage = FactoryHelper.getStorage();
93               return backupStorage.backup(srcDirs, absTargetFile);
94     }
95     
96      */

97     public void performUndoRestore(File JavaDoc f, UndoRestoreStatus rs) {
98         try {
99             FactoryHelper.getStorage().restore(f);
100             rs.setStatusCode(StatusConstants.STATUS_SUCCESS);
101         } catch(Exception JavaDoc e){
102             LoggerHelper.error("error_performing_undo_restore", e);
103             //FIXME> why is it not thrown. BUG. THrOW
104
}
105     }
106     
107     /**
108      * liquidate the target directories. note that
109      * a snapshot is already taken
110      */

111     public void deleteTarget() {
112         //FIXME NYI
113
}
114 }
115
Popular Tags