source: java/main/src/main/java/com/framsticks/diagnostics/Diagnostics.java @ 88

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

HIGHLIGHTS:

  • loading f0 schema with XmlLoader?
  • use XmlLoader? to load configuration
  • introduce unified fork-join model of various entities

(Instances, Connections, GUI Frames, etc.),
all those entities clean up gracefully on
shutdown, which may be initialized by user
or by some entity

  • basing on above, simplify several organizing classes

(Observer, main class)

(to host native frams server process from Java level)

CHANGELOG:
Remove redundant Observer class.

Clean up in AbstractJoinable?.

Update ExternalProcess? class to changes in joining model.

Another sweep through code with FindBugs?.

Find bug with not joining RemoteInstance?.

Joining almost works.

Much improved joining model.

More improvement to joining model.

Add logging messages around joinable operations.

Rename methods in AbstractJoinable?.

Improve Joinable.

Rewrite of entity structure.

More simplifications with entities.

Further improve joinables.

Let Frame compose from JFrame instead of inheriting.

Add join classes.

Improvements of closing.

Add Builder interface.

Add FramsServerTest?.xml

FramsServer? may be configured through xml.

Make Framsticks main class an Observer of Entities.

Make Observer a generic type.

Remove variables regarding to removed endpoint.

Simplify observer (remove endpoints).

More changes to Observer and Endpoint.

Minor improvements.

Add OutputListener? to ExternalProcess?.

Improve testing of ExternalProcess?.

Add ExternalProcess? runner.

Rename the Program class to Framsticks.

Migrate Program to use XmlLoader? configuration.

First steps with configuration using XmlLoader?.

Fix several bugs.

Move all f0 classes to apriopriate package.

XmlLoader? is able to load Schema.

XmlLoader? is loading classes and props.

Add GroupBuilder?.

File size: 2.8 KB
Line 
1package com.framsticks.diagnostics;
2
3
4import java.util.Date;
5import java.io.File;
6import java.io.FileOutputStream;
7import java.io.IOException;
8import java.io.OutputStreamWriter;
9import java.io.PrintWriter;
10import java.text.SimpleDateFormat;
11
12import org.apache.log4j.Logger;
13
14import com.framsticks.core.AbstractInstanceListener;
15import com.framsticks.core.Instance;
16import com.framsticks.dumping.PrintWriterSink;
17import com.framsticks.dumping.SaveStream;
18import com.framsticks.params.annotations.AutoAppendAnnotation;
19import com.framsticks.remote.RecursiveFetcher;
20import com.framsticks.util.Logging;
21import com.framsticks.util.PeriodicTask;
22import com.framsticks.util.StateFunctor;
23import com.framsticks.util.dispatching.JoinableCollection;
24import com.framsticks.util.io.Encoding;
25
26/**
27 * @author Piotr Sniegowski
28 */
29public class Diagnostics extends JoinableCollection<Instance> {
30        private static final Logger log =
31                Logger.getLogger(Diagnostics.class);
32
33
34        Integer dumpsInterval;
35        String dumpsPath;
36        String dumpsFormat;
37
38
39        public Diagnostics() {
40        }
41
42
43        @Override
44        @AutoAppendAnnotation
45        public void add(final Instance instance) {
46                super.add(instance);
47
48                instance.addListener(new AbstractInstanceListener() {
49                        @Override
50                        public void onRun(Exception e) {
51                                if (e != null) {
52                                        return;
53                                }
54
55                                if (dumpsInterval != null) {
56                                        new PeriodicTask<Instance>(instance, dumpsInterval * 1000) {
57                                                @Override
58                                                public void run() {
59
60                                                        log.info("starting periodic dump");
61                                                        new RecursiveFetcher(instance, instance.getRootPath(), new StateFunctor() {
62                                                                @Override
63                                                                public void call(Exception e) {
64                                                                        if (Logging.log(log, "recursively fetch", instance, e)) {
65                                                                                again();
66                                                                                return;
67                                                                        }
68                                                                        log.info("instance resolved, saving");
69                                                                        try {
70                                                                                final String fileName = dumpsPath + "/" + instance + "_" + new SimpleDateFormat(dumpsFormat).format(new Date()) + ".param";
71                                                                                File file = new File(fileName);
72                                                                                new SaveStream(new PrintWriterSink(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Encoding.getFramsticksCharset()))), instance, instance.getRootPath(), new StateFunctor() {
73                                                                                        @Override
74                                                                                        public void call(Exception e) {
75                                                                                                Logging.log(log, "periodic dump in " + fileName + " of", instance, e);
76                                                                                                again();
77                                                                                        }
78                                                                                });
79                                                                        } catch (IOException ex) {
80                                                                                log.info("failed to initiate dump: " + ex);
81                                                                                again();
82                                                                        }
83
84                                                                }
85                                                        });
86                                                }
87                                        };
88                                }
89                        }
90                });
91
92
93
94        }
95
96        // @Override
97        // public void configure(Configuration config) {
98        //      super.configure(config);
99        //      dumpsInterval = config.getInteger("dumps.interval", null);
100        //      dumpsPath = config.getString("dumps.path", null);
101        //      dumpsFormat = config.getString("dumps.format", null);
102        // }
103
104}
Note: See TracBrowser for help on using the repository browser.