source: java/main/src/main/java/com/framsticks/remote/RecursiveFetcher.java @ 105

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

HIGHLIGHTS:

  • import refactorization: move Tree, Path, etc.

from core to structure package

  • initial serialization implementation
  • improve PrimeExperiment? test
  • many organizational changes and convenience improvements

CHANGELOG:
Make registry in AbstractTree? final.

Move most classes from core to structure package.

Minor changes.

Switch names of Future and FutureHandler?.

Rename ExceptionResultHandler? to ExceptionHandler?.

Rename ExceptionHandler? to ExceptionDispatcherHandler?.

Fix bug in ParamCandidate? cache.

Add missing synchronization to the BufferedDispatcher?.

Develop @Serialized support.

Rework serialization further.

Add serialization/deserialization interface to ValueParam?.

Move getStorageType and isNumeric from Param down to params hierarchy.

Minor changes.

Improve param type induction.

Add TestSerializedClass? for testing new serialization.

Add info files gor GenePool? and Population.

Add standard.expt exemplary netfile.

Add type name field to PropertiesObject?.

Use PropertiesObject? for PropertiesAccess? instead of ordinary map.

Hide getFramsClass is several more places.

More unification accross FramsClass?, Access and Path.

Add ParamCollection?.

Simplify interface for getting params from FramsClass?, Access
or Path.

Make Access.call() interface variadic.

Add arguments(args) convenience wrapper around new Object[] {args}.

Upgrade to apache.commons.lang version 3.1

Minor improvement with Response constructors.

Develop proper result printing in ClientAtServer?.

Add experimentNetsave to PrimeExperiment?.

File size: 2.7 KB
Line 
1package com.framsticks.remote;
2
3
4import com.framsticks.params.Access;
5import com.framsticks.params.CompositeParam;
6import com.framsticks.structure.Node;
7import com.framsticks.structure.Path;
8import com.framsticks.structure.Tree;
9import com.framsticks.util.dispatching.FutureHandler;
10import com.framsticks.util.dispatching.Future;
11import com.framsticks.util.dispatching.ThrowExceptionHandler;
12import com.framsticks.util.FramsticksException;
13import com.framsticks.util.Logging;
14import com.framsticks.util.Stopwatch;
15import org.apache.logging.log4j.Logger;
16import org.apache.logging.log4j.LogManager;
17
18import static com.framsticks.structure.TreeOperations.*;
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 = LogManager.getLogger(RecursiveFetcher.class.getName());
28
29        protected final Tree tree;
30        protected final FutureHandler<Void> future;
31        protected int dispatched;
32        protected final Stopwatch stopwatch = new Stopwatch();
33
34        public RecursiveFetcher(Tree tree, final Path path, FutureHandler<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 {} is not resolved - skipping", path);
51                } else {
52                        Access access = bindAccess(path);
53                        for (CompositeParam p : filterInstanceof(access.getParams(), CompositeParam.class)) {
54                                Object child = access.get(p, Object.class);
55                                final Path childPath = path.appendNode(new Node(path.getTree(), p, child));
56                                if (childPath.isResolved() && getInfoFromCache(childPath) != null) {
57                                        ++dispatched;
58                                        tree.dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) {
59                                                @Override
60                                                protected void runAt() {
61                                                        fetch(childPath);
62                                                }
63                                        });
64                                        continue;
65                                }
66                                ++dispatched;
67                                tree.get(childPath, new Future<Path>(Logging.logger(log, "resolve", RecursiveFetcher.this)) {
68                                        @Override
69                                        protected void result(Path result) {
70                                                assert tree.isActive();
71                                                fetch(result);
72                                        }
73                                });
74                        }
75                }
76                --dispatched;
77                if (dispatched == 0) {
78                        finished();
79                }
80        }
81
82        protected void fetch(final Path path) {
83                tree.get(path, new FutureHandler<Path>() {
84
85                        @Override
86                        public void handle(FramsticksException e) {
87                                log.error("failed to fetch values for {}: ", path, e);
88                                process(null);
89                        }
90
91                        @Override
92                        protected void result(Path result) {
93                                process(result);
94                        }
95                });
96        }
97
98}
Note: See TracBrowser for help on using the repository browser.