]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.backup/src/org/simantics/backup/Backups.java
Getting rid of multiple jackson versions
[simantics/platform.git] / bundles / org.simantics.backup / src / org / simantics / backup / Backups.java
1 package org.simantics.backup;
2
3 import java.nio.file.Path;
4 import java.util.ArrayList;
5 import java.util.Collection;
6 import java.util.List;
7 import java.util.concurrent.Future;
8
9 /**
10  * @author Tuukka Lehtonen
11  */
12 public class Backups {
13
14     /**
15      * 
16      * @param providers
17      * @throws BackupException
18      */
19     public static void lock(List<IBackupProvider> providers) throws BackupException {
20         int i = 0;
21         int count = providers.size();
22         try {
23             for (; i < count; ++i) {
24                 providers.get(i).lock();
25             }
26         } catch (BackupException e) {
27             for (int j = i-1; j >= 0; --j) {
28                 try {
29                     providers.get(j).unlock();
30                 } catch (BackupException ex) {
31                     // TODO: proper logging.
32                     ex.printStackTrace();
33                 }
34             }
35             throw e;
36         }
37     }
38
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) );
44
45         return futures;
46     }
47
48     public static void unlock(Collection<IBackupProvider> providers) {
49         for (IBackupProvider provider : providers) {
50             try {
51                 provider.unlock();
52             } catch (BackupException e) {
53                 // TODO: proper logging
54                 e.printStackTrace();
55             }
56         }
57     }
58
59 //    private static class BackupResultFuture implements Future<BackupException> {
60 //
61 //        public static final BackupResultFuture SUCCESS = new BackupResultFuture(null);
62 //
63 //        private final BackupException e;
64 //
65 //        public BackupResultFuture(BackupException e) {
66 //            this.e = e;
67 //        }
68 //
69 //        @Override
70 //        public boolean cancel(boolean mayInterruptIfRunning) {
71 //            return false;
72 //        }
73 //
74 //        @Override
75 //        public boolean isCancelled() {
76 //            return false;
77 //        }
78 //
79 //        @Override
80 //        public boolean isDone() {
81 //            return true;
82 //        }
83 //
84 //        @Override
85 //        public BackupException get() throws InterruptedException, ExecutionException {
86 //            return e;
87 //        }
88 //
89 //        @Override
90 //        public BackupException get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
91 //            return e;
92 //        }
93 //
94 //    }
95
96 }