1 | package com.framsticks.dumping; |
---|
2 | |
---|
3 | import com.framsticks.core.LocalInstance; |
---|
4 | import com.framsticks.core.Parameters; |
---|
5 | import com.framsticks.core.Path; |
---|
6 | import com.framsticks.params.FramsClass; |
---|
7 | import com.framsticks.core.Instance; |
---|
8 | import com.framsticks.util.*; |
---|
9 | import com.framsticks.util.UnsupportedOperationException; |
---|
10 | import org.apache.log4j.Logger; |
---|
11 | |
---|
12 | import java.io.BufferedReader; |
---|
13 | import java.io.File; |
---|
14 | import java.io.FileReader; |
---|
15 | import java.io.IOException; |
---|
16 | |
---|
17 | /** |
---|
18 | * @author Piotr Sniegowski |
---|
19 | */ |
---|
20 | public class FileInstance extends LocalInstance { |
---|
21 | |
---|
22 | private static final Logger LOGGER = Logger.getLogger(Instance.class.getName()); |
---|
23 | protected final File file; |
---|
24 | |
---|
25 | public FileInstance(Parameters parameters) { |
---|
26 | super(parameters); |
---|
27 | file = new File(config.getString("filename")); |
---|
28 | } |
---|
29 | |
---|
30 | @Override |
---|
31 | public void run() { |
---|
32 | assert isActive(); |
---|
33 | super.run(); |
---|
34 | try { |
---|
35 | FileReader fileReader = new FileReader(file); |
---|
36 | LoadStream stream = new LoadStream(new Path(this, "/"), new BufferedReader(fileReader), this, new Future<Path>() { |
---|
37 | @Override |
---|
38 | public void result(Path result, Exception e) { |
---|
39 | if (e != null) { |
---|
40 | LOGGER.error("failed to load file instance " + FileInstance.this + ": " + e); |
---|
41 | fireRun(e); |
---|
42 | return; |
---|
43 | } |
---|
44 | LOGGER.info("loaded file instance " + FileInstance.this); |
---|
45 | fireRun(null); |
---|
46 | } |
---|
47 | }); |
---|
48 | stream.load(); |
---|
49 | } catch (IOException e) { |
---|
50 | LOGGER.error("io failure: " + e); |
---|
51 | fireRun(e); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | @Override |
---|
57 | protected void fetchInfo(Path path, Future<FramsClass> future) { |
---|
58 | future.result(null, new UnsupportedOperationException()); |
---|
59 | } |
---|
60 | |
---|
61 | @Override |
---|
62 | protected void tryRegisterOnChangeEvents(Path path) { |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | @Override |
---|
67 | public String toString() { |
---|
68 | return "file@" + file.getName(); |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | } |
---|