KickJava   Java API By Example, From Geeks To Geeks.

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


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.RestoreStatus;
10 import com.sun.enterprise.config.backup.status.SnapShotStatus;
11 import com.sun.enterprise.config.backup.status.Status;
12 import com.sun.enterprise.config.backup.status.StatusConstants;
13 import com.sun.enterprise.config.backup.StatusRegistry;
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 com.sun.enterprise.config.backup.utils.LocalStringsHelper;
21 import java.io.File JavaDoc;
22 import java.io.IOException JavaDoc;
23
24 /**
25  *
26  * @author sridatta
27  */

28 public class RestorePhases extends PhasesBase {
29     
30     /** Creates a new instance of BackupPhases */
31     public RestorePhases() {
32     }
33     
34    /* public void assertStatusNotFailed(BackupStatus bs) {
35         assertNotNull(bs);
36         assertNotFailed(bs);
37     }
38     */

39     
40     public void assertStatusNotNull(RestoreStatus rs) {
41         if(rs == null) {
42             LoggerHelper.info("null_status_in_restore");
43             //should never happen
44
RestoreStatus rs1 = new RestoreStatus();
45             setStatusInRegistry(rs1);
46             
47             throw new BackupAbortException(
48                 "error_invoking_restore",
49                 LocalStringsHelper.getString("error_invoking_restore"));
50         }
51     }
52     
53     public RestoreStatus getStatus() {
54         return (RestoreStatus)getStatusFromRegistry();
55     }
56     
57     public void monitorBackupDir() {
58         try {
59             FactoryHelper.getBackupStorageMonitor().run();
60         } catch(Exception JavaDoc e) {
61             //log it
62
LoggerHelper.warning("error_monitoring_backup_dir");
63             LoggerHelper.fine("error_monitoring_backup_dir", e);
64         }
65     }
66     
67     /*
68     
69     public void setBackupFileSize(long size) {
70           getStatus().setBackupFileSize(size);
71     }
72     
73      */

74     //restore methods
75

76     /**
77      * history is not maintained for snapshots. It is done internally
78      * through the system
79      */

80     public void takeSnapShot() {
81         try {
82            // String absSnapShotFileName = BackupHelper.getAbsoluteSnapshotFileName();
83
SnapShotStatus ss = new SnapShotStatus(true);
84             long size = backup(ss.getAbsoluteSnapShotFileName(), ss);
85             ss.setStatusCode(StatusConstants.STATUS_SUCCESS);
86             LoggerHelper.fine("snapshot info= " + ss);
87             FactoryHelper.getSnapShotStorageMonitor().run();
88         } catch(Exception JavaDoc e1) {
89             LoggerHelper.info("ignore_error_taking_snapshot ", e1);
90         }
91     }
92     
93     private long backup(String JavaDoc absSnapShotFileName, SnapShotStatus ss) throws Exception JavaDoc {
94         String JavaDoc[] srcDirs = ss.getDirectoriesToBackup();
95               LoggerHelper.fine("Source Directory for snapshot is "
96                                 + BackupHelper.ArrayToString(srcDirs));
97              
98               //get the correct storage class
99
BackupStorage backupStorage = FactoryHelper.getStorage();
100               return backupStorage.backup(srcDirs, absSnapShotFileName);
101     }
102     
103     public void performRestore(File JavaDoc f) throws Exception JavaDoc {
104             FactoryHelper.getStorage().restore(f);
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
FactoryHelper.getStorage().deleteTarget();
114     }
115 }
116
Popular Tags