source: java/main/src/main/java/com/framsticks/remote/SimulatorTree.java @ 97

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

HIGHLIGHTS:

  • add proper exception passing between communication sides:

if exception occur during handling client request, it is
automatically passed as comment to error response.

it may be used to snoop communication between peers

  • fix algorithm choosing text controls in GUI
  • allow GUI testing in virtual frame buffer (xvfb)

FEST had some problem with xvfb but workaround was found

supports tab-completion based on requests history

CHANGELOG:
Further improve handling of exceptions in GUI.

Add StatusBar? implementing ExceptionResultHandler?.

Make completion processing asynchronous.

Minor changes.

Improve completion in console.

Improve history in InteractiveConsole?.

First working version of DirectConsole?.

Minor changes.

Make Connection.address non final.

It is more suitable to use in configuration.

Improvement of consoles.

Improve PopupMenu? and closing of FrameJoinable?.

Fix BrowserTest?.

Found bug with FEST running under xvfb.

JButtonFixture.click() is not working under xvfb.
GuiTest? has wrapper which uses JButton.doClick() directly.

Store CompositeParam? param in TreeNode?.

Simplify ClientSideManagedConnection? connecting.

There is now connectedFunctor needed, ApplicationRequests? can be
send right after creation. They are buffered until the version
and features are negotiated.

Narow down interface of ClientSideManagedConnection?.

Allow that connection specialization send only
ApplicationRequests?.

Improve policy of text control choosing.

Change name of Genotype in BrowserTest?.

Make BrowserTest? change name of Genotype.

Minor change.

First working draft of TrackConsole?.

Simplify Consoles.

More improvements with gui joinables.

Unify initialization on gui joinables.

More rework of Frame based entities.

Refactorize structure of JFrames based entities.

Extract GuiTest? from BrowserBaseTest?.

Reorganize Console classes structure.

Add Collection view to JoinableCollection?.

Configure timeout in testing.

Minor changes.

Rework connections hierarchy.

Add Mode to the get operation.

Make get and set in Tree take PrimitiveParam?.

Unify naming of operations.

Make RunAt? use the given ExceptionHandler?.

It wraps the virtual runAt() method call with
try-catch passing exception to handler.

Force RunAt? to include ExceptionHandler?.

Improve ClientAtServer?.

Minor change.

Another sweep with FindBugs?.

Rename Instance to Tree.

Minor changes.

Minor changes.

Further clarify semantics of Futures.

Add FutureHandler?.

FutureHandler? is refinement of Future, that proxifies
exception handling to ExceptionResultHandler? given
at construction time.

Remove StateFunctor? (use Future<Void> instead).

Make Connection use Future<Void>.

Unparametrize *ResponseFuture?.

Remove StateCallback? not needed anymore.

Distinguish between sides of ResponseFuture?.

Base ResponseCallback? on Future (now ResponseFuture?).

Make asynchronous store taking Future for flags.

Implement storeValue in ObjectInstance?.

File size: 3.5 KB
Line 
1package com.framsticks.remote;
2
3import java.util.List;
4
5import org.apache.log4j.Logger;
6
7import static com.framsticks.core.TreeOperations.*;
8import com.framsticks.communication.EventCallback;
9import com.framsticks.communication.File;
10import com.framsticks.communication.util.LoggingSubscriptionCallback;
11import com.framsticks.core.Tree;
12import com.framsticks.core.TreeOperations;
13import com.framsticks.core.Path;
14import com.framsticks.params.annotations.FramsClassAnnotation;
15import com.framsticks.params.types.EventParam;
16import com.framsticks.util.Logging;
17import com.framsticks.util.PeriodicTask;
18import com.framsticks.util.UnaryFunctor;
19import com.framsticks.util.UnaryListenersSet;
20import com.framsticks.util.dispatching.FutureHandler;
21import com.framsticks.util.dispatching.RunAt;
22import com.framsticks.util.dispatching.ThrowExceptionHandler;
23
24@FramsClassAnnotation
25public class SimulatorTree extends RemoteTree {
26
27        private final static Logger log = Logger.getLogger(SimulatorTree.class);
28
29        protected Path simulator;
30
31        /**
32         *
33         */
34        public SimulatorTree() {
35                super();
36        }
37
38        public void setRunning(final boolean running) {
39                assert isActive();
40                //simulator.call(simulator.getParam(running ? "start" : "stop", ProcedureParam.class), new LoggingStateCallback(log, (running ? "starting" : "stopping") + " server"));
41        }
42
43        protected final UnaryListenersSet<Boolean> simulationRunningListeners = new UnaryListenersSet<Boolean>();
44
45        protected void updateSimulationRunning() {
46                assert isActive();
47                /*
48                fetchValue(simulator, getParam(simulator, "running", Param.class), new StateFunctor() {
49                        @Override
50                        public void call(Exception e) {
51                                if (e != null) {
52                                        log.fatal("failed to query simulator running status: " + e);
53                                        return;
54                                }
55
56                                invokeLater(new Runnable() {
57                                        @Override
58                                        public void run() {
59                                                boolean value = bindAccess(simulator).get("running", Boolean.class);
60                                                log.trace("server running: " + value);
61                                                simulationRunningListeners.call(value);
62                                        }
63                                });
64
65                        }
66                });
67                 */
68        }
69
70        public void addRunningStateListener(UnaryFunctor<Boolean, Boolean> listener) {
71                assert isActive();
72                simulationRunningListeners.add(listener);
73        }
74
75        @Override
76        protected void joinableStart() {
77                super.joinableStart();
78
79                dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) {
80                        @Override
81                        protected void runAt() {
82                                resolveAndGet(SimulatorTree.this, "/simulator", new FutureHandler<Path>(Logging.logger(log, "failed to resolve simulator node", SimulatorTree.this)) {
83                                        @Override
84                                        protected void result(Path path) {
85                                                assert isActive();
86                                                simulator = path;
87                                                fireRun(null);
88                                                log.info("resolved simulator node");
89
90                                                EventParam param = TreeOperations.getInfoFromCache(simulator).getParamEntry("running_changed", EventParam.class);
91
92                                                assert param != null;
93                                                connection.subscribe(simulator.getTextual() + "/" + param.getId(), SimulatorTree.this, new LoggingSubscriptionCallback<Tree>(log, "server running state change", new EventCallback() {
94                                                        @Override
95                                                        public void call(List<File> files) {
96                                                                //TODO TEH
97                                                                dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) {
98                                                                        @Override
99                                                                        protected void runAt() {
100                                                                                updateSimulationRunning();
101                                                                        }
102                                                                });
103                                                        }
104                                                }));
105                                                new PeriodicTask<Tree>(ThrowExceptionHandler.getInstance(), SimulatorTree.this, 1000) {
106                                                        @Override
107                                                        protected void runAt() {
108                                                                updateSimulationRunning();
109                                                                again();
110                                                        }
111                                                };
112                                        }
113                                });
114                        }
115                });
116        }
117
118}
Note: See TracBrowser for help on using the repository browser.