source: java/main/src/main/java/com/framsticks/dumping/FileInstance.java @ 77

Last change on this file since 77 was 77, checked in by psniegowski, 11 years ago

Add new java codebase.

File size: 2.0 KB
Line 
1package com.framsticks.dumping;
2
3import com.framsticks.core.LocalInstance;
4import com.framsticks.core.Parameters;
5import com.framsticks.core.Path;
6import com.framsticks.params.FramsClass;
7import com.framsticks.core.Instance;
8import com.framsticks.util.*;
9import com.framsticks.util.UnsupportedOperationException;
10import org.apache.log4j.Logger;
11
12import java.io.BufferedReader;
13import java.io.File;
14import java.io.FileReader;
15import java.io.IOException;
16
17/**
18 * @author Piotr Sniegowski
19 */
20public 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}
Note: See TracBrowser for help on using the repository browser.