1
2
3
4
5
6
7 package net.sf.exorcist.dbe.impl;
8
9 import net.sf.exorcist.api.ContentState;
10 import net.sf.exorcist.dbe.ExportService;
11 import net.sf.exorcist.dbe.ImportService;
12 import net.sf.exorcist.dbe.MigratorService;
13
14 import org.dbe.servent.Adapter;
15 import org.dbe.servent.ServiceContext;
16
17
18 /***
19 * @author Jukka Zitting
20 *
21 * TODO To change the template for this generated type comment go to
22 * Window - Preferences - Java - Code Style - Code Templates
23 */
24 public class SimpleMigratorService implements Adapter, MigratorService, Runnable {
25
26 private String[] srcEntries = null;
27 private String srcKey = null;
28 private String[] dstEntries = null;
29 private String dstKey = null;
30
31 private boolean running = true;
32 private ServiceContext context;
33
34
35
36
37 public void init(ServiceContext context) {
38 this.context = context;
39 new Thread(this).start();
40 }
41
42
43
44
45 public void destroy() {
46 running = false;
47 }
48
49 private synchronized void migrate() {
50 try {
51 ExportService exporter = (ExportService)
52 context.getService(ExportService.class, srcEntries[0]);
53 ImportService importer = (ImportService)
54 context.getService(ImportService.class, dstEntries[0]);
55 if (exporter != null && importer != null) {
56 ContentState content = exporter.exportContent(srcKey);
57 importer.importContent(dstKey, content);
58 }
59 } catch (Exception e) {
60 e.printStackTrace();
61 }
62 }
63
64 public void run() {
65 while (running) {
66 if (srcEntries != null) {
67 migrate();
68 }
69 try {
70 Thread.sleep(10*1000);
71 } catch (InterruptedException e) {
72 }
73 }
74 }
75
76
77
78
79 public synchronized void scheduleMigration(
80 String[] srcEntries, String srcKey,
81 String[] dstEntries, String dstKey) {
82 this.srcEntries = srcEntries;
83 this.srcKey = srcKey;
84 this.dstEntries = dstEntries;
85 this.dstKey = dstKey;
86 }
87
88 }