source: java/main/src/main/java/com/framsticks/dumping/LoadStream.java @ 105

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

HIGHLIGHTS:

  • import refactorization: move Tree, Path, etc.

from core to structure package

  • initial serialization implementation
  • improve PrimeExperiment? test
  • many organizational changes and convenience improvements

CHANGELOG:
Make registry in AbstractTree? final.

Move most classes from core to structure package.

Minor changes.

Switch names of Future and FutureHandler?.

Rename ExceptionResultHandler? to ExceptionHandler?.

Rename ExceptionHandler? to ExceptionDispatcherHandler?.

Fix bug in ParamCandidate? cache.

Add missing synchronization to the BufferedDispatcher?.

Develop @Serialized support.

Rework serialization further.

Add serialization/deserialization interface to ValueParam?.

Move getStorageType and isNumeric from Param down to params hierarchy.

Minor changes.

Improve param type induction.

Add TestSerializedClass? for testing new serialization.

Add info files gor GenePool? and Population.

Add standard.expt exemplary netfile.

Add type name field to PropertiesObject?.

Use PropertiesObject? for PropertiesAccess? instead of ordinary map.

Hide getFramsClass is several more places.

More unification accross FramsClass?, Access and Path.

Add ParamCollection?.

Simplify interface for getting params from FramsClass?, Access
or Path.

Make Access.call() interface variadic.

Add arguments(args) convenience wrapper around new Object[] {args}.

Upgrade to apache.commons.lang version 3.1

Minor improvement with Response constructors.

Develop proper result printing in ClientAtServer?.

Add experimentNetsave to PrimeExperiment?.

File size: 2.6 KB
Line 
1package com.framsticks.dumping;
2
3import com.framsticks.communication.File;
4import com.framsticks.params.ListSource;
5import com.framsticks.structure.Path;
6import com.framsticks.structure.Tree;
7import com.framsticks.structure.TreeOperations;
8import com.framsticks.util.*;
9import com.framsticks.util.dispatching.FutureHandler;
10import com.framsticks.util.lang.Pair;
11import com.framsticks.util.lang.Strings;
12import org.apache.logging.log4j.Logger;
13import org.apache.logging.log4j.LogManager;
14
15import java.io.BufferedReader;
16import java.io.IOException;
17import java.util.LinkedList;
18import java.util.List;
19
20/**
21 * @author Piotr Sniegowski
22 */
23public class LoadStream extends Stream {
24
25        private final static Logger log = LogManager.getLogger(LoadStream.class.getName());
26
27        protected final Tree tree;
28        protected final Path mountPath;
29        protected final BufferedReader stream;
30        protected final FutureHandler<Path> future;
31        protected final Stopwatch stopwatch = new Stopwatch();
32
33
34        public LoadStream(Path mountPath, BufferedReader stream, Tree tree, FutureHandler<Path> future) {
35                this.tree = tree;
36                this.mountPath = mountPath;
37                this.stream = stream;
38                this.future = future;
39        }
40
41        public void load() {
42                try {
43                        String line;
44                        Pair<String, String> query = null;
45                        List<File> files = null;
46                        List<String> content = null;
47                        //File file;
48                        while ((line = stream.readLine()) != null) {
49                                if (query == null) {
50                                        query = Strings.splitIntoPair(line, ' ', "");
51                                        files = new LinkedList<File>();
52                                        log.trace("loading {}", line);
53                                        continue;
54                                }
55                                if (content == null) {
56                                        if (line.equals("file")) {
57                                                content = new LinkedList<String>();
58                                                continue;
59                                        }
60                                        if (line.equals("ok")) {
61                                                if (query.first.equals("get")) {
62                                                        // Path path = null;
63                                                        throw new UnimplementedException().msg("rework load stream");
64                                                        // Path path = TreeOperations.createIfNeeded(tree, query.second);
65                                                        // TreeOperations.processFetchedValues(path, files);
66                                                } else if (query.first.equals("info")) {
67                                                        assert files.size() == 1;
68                                                        TreeOperations.processFetchedInfo(tree, files.get(0));
69                                                } else {
70                                                        assert false;
71                                                }
72                                                query = null;
73                                                files = null;
74                                                continue;
75                                        }
76                                        assert false;
77                                        continue;
78                                }
79                                if (line.equals("eof")) {
80                                        files.add(new File(query.second, new ListSource(content)));
81                                        content = null;
82                                        continue;
83                                }
84                                content.add(line);
85                        }
86                } catch (IOException e) {
87                        log.error("failed to load: {}", e);
88                        future.handle(new FramsticksException().msg("failed to load stream").cause(e));
89                        return;
90                }
91                log.info("loaded in: {}", stopwatch);
92                future.pass(Path.to(tree, mountPath.getTextual()));
93        }
94
95
96}
Note: See TracBrowser for help on using the repository browser.