- Timestamp:
- 07/08/13 23:04:56 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/diagnostics/Diagnostics.java
r97 r98 1 1 package com.framsticks.diagnostics; 2 2 3 import java.util.Date;4 import java.io.File;5 import java.io.FileOutputStream;6 import java.io.IOException;7 import java.io.OutputStreamWriter;8 import java.io.PrintWriter;9 import java.text.SimpleDateFormat;10 3 11 import org.apache.log4j.Logger;12 13 import com.framsticks.core.AbstractTreeListener;14 4 import com.framsticks.core.Tree; 15 import com.framsticks.core.Path;16 import com.framsticks.dumping.PrintWriterSink;17 import com.framsticks.dumping.SaveStream;18 5 import com.framsticks.params.annotations.AutoAppendAnnotation; 19 import com.framsticks.remote.RecursiveFetcher;20 import com.framsticks.util.FramsticksException;21 import com.framsticks.util.PeriodicTask;22 import com.framsticks.util.dispatching.ExceptionResultHandler;23 import com.framsticks.util.dispatching.FutureHandler;24 6 import com.framsticks.util.dispatching.JoinableCollection; 25 import com.framsticks.util.dispatching.ThrowExceptionHandler;26 import com.framsticks.util.io.Encoding;27 7 28 8 /** … … 30 10 */ 31 11 public class Diagnostics extends JoinableCollection<Tree> { 32 private static final Logger log = Logger.getLogger(Diagnostics.class);33 12 34 13 … … 48 27 super.add(tree); 49 28 50 tree.addListener(new AbstractTreeListener() {51 @Override52 public void onRun(Exception e) {53 if (e != null) {54 return;55 }29 // tree.addListener(new AbstractTreeListener() { 30 // @Override 31 // public void onRun(Exception e) { 32 // if (e != null) { 33 // return; 34 // } 56 35 57 if (dumpsInterval != null) {58 new PeriodicTask<Tree>(ThrowExceptionHandler.getInstance(), tree, dumpsInterval * 1000) {59 protected final ExceptionResultHandler repeater = new ExceptionResultHandler() {36 // if (dumpsInterval != null) { 37 // new PeriodicTask<Tree>(ThrowExceptionHandler.getInstance(), tree, dumpsInterval * 1000) { 38 // protected final ExceptionResultHandler repeater = new ExceptionResultHandler() { 60 39 61 @Override62 public void handle(FramsticksException exception) {63 log.error("caught error during diagnostics fetching (repeating): " + exception);64 again();65 }40 // @Override 41 // public void handle(FramsticksException exception) { 42 // log.error("caught error during diagnostics fetching (repeating): " + exception); 43 // again(); 44 // } 66 45 67 };68 @Override69 protected void runAt() {46 // }; 47 // @Override 48 // protected void runAt() { 70 49 71 log.info("starting periodic dump");72 new RecursiveFetcher(tree, Path.to(tree, "/"), new FutureHandler<Void>(repeater) {50 // log.info("starting periodic dump"); 51 // new RecursiveFetcher(tree, Path.to(tree, "/"), new FutureHandler<Void>(repeater) { 73 52 74 @Override75 protected void result(Void result) {76 log.info("tree resolved, saving");77 try {78 final String fileName = dumpsPath + "/" + tree + "_" + new SimpleDateFormat(dumpsFormat).format(new Date()) + ".param";79 File file = new File(fileName);80 new SaveStream(new PrintWriterSink(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Encoding.getFramsticksCharset()))), tree, Path.to(tree, "/"), new FutureHandler<Void>(repeater) {53 // @Override 54 // protected void result(Void result) { 55 // log.info("tree resolved, saving"); 56 // try { 57 // final String fileName = dumpsPath + "/" + tree + "_" + new SimpleDateFormat(dumpsFormat).format(new Date()) + ".param"; 58 // File file = new File(fileName); 59 // new SaveStream(new PrintWriterSink(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Encoding.getFramsticksCharset()))), tree, Path.to(tree, "/"), new FutureHandler<Void>(repeater) { 81 60 82 @Override83 protected void result(Void result) {84 again();85 }86 });87 } catch (IOException e) {88 throw new FramsticksException().msg("failed to initiate dump").cause(e);89 }90 }91 });92 }93 };94 }95 }96 });61 // @Override 62 // protected void result(Void result) { 63 // again(); 64 // } 65 // }); 66 // } catch (IOException e) { 67 // throw new FramsticksException().msg("failed to initiate dump").cause(e); 68 // } 69 // } 70 // }); 71 // } 72 // }; 73 // } 74 // } 75 // }); 97 76 98 77
Note: See TracChangeset
for help on using the changeset viewer.