| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package mnemosyne.archiver; |
| 17 |
|
|
| 18 |
|
import mnemosyne.core.PersistentRoot; |
| 19 |
|
import org.apache.commons.logging.Log; |
| 20 |
|
import org.apache.commons.logging.LogFactory; |
| 21 |
|
|
| 22 |
|
import java.io.*; |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
public class SnapshotDirectory extends ArchiveDirectory |
| 28 |
|
{ |
| 29 |
4 |
private static final Log log = LogFactory.getLog(SnapshotDirectory.class); |
| 30 |
|
|
| 31 |
|
private static final String SNAPSHOT_FILE_PREFIX = ""; |
| 32 |
|
private static final String SNAPSHOT_FILE_POSTFIX = "_snapshot"; |
| 33 |
|
private static final String SNAPSHOT_FILE_EXTENSION = "snp"; |
| 34 |
|
|
| 35 |
|
public SnapshotDirectory(String directoryName, ArchiveSequence sequence) |
| 36 |
|
{ |
| 37 |
7 |
super(directoryName, sequence); |
| 38 |
7 |
} |
| 39 |
|
|
| 40 |
|
protected String prefix() |
| 41 |
|
{ |
| 42 |
22 |
return SNAPSHOT_FILE_PREFIX; |
| 43 |
|
} |
| 44 |
|
|
| 45 |
|
protected String postfix() |
| 46 |
|
{ |
| 47 |
22 |
return SNAPSHOT_FILE_POSTFIX; |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
protected String extension() |
| 51 |
|
{ |
| 52 |
15 |
return SNAPSHOT_FILE_EXTENSION; |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
public long getLatestSnapshotSequenceNumber() |
| 56 |
|
{ |
| 57 |
5 |
if (archiveFiles.isEmpty()) |
| 58 |
|
{ |
| 59 |
1 |
return -1; |
| 60 |
|
} |
| 61 |
|
else |
| 62 |
|
{ |
| 63 |
4 |
return extractFileSequenceNumber((String)archiveFiles.last()); |
| 64 |
|
} |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
public PersistentRoot readLatestSnapshot() throws ArchiverException |
| 68 |
|
{ |
| 69 |
3 |
if (archiveFiles.isEmpty()) |
| 70 |
|
{ |
| 71 |
1 |
log.info("No snapshots found"); |
| 72 |
1 |
return null; |
| 73 |
|
} |
| 74 |
|
|
| 75 |
2 |
String latestSnapshotName = (String)archiveFiles.last(); |
| 76 |
2 |
File latestSnapshot = constructArchiveFile(latestSnapshotName); |
| 77 |
2 |
return (PersistentRoot) readArchiveFile(latestSnapshot); |
| 78 |
|
} |
| 79 |
|
} |