- Timestamp:
- 06/22/13 21:51:33 (11 years ago)
- Location:
- java/main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main
-
Property
svn:ignore
set to
target
-
Property
svn:ignore
set to
-
java/main/src/main/java/com/framsticks/dumping/LoadStream.java
r77 r84 6 6 import com.framsticks.core.Instance; 7 7 import com.framsticks.util.*; 8 import com.framsticks.util.dispatching.Future; 9 import com.framsticks.util.lang.Pair; 10 import com.framsticks.util.lang.Strings; 8 11 import org.apache.log4j.Logger; 9 12 … … 18 21 public class LoadStream { 19 22 20 private final static Logger LOGGER= Logger.getLogger(LoadStream.class.getName());23 private final static Logger log = Logger.getLogger(LoadStream.class.getName()); 21 24 22 23 24 25 26 25 protected final Instance instance; 26 protected final Path mountPath; 27 protected final BufferedReader stream; 28 protected final Future<Path> future; 29 protected final Stopwatch stopwatch = new Stopwatch(); 27 30 28 31 29 30 31 32 33 34 32 public LoadStream(Path mountPath, BufferedReader stream, Instance instance, Future<Path> future) { 33 this.instance = instance; 34 this.mountPath = mountPath; 35 this.stream = stream; 36 this.future = future; 37 } 35 38 36 37 38 39 40 41 42 43 44 45 46 47 LOGGER.trace("loading " + line);48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 LOGGER.error("failed to load: " + e);81 82 83 84 LOGGER.info("loaded in: " + stopwatch);85 future.result(new Path(instance,mountPath.getTextual()), null);86 39 public void load() { 40 try { 41 String line; 42 Pair<String, String> query = null; 43 List<File> files = null; 44 List<String> content = null; 45 //File file; 46 while ((line = stream.readLine()) != null) { 47 if (query == null) { 48 query = Strings.splitIntoPair(line, ' ', "\n"); 49 files = new LinkedList<File>(); 50 log.trace("loading " + line); 51 continue; 52 } 53 if (content == null) { 54 if (line.equals("file")) { 55 content = new LinkedList<String>(); 56 continue; 57 } 58 if (line.equals("ok")) { 59 if (query.first.equals("get")) { 60 Path path = instance.createIfNeeded(query.second); 61 instance.processFetchedValues(path, files); 62 } else if (query.first.equals("info")) { 63 assert files.size() == 1; 64 instance.processFetchedInfo(files.get(0)); 65 } else { 66 assert false; 67 } 68 query = null; 69 files = null; 70 continue; 71 } 72 assert false; 73 continue; 74 } 75 if (line.equals("eof")) { 76 files.add(new File(query.second, new ListSource(content))); 77 content = null; 78 continue; 79 } 80 content.add(line); 81 } 82 } catch (IOException e) { 83 log.error("failed to load: " + e); 84 future.result(null, e); 85 return; 86 } 87 log.info("loaded in: " + stopwatch); 88 future.result(instance.getPath(mountPath.getTextual()), null); 89 } 87 90 88 91
Note: See TracChangeset
for help on using the changeset viewer.