1 package org.simantics.backup;
3 import java.nio.file.Path;
4 import java.util.ArrayList;
5 import java.util.Collection;
7 import java.util.concurrent.Future;
10 * @author Tuukka Lehtonen
12 public class Backups {
17 * @throws BackupException
19 public static void lock(List<IBackupProvider> providers) throws BackupException {
21 int count = providers.size();
23 for (; i < count; ++i) {
24 providers.get(i).lock();
26 } catch (BackupException e) {
27 for (int j = i-1; j >= 0; --j) {
29 providers.get(j).unlock();
30 } catch (BackupException ex) {
31 // TODO: proper logging.
39 public static List<Future<BackupException>> syncBackup(List<IBackupProvider> providers, Path targetPath, int revision) throws BackupException {
40 // Initiate all backup providers, possibly to execute concurrently.
41 List<Future<BackupException>> futures = new ArrayList<>(providers.size());
42 for (IBackupProvider provider : providers)
43 futures.add( provider.backup(targetPath, revision) );
48 public static void unlock(Collection<IBackupProvider> providers) {
49 for (IBackupProvider provider : providers) {
52 } catch (BackupException e) {
53 // TODO: proper logging
59 // private static class BackupResultFuture implements Future<BackupException> {
61 // public static final BackupResultFuture SUCCESS = new BackupResultFuture(null);
63 // private final BackupException e;
65 // public BackupResultFuture(BackupException e) {
70 // public boolean cancel(boolean mayInterruptIfRunning) {
75 // public boolean isCancelled() {
80 // public boolean isDone() {
85 // public BackupException get() throws InterruptedException, ExecutionException {
90 // public BackupException get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {