source: java/main/src/main/java/com/framsticks/hosting/ClientAtServer.java @ 100

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

HIGHLIGHTS:

  • add <include/> to configuration
  • add side notes to tree
    • used to store arbitrary information alongside the tree structure
  • migrate to log4j2
    • supports lazy string evaluation of passed arguments
  • improve GUI tree
    • it stays in synchronization with actual state (even in high load test scenario)
  • improve panel management in GUI
  • make loading objects in GUI more lazy
  • offload parsing to connection receiver thread
    • info parsing
    • first step of objects parsing
  • fix connection parsing bug (eof in long values)
  • support zero-arguments procedure in table view

CHANGELOG:
Implement procedure calls from table view.

Refactorization around procedures in tables.

Add table editor for buttons.

Render buttons in the the list view.

Further improve Columns.

Add Column class for TableModel?.

Accept also non-arguments ProcedureParams? in tableView.

Increase maximal TextAreaControl? size.

Add tooltip to ProcedureControl?.

Fix bug of interpreting eofs in long values by connection reader.

Further rework connection parsing.

Simplify client connection processing.

Test ListChange? modification.

Test ListChange? events with java server.

Add TestChild?.

Fix bug with fast deregistering when connecting to running server.

Another minor refactorization in TreeOperations?.

Fix bug in SimpleAbstractAccess? loading routine.

Another minor improvement.

Minor change.

Make reading of List objects two-phase.

Another minor change.

Dispatch parsing into receiver thread.

Another step.

Enclose passing value in ObjectParam? case in closure.

Minor step.

Minor change on way to offload parsing.

Temporarily comment out single ValueParam? get.

It will be generalized to multi ValueParam?.

Process info in receiver thread.

Add DispatchingExceptionHandler?.

Make waits in browser test longer.

Use FETCHED_MARK.

It is honored in GUI, where it used to decide whether to get values

after user action.

It is set in standard algorithm for processing fetched values.

Add remove operation to side notes.

Make loading more lazy.

Improve loading policy.

On node choose load itself, on node expansion, load children.

Minor improvement.

Fix bug with panel interleaving.

Minor improvements.

Improve panel management.

More cleaning around panels.

Reorganize panels.

Further improve tree.

Fix bug in TreeModel?.

Remove children from TreeNode?.

Implement TreeNode? hashCode and equals.

Make TreeNode? delegate equals and hashcode to internal reference.

Move listeners from TreeNode? to side notes.

Store path.textual as a side note.

Side note params instead of accesses for objects.

More refactorizations.

In TreeNode? bindAccess based on side notes.

Minor step.

Hide createAccess.

Rename AccessInterface? to Access.

Minor changes.

Several improvements in high load scenarios.

Change semantics of ArrayListAccess?.set(index, null);

It now removes the element, making list shorter
(it was set to null before).

Add path remove handler.

Handle exceptions in Connection.

Update .gitignore

Configure logging to file.

Move registration to TreeModel?.

Further refactorization.

Minor refactorization.

Minor improvements.

Use specialized event also for Modify action of ListChange?.

Use remove events.

Use the insertion events for tree.

Further improve tree refreshing.

Further improve reacting on events in GUI.

Fix problem with not adding objects on addition list change.

Migrate to log4j lazy String construction interface.

Migrate imports to log4j2.

Drop dependency on adapter to version 1.2.

Switch log4j implementation to log4j2.

Add dirty mark to the NodeAtFrame?.

Make selecting in AccessInterfaces? type safe.

Ignore containers size settings in Model and Genotype.

Use tree side notes to remember local changes and panels.

Add sideNotes to tree.

They will be used to store various accompanying information
right in the tree.

Use ReferenceIdentityMap? from apache in TreeNode?.

It suits the need perfectly (weak semantics on both key and value).

Make ArrayListParam? do not react size changes.

Guard in TableModel? before not yet loaded objects.

Add <include/> clause and AutoInjector?.

Extract common columns configuration to separate xml,
that can be included by other configurations.

File size: 7.5 KB
Line 
1package com.framsticks.hosting;
2
3import static com.framsticks.util.lang.Strings.assureNotEmpty;
4
5import com.framsticks.communication.*;
6import com.framsticks.communication.queries.ApplicationRequest;
7import com.framsticks.communication.queries.CallRequest;
8import com.framsticks.communication.queries.GetRequest;
9import com.framsticks.communication.queries.InfoRequest;
10import com.framsticks.communication.queries.RegisterRequest;
11import com.framsticks.communication.queries.SetRequest;
12import com.framsticks.core.LocalTree;
13import com.framsticks.core.Tree;
14import com.framsticks.core.Path;
15import com.framsticks.params.*;
16import com.framsticks.params.types.EventParam;
17import com.framsticks.params.types.ProcedureParam;
18import com.framsticks.parsers.Savers;
19import com.framsticks.util.FramsticksException;
20import com.framsticks.util.Misc;
21import com.framsticks.util.dispatching.AbstractJoinable;
22import com.framsticks.util.dispatching.Dispatching;
23import com.framsticks.util.dispatching.ExceptionResultHandler;
24import com.framsticks.util.dispatching.FutureHandler;
25import com.framsticks.util.dispatching.Joinable;
26import com.framsticks.util.dispatching.JoinableParent;
27import com.framsticks.util.dispatching.JoinableState;
28import com.framsticks.util.lang.FlagsUtil;
29import com.framsticks.util.lang.Strings;
30
31import static com.framsticks.core.TreeOperations.*;
32
33import java.net.Socket;
34
35/**
36 * @author Piotr Sniegowski
37 */
38public class ClientAtServer extends AbstractJoinable implements RequestHandler, JoinableParent, ExceptionResultHandler {
39
40        protected final Server server;
41        protected final Tree contentTree;
42        protected final Object treeRootObject;
43        protected final ServerSideManagedConnection connection;
44
45        protected final Cli cliObject;
46        protected final LocalTree rootTree;
47
48
49        protected final FramsClass rootFramsClass;
50        protected final Object root;
51        protected final String contentPrefix;
52
53        public ClientAtServer(Server server, Socket socket) {
54                this.server = server;
55                this.contentTree = server.hosted;
56                this.connection = new ServerSideManagedConnection(socket, this);
57
58                treeRootObject = contentTree.getAssignedRoot().getObject();
59                Misc.throwIfNull(treeRootObject);
60
61                cliObject = new Cli(this);
62                rootTree = new LocalTree();
63                // rootTree.setDispatcher(new AtOnceDispatcher<Tree>());
64                rootTree.setDispatcher(server.getHosted().getDispatcher());
65                assert rootTree.getDispatcher() != null;
66
67                final FramsClass framsClass = bindAccess(contentTree.getAssignedRoot()).getFramsClass();
68                final String id = Strings.uncapitalize(framsClass.getName());
69                contentPrefix = "/" + id;
70                final String rootFramsClassId = id + "Root";
71
72                rootFramsClass = FramsClass.build()
73                        .idAndName(rootFramsClassId)
74                        .param(Param.build().id(id).name(framsClass.getName()).type("o " + framsClass.getId()))
75                        .param(Param.build().id("cli").name("CLI").type("o Cli"))
76                        .finish();
77
78                // rootTree.putInfoIntoCache(rootFramsClass);
79                rootTree.getRegistry().putFramsClass(rootFramsClass);
80                rootTree.getRegistry().registerAndBuild(Cli.class);
81                rootTree.getRegistry().registerAndBuild(CliEvent.class);
82
83                Access access = new PropertiesAccess(rootFramsClass);
84
85                root = createAccessee(rootTree, access);
86                access.select(root);
87                access.set(id, treeRootObject);
88                access.set("cli", cliObject);
89
90                rootTree.assignRootParam(access.buildParam(new ParamBuilder()).name(rootFramsClassId).finish(CompositeParam.class));
91                rootTree.assignRootObject(root);
92
93        }
94
95        @Override
96        public String getName() {
97                return connection + " to " + server;
98        }
99
100        @Override
101        public void handle(final ApplicationRequest request, final ServerSideResponseFuture responseCallback) {
102                assureNotEmpty(request.getPath());
103
104                if (request.getPath().startsWith(contentPrefix)) {
105                        String p = request.getPath().substring(contentPrefix.length());
106                        request.path(p.equals("") ? "/" : p);
107                        handleInTree(contentTree, request, responseCallback, contentPrefix);
108                        return;
109                }
110
111                handleInTree(rootTree, request, responseCallback, "");
112        }
113
114        public static File printToFile(String path, Access access) {
115                ListSink sink = new ListSink();
116                access.save(sink);
117                return new File(path, new ListSource(sink.getOut()));
118        }
119
120        protected void handleInTree(final Tree tree, final ApplicationRequest request, final ServerSideResponseFuture responseCallback, final String usedPrefix) {
121
122                tryGet(tree, request.getActualPath(), new FutureHandler<Path>(responseCallback) {
123                        @Override
124                        protected void result(final Path path) {
125
126                                if (!path.getTextual().equals(request.getActualPath())) {
127                                        throw new FramsticksException().msg("invalid path").arg("path", request.getActualPath());
128                                }
129
130                                // final Access access = tree.prepareAccess(path);
131                                final Access access = bindAccess(path);
132
133                                if (request instanceof GetRequest) {
134                                        Object result = path.getTopObject();
135                                        if (result != access.getSelected()) {
136                                                throw new FramsticksException().msg("mismatch objects during fetch").arg("path", path);
137                                        }
138                                        responseCallback.pass(new Response(true, "", File.single(printToFile(path.getTextual(), access))));
139
140                                        return;
141                                }
142
143                                if (request instanceof SetRequest) {
144                                        SetRequest setRequest = (SetRequest) request;
145                                        //TODO Primitive Param?
146                                        tree.set(path, access.getFramsClass().getParamEntry(setRequest.getField(), PrimitiveParam.class), setRequest.getValue(), new FutureHandler<Integer>(responseCallback) {
147                                                @Override
148                                                protected void result(Integer flag) {
149                                                        responseCallback.pass(new Response(true, FlagsUtil.write(SetStateFlags.class, flag, null), null));
150
151                                                }
152                                        });
153                                        return;
154                                }
155
156                                if (request instanceof CallRequest) {
157                                        final CallRequest callRequest = (CallRequest) request;
158                                        tree.call(path, access.getFramsClass().getParamEntry(callRequest.getProcedure(), ProcedureParam.class), callRequest.getArguments().toArray(), new FutureHandler<Object>(responseCallback) {
159                                                @Override
160                                                protected void result(Object result) {
161                                                        ListSink sink = new ListSink();
162                                                        sink.print("Result:").breakLine();
163                                                        sink.print("value:").print("[");
164                                                        if (result != null) {
165                                                                sink.print(result);
166                                                        }
167                                                        sink.print("]");
168
169                                                        responseCallback.pass(new Response(true, "", File.single(new File("", new ListSource(sink.getOut())))));
170                                                }
171                                        });
172                                        return;
173                                }
174
175                                if (request instanceof InfoRequest) {
176                                        FramsClass framsClass = getInfo(path);
177                                        if (framsClass == null) {
178                                                throw new FramsticksException().msg("info should be available");
179                                        }
180                                        responseCallback.pass(new Response(true, null, File.single(new File(path.getTextual(), new ListSource(Savers.saveFramsClass(new ListSink(), framsClass).getOut())))));
181                                        return;
182                                }
183
184                                if (request instanceof RegisterRequest) {
185                                        RegisterRequest register = (RegisterRequest) request;
186
187                                        cliObject.addListener(path, access.getFramsClass().getParamEntry(register.getEventName(), EventParam.class), usedPrefix, responseCallback);
188                                        return;
189                                }
190
191                                throw new FramsticksException().msg("invalid request type: " + request.getCommand());
192                        }
193                });
194
195        }
196
197        @Override
198        protected void joinableStart() {
199                Dispatching.use(connection, this);
200        }
201
202        @Override
203        protected void joinableInterrupt() {
204                Dispatching.drop(connection, this);
205        }
206
207        @Override
208        protected void joinableFinish() {
209        }
210
211        @Override
212        protected void joinableJoin() throws InterruptedException {
213                Dispatching.join(connection);
214        }
215
216        @Override
217        public void childChangedState(Joinable joinable, JoinableState state) {
218                proceedToState(state);
219        }
220
221        @Override
222        public void handle(FramsticksException exception) {
223                contentTree.handle(exception);
224        }
225
226        /**
227         * @return the tree
228         */
229        public Tree getTree() {
230                return contentTree;
231        }
232
233}
Note: See TracBrowser for help on using the repository browser.