Search in sources :

Example 1 with StartBackup

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);
}
Also used : ChangePath(com.swiftmq.impl.store.standard.backup.po.ChangePath) Semaphore(com.swiftmq.tools.concurrent.Semaphore) ChangeGenerations(com.swiftmq.impl.store.standard.backup.po.ChangeGenerations) SwiftletException(com.swiftmq.swiftlet.SwiftletException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) StartBackup(com.swiftmq.impl.store.standard.backup.po.StartBackup) ScanSaveSets(com.swiftmq.impl.store.standard.backup.po.ScanSaveSets)

Example 2 with StartBackup

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));
}
Also used : JobException(com.swiftmq.swiftlet.scheduler.JobException) Semaphore(com.swiftmq.tools.concurrent.Semaphore) StartBackup(com.swiftmq.impl.store.standard.backup.po.StartBackup) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Aggregations

StartBackup (com.swiftmq.impl.store.standard.backup.po.StartBackup)2 Semaphore (com.swiftmq.tools.concurrent.Semaphore)2 ChangeGenerations (com.swiftmq.impl.store.standard.backup.po.ChangeGenerations)1 ChangePath (com.swiftmq.impl.store.standard.backup.po.ChangePath)1 ScanSaveSets (com.swiftmq.impl.store.standard.backup.po.ScanSaveSets)1 SwiftletException (com.swiftmq.swiftlet.SwiftletException)1 JobException (com.swiftmq.swiftlet.scheduler.JobException)1 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1