source: java/main/src/main/java/com/framsticks/remote/RecursiveFetcher.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: 2.8 KB
Line 
1package com.framsticks.remote;
2
3import static com.framsticks.core.TreeOperations.*;
4
5import com.framsticks.core.Mode;
6import com.framsticks.core.Node;
7import com.framsticks.core.Path;
8import com.framsticks.params.AccessInterface;
9import com.framsticks.params.CompositeParam;
10import com.framsticks.params.FramsClass;
11import com.framsticks.core.Tree;
12import com.framsticks.util.dispatching.Future;
13import com.framsticks.util.dispatching.FutureHandler;
14import com.framsticks.util.dispatching.ThrowExceptionHandler;
15import com.framsticks.util.FramsticksException;
16import com.framsticks.util.Logging;
17import com.framsticks.util.Stopwatch;
18import org.apache.log4j.Logger;
19import static com.framsticks.util.lang.Containers.filterInstanceof;
20import com.framsticks.util.dispatching.RunAt;
21
22/**
23 * @author Piotr Sniegowski
24 */
25public class RecursiveFetcher {
26
27        private final static Logger log = Logger.getLogger(RecursiveFetcher.class.getName());
28
29        protected final Tree tree;
30        protected final Future<Void> future;
31        protected int dispatched;
32        protected final Stopwatch stopwatch = new Stopwatch();
33
34        public RecursiveFetcher(Tree tree, final Path path, Future<Void> future) {
35                this.tree = tree;
36                this.future = future;
37                dispatched = 1;
38                process(path);
39        }
40
41        protected void finished() {
42                assert tree.isActive();
43                log.info("recursively fetched in " + stopwatch);
44                future.pass(null);
45        }
46
47        protected void process(final Path path) {
48                assert tree.isActive();
49                if (path == null || !path.isResolved()) {
50                        log.warn("path " + path + " is not resolved - skipping");
51                } else {
52                        AccessInterface access = bindAccess(path);
53                        FramsClass framsClass = access.getFramsClass();
54                        assert framsClass != null;
55                        for (CompositeParam p : filterInstanceof(access.getParams(), CompositeParam.class)) {
56                                Object child = access.get(p, Object.class);
57                                final Path childPath = path.appendNode(new Node(p, child));
58                                if (childPath.isResolved() && getInfoFromCache(childPath) != null) {
59                                        ++dispatched;
60                                        tree.dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) {
61                                                @Override
62                                                protected void runAt() {
63                                                        fetch(childPath);
64                                                }
65                                        });
66                                        continue;
67                                }
68                                ++dispatched;
69                                tree.resolve(childPath, new FutureHandler<Path>(Logging.logger(log, "resolve", RecursiveFetcher.this)) {
70                                        @Override
71                                        protected void result(Path result) {
72                                                assert tree.isActive();
73                                                fetch(result);
74                                        }
75                                });
76                        }
77                }
78                --dispatched;
79                if (dispatched == 0) {
80                        finished();
81                }
82        }
83
84        protected void fetch(final Path path) {
85                tree.get(path, Mode.FETCH, new Future<Object>() {
86
87                        @Override
88                        public void handle(FramsticksException e) {
89                                log.error("failed to fetch values for " + path + ": " + e);
90                                process(null);
91                        }
92
93                        @Override
94                        protected void result(Object object) {
95                                process(path);
96                        }
97                });
98        }
99
100}
Note: See TracBrowser for help on using the repository browser.