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

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

HIGHLIGHTS:

  • cleanup Instance management
    • extract Instance interface
    • extract Instance common algorithms to InstanceUtils?
  • fix closing issues: Ctrl+C or window close button

properly shutdown whole program

by Java Framsticks framework

  • fix parsing and printing of all request types
  • hide exception passing in special handle method of closures
    • substantially improve readability of closures
    • basically enable use of exception in asynchronous closures

(thrown exception is transported back to the caller)

  • implement call request on both sides

CHANGELOG:
Further improve calling.

Improve instance calling.

Calling is working on both sides.

Improve exception handling in testing.

Waiters do not supercede other apllication exception being thrown.

Finished parsing and printing of all request types (with tests).

Move implementation and tests of request parsing to Request.

Add tests for Requests.

Improve waits in asynchronours tests.

Extract more algorithms to InstanceUtils?.

Extract Instance.resolve to InstanceUtils?.

Improve naming.

Improve passing exception in InstanceClient?.

Hide calling of passed functor in StateCallback?.

Hide Exception passing in asynchronous closures.

Hide exception passing in Future.

Make ResponseCallback? an abstract class.

Make Future an abstract class.

Minor change.

Move getPath to Path.to()

Move bindAccess to InstanceUtils?.

Extract common things to InstanceUtils?.

Fix synchronization bug in Connection.

Move resolve to InstanceUtils?.

Allow names of Joinable to be dynamic.

Add support for set request server side.

More fixes in communication.

Fix issues with parsing in connection.

Cut new line characters when reading.

More improvements.

Migrate closures to FramsticksException?.

Several changes.

Extract resolveAndFetch to InstanceUtils? algorithms.

Test resolving and fetching.

More fixes with function signature deduction.

Do not print default values in SimpleAbstractAccess?.

Add test of FramsClass? printing.

Improve FramsticksException? messages.

Add explicit dispatcher synchronization feature.

Rework assertions in tests.

Previous solution was not generic enough.

Allow addition of joinables to collection after start.

Extract SimulatorInstance? from RemoteInstance?.

Remove PrivateJoinableCollection?.

Improve connections.

Move shutdown hook to inside the Monitor.

It should work in TestNG tests, but it seems that
hooks are not called.

In ServerTest? client connects to testing server.

Move socket initialization to receiver thread.

Add proper closing on Ctrl+C (don't use signals).

Fix bugs with server accepting connections.

Merge Entity into Joinable.

Reworking ServerInstance?.

Extract more algorithm to InstanceUtils?.

Extract some common functionality from AbstractInstance?.

Functions were placed in InstanceUtils?.

Hide registry of Instance.

Use ValueParam? in Instance interface.

Minor change.

Extract Instance interface.

Old Instance is now AbstractInstance?.

File size: 3.0 KB
Line 
1package com.framsticks.diagnostics;
2
3import java.util.Date;
4import java.io.File;
5import java.io.FileOutputStream;
6import java.io.IOException;
7import java.io.OutputStreamWriter;
8import java.io.PrintWriter;
9import java.text.SimpleDateFormat;
10
11import org.apache.log4j.Logger;
12
13import com.framsticks.core.AbstractInstanceListener;
14import com.framsticks.core.Instance;
15import com.framsticks.core.Path;
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.FramsticksException;
21import com.framsticks.util.Logging;
22import com.framsticks.util.PeriodicTask;
23import com.framsticks.util.StateFunctor;
24import com.framsticks.util.dispatching.JoinableCollection;
25import com.framsticks.util.io.Encoding;
26
27/**
28 * @author Piotr Sniegowski
29 */
30public class Diagnostics extends JoinableCollection<Instance> {
31        private static final Logger log = 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, Path.to(instance, "/"), new StateFunctor() {
62                                                                @Override
63                                                                public void handle(FramsticksException e) {
64                                                                        Logging.log(log, "recursively fetch", instance, e);
65                                                                        again();
66                                                                }
67
68                                                                @Override
69                                                                public void call() {
70                                                                        log.info("instance resolved, saving");
71                                                                        try {
72                                                                                final String fileName = dumpsPath + "/" + instance + "_" + new SimpleDateFormat(dumpsFormat).format(new Date()) + ".param";
73                                                                                File file = new File(fileName);
74                                                                                new SaveStream(new PrintWriterSink(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Encoding.getFramsticksCharset()))), instance, Path.to(instance, "/"), new StateFunctor() {
75                                                                                        @Override
76                                                                                        public void handle(FramsticksException e) {
77                                                                                                Logging.log(log, "periodic dump in " + fileName + " of", instance, e);
78                                                                                                again();
79                                                                                        }
80
81                                                                                        @Override
82                                                                                        public void call() {
83                                                                                                again();
84                                                                                        }
85                                                                                });
86                                                                        } catch (IOException ex) {
87                                                                                log.info("failed to initiate dump: " + ex);
88                                                                                again();
89                                                                        }
90
91                                                                }
92                                                        });
93                                                }
94                                        };
95                                }
96                        }
97                });
98
99
100
101        }
102
103        // @Override
104        // public void configure(Configuration config) {
105        //      super.configure(config);
106        //      dumpsInterval = config.getInteger("dumps.interval", null);
107        //      dumpsPath = config.getString("dumps.path", null);
108        //      dumpsFormat = config.getString("dumps.format", null);
109        // }
110
111}
Note: See TracBrowser for help on using the repository browser.