use of com.swiftmq.impl.store.standard.backup.po.StartBackup in project swiftmq-ce by iitsoftware.
the class StoreSwiftletImpl method checkBackupPath.
private void checkBackupPath() throws SwiftletException {
Property prop = ctx.backupEntity.getProperty("path");
String path = SwiftUtilities.addWorkingDir((String) prop.getValue());
File f = new File(path);
if (f.exists()) {
if (!f.isDirectory())
throw new SwiftletException("Invalid Backup Path (not a Directory): " + path + "(absolute paths must be prefixed with \"absolute:\")");
} else {
if (!f.mkdirs())
throw new SwiftletException("Invalid Backup Path (unable to create Directory): " + path + "(absolute paths must be prefixed with \"absolute:\")");
}
ctx.backupProcessor.enqueue(new ScanSaveSets());
prop.setPropertyChangeListener(new PropertyChangeListener() {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
String s = SwiftUtilities.addWorkingDir((String) newValue);
File file = new File(s);
if (file.exists()) {
if (!file.isDirectory())
throw new PropertyChangeException("Invalid Backup Path (not a Directory): " + s + "(absolute paths must be prefixed with \"absolute:\")");
} else {
if (!file.mkdirs())
throw new PropertyChangeException("Invalid Backup Path (unable to create Directory): " + s + "(absolute paths must be prefixed with \"absolute:\")");
}
Semaphore sem = new Semaphore();
ChangePath po = new ChangePath(sem, (String) newValue);
ctx.backupProcessor.enqueue(po);
sem.waitHere();
if (!po.isSuccess())
throw new PropertyChangeException(po.getException());
ctx.backupProcessor.enqueue(new ScanSaveSets());
}
});
prop = ctx.backupEntity.getProperty("keep-generations");
prop.setPropertyChangeListener(new PropertyChangeListener() {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
int i = ((Integer) newValue).intValue();
Semaphore sem = new Semaphore();
ChangeGenerations po = new ChangeGenerations(sem, i);
ctx.backupProcessor.enqueue(po);
sem.waitHere();
if (!po.isSuccess())
throw new PropertyChangeException(po.getException());
ctx.backupProcessor.enqueue(new ScanSaveSets());
}
});
CommandRegistry commandRegistry = ctx.backupEntity.getCommandRegistry();
CommandExecutor backupExecutor = new CommandExecutor() {
public String[] execute(String[] context, Entity entity, String[] cmd) {
if (cmd.length != 1)
return new String[] { TreeCommands.ERROR, "Invalid command, please try 'backup'" };
Semaphore sem = new Semaphore();
StartBackup po = new StartBackup(sem, null);
ctx.backupProcessor.enqueue(po);
sem.waitHere();
String[] result = null;
if (po.isSuccess())
result = new String[] { TreeCommands.INFO, "Backup initiated. Please watch Folder 'Generated Backup Save Sets'." };
else
result = new String[] { TreeCommands.ERROR, po.getException() };
return result;
}
};
Command backupCommand = new Command("backup", "backup", "Perform Backup Now", true, backupExecutor, true, false);
commandRegistry.addCommand(backupCommand);
}
use of com.swiftmq.impl.store.standard.backup.po.StartBackup in project swiftmq-ce by iitsoftware.
the class BackupJob method start.
public synchronized void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.storeSwiftlet.getName(), toString() + "/start, properties=" + properties + " ...");
this.jobTerminationListener = jobTerminationListener;
this.properties = properties;
Semaphore sem = new Semaphore();
StartBackup po = new StartBackup(sem, this);
ctx.backupProcessor.enqueue(po);
sem.waitHere();
if (!po.isSuccess())
jobTerminationListener.jobTerminated(new JobException(po.getException(), new Exception(po.getException()), false));
}
Aggregations