-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMigrate12to13.groovy
45 lines (39 loc) · 1.14 KB
/
Migrate12to13.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.concurrent.*
import v12.journal.io.api.*
import static v12.journal.io.api.Journal.*
POOL_SIZE = 5
srcRoot = this.args[0]
targetRoot = this.args[1]
operations = []
new File(srcRoot).eachDirRecurse { srcDir ->
relative = srcDir.path.substring(srcRoot.length())
operations << [srcDir, new File(targetRoot + relative)]
}
threadPool = Executors.newFixedThreadPool(POOL_SIZE)
try {
c = { s, t ->
println s.path + " -> " + t.path
Journal src = new Journal();
src.setDirectory(s);
src.open();
def target = new journal.io.api.Journal();
t.mkdirs()
target.setDirectory(t);
target.open();
try {
for (Location location : src.redo()) {
byte[] record = src.read(location, ReadType.ASYNC);
target.write(record, journal.io.api.Journal.WriteType.SYNC)
}
} finally {
src.close()
target.close()
}
}
futures = operations.collect {
threadPool.submit({-> c(it[0], it[1])} as Callable);
}
futures.each{it.get()}
} finally {
threadPool.shutdown()
}