source: java/main/src/main/java/com/framsticks/core/ObjectTree.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.4 KB
Line 
1package com.framsticks.core;
2
3import org.apache.log4j.Logger;
4
5import com.framsticks.params.AccessInterface;
6import com.framsticks.params.CompositeParam;
7import com.framsticks.params.FramsClass;
8import com.framsticks.params.Param;
9import com.framsticks.params.PrimitiveParam;
10import com.framsticks.params.annotations.AutoAppendAnnotation;
11import com.framsticks.params.annotations.FramsClassAnnotation;
12import com.framsticks.util.UnsupportedOperationException;
13import com.framsticks.params.types.ProcedureParam;
14import com.framsticks.util.FramsticksException;
15import com.framsticks.util.dispatching.Future;
16import static com.framsticks.core.TreeOperations.*;
17
18@FramsClassAnnotation
19public class ObjectTree extends AbstractTree {
20        private static final Logger log = Logger.getLogger(ObjectTree.class);
21
22        @AutoAppendAnnotation
23        public void setRootObject(Object object) {
24                registry.registerAndBuild(object.getClass());
25                AccessInterface access = registry.createAccess(object.getClass());
26                setRoot(new Node(Param.build().forAccess(access).id(getName()).finish(CompositeParam.class), object));
27        }
28
29        public Object getRootObject() {
30                return getRoot().getObject();
31        }
32
33        public <T> T getRootObject(Class<T> type) {
34                Object result = getRootObject();
35                if (result == null) {
36                        throw new FramsticksException().msg("object tree is empty").arg("tree", this);
37                }
38                if (!type.isInstance(result)) {
39                        throw new FramsticksException().msg("object tree holds object of different kind").arg("object", result).arg("requested", type).arg("tree", this);
40                }
41                return type.cast(result);
42        }
43
44        @Override
45        public void get(final Path path, Mode mode, Future<Object> future) {
46                assert isActive();
47                log.debug("requesting: " + path);
48                fireFetch(path);
49                future.pass(path.getTopObject());
50        }
51
52        @Override
53        public void get(Path path, PrimitiveParam<?> param, Mode mode, Future<Object> future) {
54                assert isActive();
55                fireFetch(path);
56                future.pass(bindAccess(path).get(param, Object.class));
57        }
58
59        @Override
60        public void call(Path path, ProcedureParam param, Object[] arguments, Future<Object> future) {
61                assert isActive();
62                try {
63                        future.pass(bindAccess(path).call(param, arguments));
64                } catch (FramsticksException e) {
65                        future.handle(e);
66                }
67        }
68
69        @Override
70        public void info(Path path, Future<FramsClass> future) {
71                assert isActive();
72                Path p = path.tryResolveIfNeeded();
73                Class<?> javaClass = p.getTopObject().getClass();
74                FramsClass framsClass = registry.registerReflectedIfNeeded(javaClass);
75                if (framsClass != null) {
76                        future.pass(framsClass);
77                } else {
78                        future.handle(new FramsticksException().msg("failed to find info for class").arg("java class", javaClass));
79                }
80        }
81
82        @Override
83        public void resolve(Path path, Future<Path> future) {
84                assert isActive();
85                assert path.isOwner(this);
86                if (path.getTop().getObject() != null) {
87                        future.pass(path);
88                        return;
89                }
90                AccessInterface access = bindAccess(this, path.getUnder());
91                Object object = access.get(path.getTop().getParam(), Object.class);
92                if (object == null) {
93                        future.pass(path);
94                        return;
95                }
96                future.pass(path.appendResolution(object));
97        }
98
99        @Override
100        public void set(Path path, PrimitiveParam<?> param, Object value, final Future<Integer> future) {
101                assert isActive();
102                future.pass(bindAccess(path).set(param, value));
103        }
104
105        @Override
106        public Path create(Path path) {
107                assert isActive();
108                assert !path.isResolved();
109                throw new UnsupportedOperationException();
110        }
111
112}
Note: See TracBrowser for help on using the repository browser.