source: java/main/src/main/java/com/framsticks/core/AbstractTree.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.7 KB
Line 
1package com.framsticks.core;
2import java.util.HashSet;
3import java.util.Set;
4
5import javax.annotation.Nonnull;
6
7import org.apache.log4j.Logger;
8
9import com.framsticks.params.AccessInterface;
10import com.framsticks.params.CompositeParam;
11import com.framsticks.params.FramsClass;
12import com.framsticks.params.Param;
13import com.framsticks.params.ParamsPackage;
14import com.framsticks.params.Registry;
15import com.framsticks.params.annotations.AutoAppendAnnotation;
16import com.framsticks.params.annotations.FramsClassAnnotation;
17import com.framsticks.util.dispatching.Dispatching;
18import com.framsticks.util.dispatching.RunAt;
19import com.framsticks.util.dispatching.Thread;
20import com.framsticks.util.dispatching.ThrowExceptionHandler;
21
22/**
23 * @author Piotr Sniegowski
24 */
25@FramsClassAnnotation
26public abstract class AbstractTree extends Thread<Tree> implements Tree {
27
28        private static final Logger log = Logger.getLogger(Tree.class);
29
30        private Node root;
31
32        @Override
33        public void setRoot(Node node) {
34                root = node;
35        }
36
37        @Override
38        public @Nonnull Node getRoot() {
39                assert root != null;
40                return root;
41        }
42
43        public boolean isRootAssigned() {
44                // assert isActive();
45                return root != null;
46        }
47
48        protected Set<TreeListener> listeners = new HashSet<TreeListener>();
49
50        public AbstractTree() {
51                setName("entity");
52        }
53
54        protected void tryRegisterOnChangeEvents(Path path) {
55
56        }
57
58
59        protected void fireRun(Exception e) {
60                for (TreeListener l : this.listeners) {
61                        l.onRun(e);
62                }
63        }
64
65        protected void fireStop(Exception e) {
66                for (TreeListener l : this.listeners) {
67                        l.onStop(e);
68                }
69        }
70
71        @Override
72        public void addListener(final TreeListener listener) {
73                assert Dispatching.isThreadSafe();
74                Dispatching.dispatchIfNotActive(this, new RunAt<Tree>(ThrowExceptionHandler.getInstance()) {
75                        @Override
76                        protected void runAt() {
77                                listeners.add(listener);
78                        }
79                });
80        }
81
82        @Override
83        public void removeListener(final TreeListener listener) {
84                assert Dispatching.isThreadSafe();
85                Dispatching.dispatchIfNotActive(this, new RunAt<Tree>(ThrowExceptionHandler.getInstance()) {
86                        @Override
87                        protected void runAt() {
88                                listeners.remove(listener);
89                        }
90                });
91        }
92
93        protected void fireListChange(Path path, ListChange change) {
94                assert isActive();
95                for (TreeListener l : this.listeners) {
96                        l.onListChange(path, change);
97                }
98        }
99
100        @Override
101        public void notifyOfFetch(Path path) {
102                fireFetch(path);
103        }
104
105        protected void fireFetch(Path path) {
106                assert isActive();
107                for (TreeListener l : this.listeners) {
108                        l.onFetch(path);
109                }
110        }
111
112
113        @Override
114        public final FramsClass getInfoFromCache(String id) {
115                assert isActive();
116                return registry.getFramsClass(id);
117        }
118
119        protected Registry registry = new Registry();
120
121
122        @Override
123        public @Nonnull AccessInterface prepareAccess(CompositeParam param) {
124                return registry.prepareAccess(param);
125        }
126
127        @Override
128        public void takeAllFrom(Registry source) {
129                registry.takeAllFrom(source);
130        }
131
132        @AutoAppendAnnotation
133        public void usePackage(ParamsPackage paramsPackage) {
134                log.debug("using package " + paramsPackage + " in tree " + this);
135                paramsPackage.register(registry);
136        }
137
138        @AutoAppendAnnotation
139        public void takeFromRegistry(Registry registry) {
140                log.debug("taking from registry " + registry + " in tree " + this);
141                this.registry.takeAllFrom(registry);
142        }
143
144        @Override
145        protected void joinableStart() {
146                dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) {
147                        @Override
148                        protected void runAt() {
149                                if (!isRootAssigned()) {
150                                        setRoot(new Node(Param.build().name("Tree").id(getName()).type("o").finish(CompositeParam.class), null));
151                                }
152                        }
153                });
154                super.joinableStart();
155        }
156
157        @Override
158        public void putInfoIntoCache(FramsClass framclass) {
159                registry.putFramsClass(framclass);
160        }
161}
162
Note: See TracBrowser for help on using the repository browser.